hecto/src/main.rs

30 lines
552 B
Rust
Raw Normal View History

2021-01-28 15:53:09 -05:00
use std::io::{self, stdout};
use termion::event::Key;
use termion::input::TermRead;
2021-01-22 19:36:11 -05:00
use termion::raw::IntoRawMode;
fn die(e: std::io::Error) {
panic!(e);
}
fn main() {
let _stdout = stdout().into_raw_mode().unwrap();
2021-01-28 15:53:09 -05:00
for key in io::stdin().keys() {
match key {
Ok(key) => match key {
Key::Char(c) => {
if c.is_control() {
println!("{:?}\r", c as u8);
} else {
println!("{:?} ({})\r", c as u8, c);
}
2021-01-22 19:36:11 -05:00
}
2021-01-28 15:53:09 -05:00
Key::Ctrl('q') => break,
_ => println!("{:?}\r", key),
2021-01-22 19:36:11 -05:00
}
Err(err) => die(err),
}
}
}