2016-03-15 20:36:33 +00:00
|
|
|
extern crate termion;
|
2016-03-06 13:55:01 +00:00
|
|
|
|
2016-07-23 15:40:27 +01:00
|
|
|
use termion::color;
|
|
|
|
use termion::raw::IntoRawMode;
|
2016-03-06 13:55:01 +00:00
|
|
|
use std::io::{Read, Write, stdout, stdin};
|
|
|
|
|
|
|
|
fn main() {
|
2016-04-02 17:05:31 +01:00
|
|
|
// Initialize 'em all.
|
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-07-23 15:40:27 +01:00
|
|
|
write!(stdout, "{}{}{}yo, 'q' will exit.{}{}", termion::clear::All, termion::cursor::Goto(5, 5),
|
|
|
|
termion::style::Bold, termion::style::Reset, termion::cursor::Goto(20, 10)).unwrap();
|
2016-03-07 15:23:05 +00:00
|
|
|
stdout.flush().unwrap();
|
2016-03-06 13:55:01 +00:00
|
|
|
|
|
|
|
let mut bytes = stdin.bytes();
|
|
|
|
loop {
|
|
|
|
let b = bytes.next().unwrap().unwrap();
|
|
|
|
|
|
|
|
match b {
|
2016-04-02 17:05:31 +01:00
|
|
|
// Quit
|
2016-03-06 13:55:01 +00:00
|
|
|
b'q' => return,
|
2016-04-02 17:05:31 +01:00
|
|
|
// Clear the screen
|
2016-07-23 15:40:27 +01:00
|
|
|
b'c' => write!(stdout, "{}", termion::clear::All),
|
2016-04-02 17:05:31 +01:00
|
|
|
// Set red color
|
2016-07-23 15:40:27 +01:00
|
|
|
b'r' => write!(stdout, "{}", color::Fg(color::Rgb(5, 0, 0))),
|
2016-04-02 17:05:31 +01:00
|
|
|
// Write it to stdout.
|
2016-07-23 15:40:27 +01:00
|
|
|
a => write!(stdout, "{}", 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
|
|
|
}
|
|
|
|
}
|