reverberation 0.1.0

Reverberation - A lightweight text viewer that creates echo effects when displaying text.
/*!
 * Reverberation - A lightweight text viewer
 *
 * Copyright (c) 2026 S.A. (@snoware)
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

use std::fs::File;
use std::io::{BufRead, BufReader, Write};
use std::str::FromStr;
use std::thread;
use std::time::Duration;

/// Reverberation - A lightweight text viewer that creates echo effects when displaying text.
/// 
/// This program reads a text file and displays its content character by character
/// with a configurable delay between characters, creating a "typewriter" effect.
/// 
/// # Usage
/// 
/// reverberation <filename> <delay_ms>
/// 
/// - `filename`: Path to the text file to be displayed
/// - `delay_ms`: Delay time between characters in milliseconds
/// 
/// To get help:
/// reverberation --help
fn main() {
    // 获取命令行参数(包括程序名)
    let args: Vec<String> = std::env::args().collect();
    // 检查是否有足够的参数
    if args.len() < 2 || args[1] == "-h" || args[1] == "--help" {
        println!("Reverberation - Designed by S.A. | (C) SNOWARE 2026");
        println!(":) 逐字去读...第一个参数是文件名(纯文本),第二个间隔时间(ms)");
        return;
    }

    let file = File::open(&args[1]).expect(":( FileLoadErr");
    let reader = BufReader::new(file);

    for line in reader.lines() {
        let line = line.expect(":( ContentLoadErr");
        for ch in line.chars() {
            print!("{}", ch);
            std::io::stdout().flush().expect(":( I/O error");
            thread::sleep(Duration::from_millis(u64::from_str(&args[2])
                .expect(":( NumFormatErr")))
        }
        println!(); // 换行
    }
}