See Here for a recording.
Inspired by this reddit post
[package] | |
name = "hello-world" | |
version = "0.1.0" | |
authors = ["holi0317 <holliswuhollis@gmail.com>"] | |
[dependencies] | |
rand = "0.4.2" |
extern crate rand; | |
use std::{time, thread}; | |
use std::io::{self, Write}; | |
use rand::{thread_rng, Rng}; | |
const EREASE_SEQUENCE: &str = "\x1B[D\x1B[K"; | |
const SLEEP_DUR: u64 = 70; | |
const TARGET: &str = "Hello, world!"; | |
fn main() { | |
println!(); | |
for c in TARGET.chars() { | |
let c = c.to_string(); | |
let mut rng = thread_rng(); | |
let mut generator = rng | |
.gen_iter::<u8>() | |
.filter(|&n| n >= 32 && n <= 126) | |
.map(|n| String::from_utf8(vec!(n)).unwrap()); | |
for random in generator { | |
if random != c { | |
print!("{}", random); | |
io::stdout().flush().unwrap(); | |
thread::sleep(time::Duration::from_millis(SLEEP_DUR)); | |
print!("{}", EREASE_SEQUENCE); | |
io::stdout().flush().unwrap(); | |
} else { | |
break | |
} | |
} | |
print!("{}", c); | |
} | |
println!(); | |
} |
See Here for a recording.
Inspired by this reddit post