2016-03-15 20:36:33 +00:00
|
|
|
extern crate termion;
|
2016-03-06 13:55:01 +00:00
|
|
|
|
2016-03-15 20:36:33 +00:00
|
|
|
use termion::{TermWrite, IntoRawMode, Color, Style};
|
2016-03-06 13:55:01 +00:00
|
|
|
use std::io::{Read, Write, stdout, stdin};
|
|
|
|
|
|
|
|
fn main() {
|
2016-03-07 17:42:11 +00:00
|
|
|
let stdout = stdout();
|
2016-03-07 21:19:35 +00:00
|
|
|
let mut stdout = stdout.lock().into_raw_mode().unwrap();
|
2016-03-08 07:27:59 +00:00
|
|
|
let stdin = stdin();
|
2016-03-15 19:32:25 +00:00
|
|
|
let stdin = stdin.lock();
|
2016-03-06 13:55:01 +00:00
|
|
|
|
2016-03-07 15:23:05 +00:00
|
|
|
stdout.goto(5, 5).unwrap();
|
|
|
|
stdout.clear().unwrap();
|
2016-03-08 17:38:07 +00:00
|
|
|
stdout.style(Style::Bold).unwrap();
|
2016-03-07 15:23:05 +00:00
|
|
|
stdout.write(b"yo, 'q' will exit.").unwrap();
|
2016-03-07 16:57:17 +00:00
|
|
|
stdout.reset().unwrap();
|
2016-03-07 15:23:05 +00:00
|
|
|
stdout.flush().unwrap();
|
|
|
|
stdout.goto(20, 10).unwrap();
|
2016-03-06 13:55:01 +00:00
|
|
|
|
|
|
|
let mut bytes = stdin.bytes();
|
|
|
|
loop {
|
|
|
|
let b = bytes.next().unwrap().unwrap();
|
|
|
|
|
|
|
|
match b {
|
|
|
|
b'q' => return,
|
|
|
|
b'c' => stdout.clear(),
|
2016-03-07 16:39:25 +00:00
|
|
|
b'r' => stdout.color(Color::Rgb(5, 0, 0)),
|
2016-03-06 13:55:01 +00:00
|
|
|
a => stdout.write(&[a]),
|
2016-03-07 15:23:05 +00:00
|
|
|
}.unwrap();
|
2016-03-06 13:55:01 +00:00
|
|
|
|
2016-03-07 15:23:05 +00:00
|
|
|
stdout.flush().unwrap();
|
2016-03-06 13:55:01 +00:00
|
|
|
}
|
|
|
|
}
|