summaryrefslogtreecommitdiffstats
path: root/third_party/rust/termion/examples/keys.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/termion/examples/keys.rs')
-rw-r--r--third_party/rust/termion/examples/keys.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/third_party/rust/termion/examples/keys.rs b/third_party/rust/termion/examples/keys.rs
new file mode 100644
index 0000000000..272ffd1b9a
--- /dev/null
+++ b/third_party/rust/termion/examples/keys.rs
@@ -0,0 +1,44 @@
+extern crate termion;
+
+use termion::event::Key;
+use termion::input::TermRead;
+use termion::raw::IntoRawMode;
+use std::io::{Write, stdout, stdin};
+
+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();
+ stdout.flush().unwrap();
+
+ for c in stdin.keys() {
+ write!(stdout,
+ "{}{}",
+ termion::cursor::Goto(1, 1),
+ termion::clear::CurrentLine)
+ .unwrap();
+
+ match c.unwrap() {
+ Key::Char('q') => break,
+ Key::Char(c) => println!("{}", c),
+ Key::Alt(c) => println!("^{}", c),
+ Key::Ctrl(c) => println!("*{}", c),
+ Key::Esc => println!("ESC"),
+ Key::Left => println!("←"),
+ Key::Right => println!("→"),
+ Key::Up => println!("↑"),
+ Key::Down => println!("↓"),
+ Key::Backspace => println!("×"),
+ _ => {}
+ }
+ stdout.flush().unwrap();
+ }
+
+ write!(stdout, "{}", termion::cursor::Show).unwrap();
+}