termion/examples/simple.rs

33 lines
820 B
Rust
Raw Normal View History

2016-03-06 13:55:01 +00:00
extern crate libterm;
2016-03-08 20:39:24 +00:00
use libterm::{WriteExt, IntoRawMode, Color, Style};
2016-03-06 13:55:01 +00:00
use std::io::{Read, Write, stdout, stdin};
fn main() {
let stdout = stdout();
2016-03-07 21:19:35 +00:00
let mut stdout = stdout.lock().into_raw_mode().unwrap();
let stdin = stdin();
2016-03-06 13:55:01 +00:00
2016-03-07 15:23:05 +00:00
stdout.goto(5, 5).unwrap();
stdout.clear().unwrap();
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
}
}