From f1499d1d4518674c6c3c5c859a7028709bdd741d Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Sat, 24 Sep 2016 16:11:50 -0700 Subject: Use evented I/O for the pty This was largely an experiment to see whether writing and reading from a separate thread was causing terminal state corruption as described in https://github.com/jwilm/alacritty/issues/9. Although this doesn't seem to fix that particular issue. Keeping this because it generally seems more correct than reading/writing from separate locations. --- src/event.rs | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'src/event.rs') diff --git a/src/event.rs b/src/event.rs index 303c6d8e..f44fd86c 100644 --- a/src/event.rs +++ b/src/event.rs @@ -1,4 +1,5 @@ //! Process window events +use std::io; use std::sync::{Arc, mpsc}; use std; @@ -9,27 +10,25 @@ use sync::FairMutex; use term::Term; /// The event processor -pub struct Processor<'a, W: 'a> { - writer: &'a mut W, +pub struct Processor { + notifier: N, input_processor: input::Processor, terminal: Arc>, resize_tx: mpsc::Sender<(u32, u32)>, } -impl<'a, W> Processor<'a, W> - where W: std::io::Write -{ +impl Processor { /// Create a new event processor /// /// Takes a writer which is expected to be hooked up to the write end of a /// pty. - pub fn new(writer: &mut W, - terminal: Arc>, - resize_tx: mpsc::Sender<(u32, u32)>) - -> Processor - { + pub fn new( + notifier: N, + terminal: Arc>, + resize_tx: mpsc::Sender<(u32, u32)> + ) -> Processor { Processor { - writer: writer, + notifier: notifier, terminal: terminal, input_processor: input::Processor::new(), resize_tx: resize_tx, @@ -47,7 +46,7 @@ impl<'a, W> Processor<'a, W> '\u{f700}' | '\u{f701}' | '\u{f702}' | '\u{f703}' => (), _ => { let encoded = c.encode_utf8(); - self.writer.write(encoded.as_slice()).unwrap(); + self.notifier.notify(encoded.as_slice().to_vec()); } } }, @@ -60,10 +59,10 @@ impl<'a, W> Processor<'a, W> glutin::Event::KeyboardInput(state, _code, key, mods) => { // Acquire term lock let terminal = self.terminal.lock(); + let processor = &mut self.input_processor; + let notifier = &mut self.notifier; - self.input_processor.process(state, key, mods, - &mut input::WriteNotifier(self.writer), - *terminal.mode()); + processor.process(state, key, mods, notifier, *terminal.mode()); }, _ => (), } -- cgit v1.2.3-54-g00ecf