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/input.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'src/input.rs') diff --git a/src/input.rs b/src/input.rs index 757256d2..829312e7 100644 --- a/src/input.rs +++ b/src/input.rs @@ -23,6 +23,7 @@ //! APIs //! //! TODO handling xmodmap would be good +use std::borrow::Cow; use std::io::Write; use glutin::{ElementState, VirtualKeyCode}; @@ -42,15 +43,34 @@ pub struct Processor; /// Types that are notified of escape sequences from the input::Processor. pub trait Notify { /// Notify that an escape sequence should be written to the pty - fn notify(&mut self, &str); + /// + /// TODO this needs to be able to error somehow + fn notify>>(&mut self, B); } /// 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_all(message.as_bytes()).unwrap(); + fn notify(&mut self, bytes: B) + where B: Into> + { + let message = bytes.into(); + self.0.write_all(&message[..]).unwrap(); + } +} + +pub struct LoopNotifier(pub ::mio::channel::Sender<::EventLoopMessage>); + +impl Notify for LoopNotifier { + fn notify(&mut self, bytes: B) + where B: Into> + { + let bytes = bytes.into(); + match self.0.send(::EventLoopMessage::Input(bytes)) { + Ok(_) => (), + Err(_) => panic!("expected send event loop msg"), + } } } @@ -277,7 +297,7 @@ impl Processor { // Modifier keys if binding.mods.is_all() || mods.intersects(binding.mods) { // everything matches - notifier.notify(binding.send); + notifier.notify(binding.send.as_bytes()); break; } } -- cgit