termion/examples/keys.rs

37 lines
1.1 KiB
Rust
Raw Normal View History

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