2016-03-15 20:36:33 +00:00
|
|
|
|
extern crate termion;
|
2016-03-09 08:39:22 +00:00
|
|
|
|
|
|
|
|
|
|
2016-03-13 10:59:55 +00:00
|
|
|
|
#[cfg(feature = "nightly")]
|
2016-03-09 08:39:22 +00:00
|
|
|
|
fn main() {
|
2016-03-15 20:36:33 +00:00
|
|
|
|
use termion::{TermRead, TermWrite, IntoRawMode, Key};
|
2016-03-13 10:59:55 +00:00
|
|
|
|
use std::io::{Write, stdout, stdin};
|
|
|
|
|
|
2016-03-09 08:39:22 +00:00
|
|
|
|
let stdin = stdin();
|
|
|
|
|
let mut stdout = stdout().into_raw_mode().unwrap();
|
|
|
|
|
|
2016-03-09 16:18:31 +00:00
|
|
|
|
stdout.clear().unwrap();
|
|
|
|
|
stdout.goto(0, 0).unwrap();
|
|
|
|
|
stdout.write(b"q to exit. Type stuff, use alt, and so on.").unwrap();
|
|
|
|
|
stdout.hide_cursor().unwrap();
|
|
|
|
|
stdout.flush().unwrap();
|
2016-03-09 08:39:22 +00:00
|
|
|
|
|
|
|
|
|
for c in stdin.keys() {
|
2016-03-09 16:18:31 +00:00
|
|
|
|
stdout.goto(5, 5).unwrap();
|
|
|
|
|
stdout.clear_line().unwrap();
|
2016-03-09 08:39:22 +00:00
|
|
|
|
match c {
|
|
|
|
|
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),
|
2016-03-09 08:39:22 +00:00
|
|
|
|
Key::Left => println!("←"),
|
|
|
|
|
Key::Right => println!("→"),
|
2016-03-09 10:38:43 +00:00
|
|
|
|
Key::Up => println!("↑"),
|
|
|
|
|
Key::Down => println!("↓"),
|
2016-03-09 08:39:22 +00:00
|
|
|
|
Key::Backspace => println!("×"),
|
|
|
|
|
Key::Invalid => println!("???"),
|
|
|
|
|
Key::Error => println!("ERROR"),
|
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-03-09 16:18:31 +00:00
|
|
|
|
stdout.show_cursor().unwrap();
|
2016-03-09 08:39:22 +00:00
|
|
|
|
}
|
2016-03-13 10:59:55 +00:00
|
|
|
|
#[cfg(not(feature = "nightly"))]
|
|
|
|
|
fn main() {
|
|
|
|
|
println!("To run this example, you need to enable the `nightly` feature. Use Rust nightly and compile with `--features nightly`.")
|
|
|
|
|
}
|