-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtermion.rs
34 lines (26 loc) · 915 Bytes
/
termion.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
mod config;
use config::{CONFIG_DATA, Config, Action};
use keymap::KeyMap;
use termion::event::Event;
use termion::input::{TermRead, MouseTerminal};
use termion::raw::IntoRawMode;
use std::io::{Write, stdout, stdin};
fn main() {
let stdin = stdin();
let mut stdout = MouseTerminal::from(stdout().into_raw_mode().unwrap());
stdout.flush().unwrap();
// Parse key event
let bindings: Config = toml::from_str(CONFIG_DATA).unwrap();
for c in stdin.events() {
let evt = c.unwrap();
if let Event::Key(key) = evt {
if let Some((k, action)) = bindings.0.get_key_value(&KeyMap::from(key)) {
if *action == Action::Quit {
break;
}
write!(stdout, "{}{}key:{k} - {}", termion::clear::All, termion::cursor::Goto(1, 1), action).unwrap();
}
}
stdout.flush().unwrap();
}
}