Fix pancurses input

Fixes #210
This commit is contained in:
Alexandre Bury 2018-03-01 13:21:52 -08:00
parent 5e58726ffd
commit 1ae3bbff89
2 changed files with 2 additions and 27 deletions

View File

@ -48,7 +48,7 @@ version = "5.91.0"
[dependencies.pancurses]
features = ["wide"]
optional = true
version = "0.14"
version = "0.15"
[dependencies.pulldown-cmark]
default-features = false

View File

@ -8,7 +8,6 @@ use std::cell::{Cell, RefCell};
use std::collections::HashMap;
use std::io::{stdout, Write};
use theme::{Color, ColorPair, Effect};
use utf8;
use vec::Vec2;
pub struct Concrete {
@ -244,33 +243,10 @@ impl backend::Backend for Concrete {
pancurses::Input::Character('\u{1b}') => {
Event::Key(Key::Esc)
}
pancurses::Input::Character(c)
if 32 <= (c as u32) && (c as u32) <= 255 =>
{
// TODO: pancurses may start parsing the input.
// In this case, return as-is.
utf8::read_char(c as u8, || {
self.window.getch().and_then(|i| match i {
pancurses::Input::Character(c) => {
Some(c as u8)
}
_ => None,
})
}).map(Event::Char)
.unwrap_or_else(|e| {
warn!("Error reading input: {}", e);
Event::Unknown(vec![c as u8])
})
}
pancurses::Input::Character(c) if (c as u32) <= 26 => {
Event::CtrlChar((b'a' - 1 + c as u8) as char)
}
pancurses::Input::Character(c) => {
let mut bytes = [0u8; 4];
Event::Unknown(
c.encode_utf8(&mut bytes).as_bytes().to_vec(),
)
}
pancurses::Input::Character(c) => Event::Char(c),
// TODO: Some key combos are not recognized by pancurses,
// but are sent as Unknown. We could still parse them here.
pancurses::Input::Unknown(code) => self.key_codes
@ -507,7 +483,6 @@ fn get_mouse_button(bare_event: mmask_t) -> MouseButton {
}
fn initialize_keymap() -> HashMap<i32, Event> {
let mut map = HashMap::new();
super::fill_key_codes(&mut map, pancurses::keyname);