]> git.proxmox.com Git - rustc.git/blob - src/vendor/termion/examples/keys.rs
New upstream version 1.23.0+dfsg1
[rustc.git] / src / vendor / termion / examples / keys.rs
1 extern crate termion;
2
3 use termion::event::Key;
4 use termion::input::TermRead;
5 use termion::raw::IntoRawMode;
6 use std::io::{Write, stdout, stdin};
7
8 fn main() {
9 let stdin = stdin();
10 let mut stdout = stdout().into_raw_mode().unwrap();
11
12 write!(stdout,
13 "{}{}q to exit. Type stuff, use alt, and so on.{}",
14 termion::clear::All,
15 termion::cursor::Goto(1, 1),
16 termion::cursor::Hide)
17 .unwrap();
18 stdout.flush().unwrap();
19
20 for c in stdin.keys() {
21 write!(stdout,
22 "{}{}",
23 termion::cursor::Goto(1, 1),
24 termion::clear::CurrentLine)
25 .unwrap();
26
27 match c.unwrap() {
28 Key::Char('q') => break,
29 Key::Char(c) => println!("{}", c),
30 Key::Alt(c) => println!("^{}", c),
31 Key::Ctrl(c) => println!("*{}", c),
32 Key::Esc => println!("ESC"),
33 Key::Left => println!("←"),
34 Key::Right => println!("→"),
35 Key::Up => println!("↑"),
36 Key::Down => println!("↓"),
37 Key::Backspace => println!("×"),
38 _ => {}
39 }
40 stdout.flush().unwrap();
41 }
42
43 write!(stdout, "{}", termion::cursor::Show).unwrap();
44 }