Skip to content

Instantly share code, notes, and snippets.

@Holi0317
Created April 28, 2018 09:19
Show Gist options
  • Save Holi0317/2c92275eb75c019e7babcb7e60f6e2e5 to your computer and use it in GitHub Desktop.
Save Holi0317/2c92275eb75c019e7babcb7e60f6e2e5 to your computer and use it in GitHub Desktop.
Hello world!
[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!();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment