Skip to content

Instantly share code, notes, and snippets.

@0atman
Created June 12, 2022 08:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0atman/9bc09c3b2a234d685f658a2ac2702a5c to your computer and use it in GitHub Desktop.
Save 0atman/9bc09c3b2a234d685f658a2ac2702a5c to your computer and use it in GitHub Desktop.
Auto-typer from Lost Terminal
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(())
}
@0atman
Copy link
Author

0atman commented Jul 7, 2022

[profile.release]
opt-level = 'z'     # Optimize for size.
lto = true          # Enable Link Time Optimization
codegen-units = 1   # Reduce number of codegen units to increase optimizations.
panic = 'abort'     # Abort on panic
strip = "symbols"        # Strip symbols from binary*

@0atman
Copy link
Author

0atman commented Jul 7, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment