ncurses: detect key offset at runtime

This commit is contained in:
Alexandre Bury 2017-11-19 20:13:57 -08:00
parent c10da1390b
commit b2097bd1c8
2 changed files with 10 additions and 3 deletions

View File

@ -50,7 +50,7 @@ version = "0.3"
[dependencies.ncurses] [dependencies.ncurses]
features = ["wide"] features = ["wide"]
optional = true optional = true
version = "5.86.0" version = "5.87.0"
[dependencies.pancurses] [dependencies.pancurses]
features = ["wide"] features = ["wide"]

View File

@ -139,6 +139,7 @@ impl Concrete {
} }
fn parse_ncurses_char(&mut self, ch: i32) -> Event { fn parse_ncurses_char(&mut self, ch: i32) -> Event {
// eprintln!("Found {:?}", ncurses::keyname(ch));
if ch == ncurses::KEY_MOUSE { if ch == ncurses::KEY_MOUSE {
self.parse_mouse_event() self.parse_mouse_event()
} else { } else {
@ -454,8 +455,14 @@ fn initialize_keymap() -> HashMap<i32, Event> {
add_fn(313, Event::Alt, &mut map); add_fn(313, Event::Alt, &mut map);
// Those codes actually vary between ncurses versions... // Those codes actually vary between ncurses versions...
// TODO: load that at compile/runtime... // Use ncurses::keyname to find the key representing kDC3 (alt-DEL)
let del_offset = 522; let del_offset = (512..1024)
.find(|&code| {
ncurses::keyname(code)
.map(|name| &name == "kDC3")
.unwrap_or(false)
})
.unwrap_or(522);
add_modifiers(del_offset, Key::Del, &mut map); add_modifiers(del_offset, Key::Del, &mut map);
add_modifiers(del_offset + 6, Key::Down, &mut map); add_modifiers(del_offset + 6, Key::Down, &mut map);