File: key_tester.rs

package info (click to toggle)
rust-termwiz 0.22.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,036 kB
  • sloc: sh: 10,450; makefile: 18
file content (24 lines) | stat: -rw-r--r-- 609 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use termwiz::caps::Capabilities;
use termwiz::input::{InputEvent, KeyCode, KeyEvent, Modifiers};
use termwiz::terminal::{new_terminal, Terminal};
use termwiz::Error;

const CTRL_C: KeyEvent = KeyEvent {
    key: KeyCode::Char('c'),
    modifiers: Modifiers::CTRL,
};

fn main() -> Result<(), Error> {
    let caps = Capabilities::new_from_env()?;
    let mut terminal = new_terminal(caps)?;
    terminal.set_raw_mode()?;

    while let Some(event) = terminal.poll_input(None)? {
        print!("{:?}\r\n", event);
        if event == InputEvent::Key(CTRL_C) {
            break;
        }
    }

    Ok(())
}