Created
June 12, 2022 08:39
-
-
Save 0atman/9bc09c3b2a234d685f658a2ac2702a5c to your computer and use it in GitHub Desktop.
Auto-typer from Lost Terminal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fs; | |
use std::io::{self, BufRead, Write}; | |
use std::{thread, time}; | |
/// stdout readline implementation | |
fn wait() { | |
io::stdin().lock().lines().next(); | |
} | |
/// Type the script at 300wpm | |
fn main() -> io::Result<()> { | |
let filename = std::env::args().nth(1) | |
.unwrap_or("episode.md".to_string()); | |
let pause = time::Duration::from_millis(40); | |
let stdout = io::stdout(); | |
let mut handle = stdout.lock(); | |
let contents = fs::read_to_string(filename)?; | |
wait(); | |
for c in contents.chars() { | |
if c == '\n' { | |
wait(); | |
} else { | |
handle.write_all(&[c as u8])?; | |
handle.flush()?; | |
thread::sleep(pause); | |
} | |
} | |
Ok(()) | |
} |
Author
0atman
commented
Jul 7, 2022
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment