aboutsummaryrefslogtreecommitdiff
path: root/src/input.rs
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-09-24 16:11:50 -0700
committerJoe Wilm <joe@jwilm.com>2016-09-24 17:03:07 -0700
commitf1499d1d4518674c6c3c5c859a7028709bdd741d (patch)
tree4500d7a560b01d33b3da02e44c90ca7b0385158d /src/input.rs
parentbe09467d48a5b7644411c2a09d948ee89509894e (diff)
downloadalacritty-f1499d1d4518674c6c3c5c859a7028709bdd741d.tar.gz
alacritty-f1499d1d4518674c6c3c5c859a7028709bdd741d.zip
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.
Diffstat (limited to 'src/input.rs')
-rw-r--r--src/input.rs28
1 files changed, 24 insertions, 4 deletions
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<B: Into<Cow<'static, [u8]>>>(&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<B>(&mut self, bytes: B)
+ where B: Into<Cow<'static, [u8]>>
+ {
+ let message = bytes.into();
+ self.0.write_all(&message[..]).unwrap();
+ }
+}
+
+pub struct LoopNotifier(pub ::mio::channel::Sender<::EventLoopMessage>);
+
+impl Notify for LoopNotifier {
+ fn notify<B>(&mut self, bytes: B)
+ where B: Into<Cow<'static, [u8]>>
+ {
+ 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;
}
}