2016-03-15 20:36:33 +00:00
|
|
|
|
extern crate termion;
|
2016-03-09 08:39:22 +00:00
|
|
|
|
|
2016-07-23 15:40:27 +01:00
|
|
|
|
use termion::input::{TermRead, Key};
|
|
|
|
|
use termion::raw::IntoRawMode;
|
|
|
|
|
use std::io::{Write, stdout, stdin};
|
2016-03-13 10:59:55 +00:00
|
|
|
|
|
2016-07-23 15:40:27 +01:00
|
|
|
|
fn main() {
|
2016-03-09 08:39:22 +00:00
|
|
|
|
let stdin = stdin();
|
|
|
|
|
let mut stdout = stdout().into_raw_mode().unwrap();
|
|
|
|
|
|
2016-07-23 15:40:27 +01:00
|
|
|
|
write!(stdout, "{}{}q to exit. Type stuff, use alt, and so on.{}",
|
|
|
|
|
termion::clear::All,
|
|
|
|
|
termion::cursor::Goto(1, 1),
|
|
|
|
|
termion::cursor::Hide).unwrap();
|
2016-03-09 08:39:22 +00:00
|
|
|
|
|
|
|
|
|
for c in stdin.keys() {
|
2016-07-23 15:40:27 +01:00
|
|
|
|
write!(stdout, "{}{}", termion::cursor::Goto(1, 1), termion::clear::CurrentLine).unwrap();
|
|
|
|
|
|
2016-06-14 13:24:07 +01:00
|
|
|
|
match c.unwrap() {
|
2016-03-09 08:39:22 +00:00
|
|
|
|
Key::Char('q') => break,
|
2016-07-23 15:40:27 +01:00
|
|
|
|
Key::Char(c) => writeln!(stdout, "{}", c).unwrap(),
|
|
|
|
|
Key::Alt(c) => writeln!(stdout, "^{}", c).unwrap(),
|
|
|
|
|
Key::Ctrl(c) => writeln!(stdout, "*{}", c).unwrap(),
|
|
|
|
|
Key::Left => writeln!(stdout, "←").unwrap(),
|
|
|
|
|
Key::Right => writeln!(stdout, "→").unwrap(),
|
|
|
|
|
Key::Up => writeln!(stdout, "↑").unwrap(),
|
|
|
|
|
Key::Down => writeln!(stdout, "↓").unwrap(),
|
|
|
|
|
Key::Backspace => writeln!(stdout, "×").unwrap(),
|
|
|
|
|
Key::Invalid => writeln!(stdout, "???").unwrap(),
|
2016-03-13 10:55:24 +00:00
|
|
|
|
_ => {},
|
2016-03-09 08:39:22 +00:00
|
|
|
|
}
|
2016-03-09 16:18:31 +00:00
|
|
|
|
stdout.flush().unwrap();
|
2016-03-09 08:39:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-23 15:40:27 +01:00
|
|
|
|
write!(stdout, "{}", termion::cursor::Show).unwrap();
|
2016-03-13 10:59:55 +00:00
|
|
|
|
}
|