1 extern crate termion;
2
3 use termion::color;
4 use termion::raw::IntoRawMode;
5 use std::io::{Read, Write, stdout, stdin};
6
main()7 fn main() {
8 // Initialize 'em all.
9 let stdout = stdout();
10 let mut stdout = stdout.lock().into_raw_mode().unwrap();
11 let stdin = stdin();
12 let stdin = stdin.lock();
13
14 write!(stdout,
15 "{}{}{}yo, 'q' will exit.{}{}",
16 termion::clear::All,
17 termion::cursor::Goto(5, 5),
18 termion::style::Bold,
19 termion::style::Reset,
20 termion::cursor::Goto(20, 10))
21 .unwrap();
22 stdout.flush().unwrap();
23
24 let mut bytes = stdin.bytes();
25 loop {
26 let b = bytes.next().unwrap().unwrap();
27
28 match b {
29 // Quit
30 b'q' => return,
31 // Clear the screen
32 b'c' => write!(stdout, "{}", termion::clear::All),
33 // Set red color
34 b'r' => write!(stdout, "{}", color::Fg(color::Rgb(5, 0, 0))),
35 // Write it to stdout.
36 a => write!(stdout, "{}", a),
37 }
38 .unwrap();
39
40 stdout.flush().unwrap();
41 }
42 }
43