Skip to content

Commit ed4ca61

Browse files
authored
Add a small example for working out control keys (#192)
1 parent 50ccfcd commit ed4ca61

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

examples/keyboard.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use std::io;
2+
3+
use console::{Key, Term};
4+
5+
fn main() -> io::Result<()> {
6+
let term = Term::stdout();
7+
term.write_line("Press any key. Esc to exit")?;
8+
loop {
9+
let key = term.read_key()?;
10+
term.write_line(&format!("You pressed {:?}", key))?;
11+
if key == Key::Escape {
12+
break;
13+
}
14+
}
15+
Ok(())
16+
}

0 commit comments

Comments
 (0)