aboutsummaryrefslogtreecommitdiff
path: root/src/event.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/event.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/event.rs')
-rw-r--r--src/event.rs29
1 files changed, 14 insertions, 15 deletions
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<N> {
+ notifier: N,
input_processor: input::Processor,
terminal: Arc<FairMutex<Term>>,
resize_tx: mpsc::Sender<(u32, u32)>,
}
-impl<'a, W> Processor<'a, W>
- where W: std::io::Write
-{
+impl<N: input::Notify> Processor<N> {
/// 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<FairMutex<Term>>,
- resize_tx: mpsc::Sender<(u32, u32)>)
- -> Processor<W>
- {
+ pub fn new(
+ notifier: N,
+ terminal: Arc<FairMutex<Term>>,
+ resize_tx: mpsc::Sender<(u32, u32)>
+ ) -> Processor<N> {
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());
},
_ => (),
}