Skip to content

Commit

Permalink
fix crossterm input handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 3, 2020
1 parent 9e74ada commit 8547c8b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/tui/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pub mod input {
Null => Key::Null,
Esc => Key::Esc,
Char(c) => match value.modifiers {
KeyModifiers::SHIFT => Key::Char(c),
KeyModifiers::NONE | KeyModifiers::SHIFT => Key::Char(c),
KeyModifiers::CONTROL => Key::Ctrl(c),
KeyModifiers::ALT => Key::Alt(c),
_ => return Err(value),
Expand Down Expand Up @@ -268,7 +268,9 @@ mod _impl {

pub fn key_input_stream() -> futures_channel::mpsc::Receiver<Key> {
let (mut key_send, key_receive) = futures_channel::mpsc::channel::<Key>(1);
// This brings blocking key-handling into the async world
// NOTE: Even though crossterm has support for async event streams, it will use MIO in this
// case and pull in even more things that we simply don't need for that. A thread and blocking
// IO will do just fine.
std::thread::spawn(move || -> Result<(), io::Error> {
loop {
let event = crossterm::event::read().map_err(into_io_error)?;
Expand All @@ -277,7 +279,7 @@ mod _impl {
let key: Result<Key, _> = key.try_into();
if let Ok(key) = key {
smol::block_on(key_send.send(key)).ok();
}
};
}
_ => continue,
};
Expand Down

0 comments on commit 8547c8b

Please sign in to comment.