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:
1 parent
6164860a10
commit
83921728ae
1 file changed
+27
@@ -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(())
|
||||
}
|
||||
Reference in new issue
Block a user