1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-27 12:23:46 +03:00

add key_tester example

Add an example which displays each key that is pressed.  This is useful for
testing what different terminals produce when keys are pressed.
This commit is contained in:
Mark Thomas 2019-04-21 04:14:20 +01:00 committed by Wez Furlong
parent 6164860a10
commit 83921728ae

View File

@ -0,0 +1,27 @@
extern crate failure;
extern crate termwiz;
use failure::Error;
use termwiz::caps::Capabilities;
use termwiz::input::{InputEvent, KeyCode, KeyEvent, Modifiers};
use termwiz::terminal::{new_terminal, Blocking, Terminal};
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(Blocking::Wait)? {
print!("{:?}\r\n", event);
if event == InputEvent::Key(CTRL_C) {
break;
}
}
Ok(())
}