Move WriteNotifier type into input module
It's a generic impl of `input::Notify` for `Write` types; as such, it seems completely reasonable to include in the input module. Moving it also serves to declutter main.
This commit is contained in:
parent
f2e6d66a5e
commit
bc2793a762
11
src/input.rs
11
src/input.rs
|
@ -23,6 +23,8 @@
|
|||
//! APIs
|
||||
//!
|
||||
//! TODO handling xmodmap would be good
|
||||
use std::io::Write;
|
||||
|
||||
use glutin::{ElementState, VirtualKeyCode};
|
||||
|
||||
use term::mode::{self, TermMode};
|
||||
|
@ -108,6 +110,15 @@ pub trait Notify {
|
|||
fn notify(&mut self, &str);
|
||||
}
|
||||
|
||||
/// A notifier type that simply writes bytes to the provided `Write` type
|
||||
pub struct WriteNotifier<'a, W: Write + 'a>(pub &'a mut W);
|
||||
|
||||
impl<'a, W: Write> Notify for WriteNotifier<'a, W> {
|
||||
fn notify(&mut self, message: &str) {
|
||||
self.0.write(message.as_bytes()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// Describes a key combination that should emit a control sequence
|
||||
///
|
||||
/// The actual triggering key is omitted here since bindings are grouped by the trigger key.
|
||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -69,14 +69,6 @@ enum ShouldExit {
|
|||
Yes,
|
||||
No
|
||||
}
|
||||
|
||||
struct WriteNotifier<'a, W: Write + 'a>(&'a mut W);
|
||||
impl<'a, W: Write> input::Notify for WriteNotifier<'a, W> {
|
||||
fn notify(&mut self, message: &str) {
|
||||
self.0.write(message.as_bytes()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// Channel used by resize handling on mac
|
||||
static mut resize_sender: Option<mpsc::Sender<glutin::Event>> = None;
|
||||
|
||||
|
@ -108,7 +100,7 @@ fn handle_event<W>(event: glutin::Event,
|
|||
render_tx.send((w, h)).expect("render thread active");
|
||||
},
|
||||
glutin::Event::KeyboardInput(state, _code, key) => {
|
||||
input_processor.process(state, key, &mut WriteNotifier(writer), *terminal.mode())
|
||||
input_processor.process(state, key, &mut input::WriteNotifier(writer), *terminal.mode())
|
||||
},
|
||||
_ => ()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue