termion/examples/simple.rs

31 lines
694 B
Rust
Raw Normal View History

2016-03-06 13:55:01 +00:00
extern crate libterm;
use libterm::{TermControl, raw_mode};
use std::io::{Read, Write, stdout, stdin};
fn main() {
2016-03-07 15:23:05 +00:00
let _raw = raw_mode();
2016-03-06 13:55:01 +00:00
let mut stdout = stdout();
2016-03-07 15:23:05 +00:00
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.write(b"yo, 'q' will exit.").unwrap();
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 15:23:05 +00:00
b'r' => stdout.rendition(91),
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
}
}