aboutsummaryrefslogtreecommitdiff
path: root/src/event_loop.rs
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-12-26 18:33:27 -0500
committerJoe Wilm <joe@jwilm.com>2016-12-26 18:39:30 -0500
commit358c9fa17d9b088bae79f7d352a8cc21878f6303 (patch)
tree40926a8e496360913e3ebd5a0991e7b118eef85f /src/event_loop.rs
parent3b7c7377c913b92c52f45660fa94001db38c8bc6 (diff)
downloadalacritty-358c9fa17d9b088bae79f7d352a8cc21878f6303.tar.gz
alacritty-358c9fa17d9b088bae79f7d352a8cc21878f6303.zip
Major cleanup for event handling
The event handling code grew organically over time, and with that came a number of warts. The primary issue was with passing some random selection of arguments to the input::Processor based on what the input was. There was the issue that if multiple events were drained from a single PollEventsIterator, the terminal mutex was potentially locked and unlocked many times. Finally, and perhaps most importantly, there was no good way to pass necessary state to the Action executor without going through several API layers. To fix all that, the input::ActionContext and input::Processor are now generated once per call to the event::Processor. The input::Processor holds onto the ActionContext so that it doesn't need to be passed through layers of function calls. When a binding is activated, the ActionContext is simply passed to the handler. This did have the effect of breaking the input::Processor tests (specifically, those relating to bindings). The issue was not addressed in this commit since a larger refactor of the bindings is planned which should also improve testability.
Diffstat (limited to 'src/event_loop.rs')
-rw-r--r--src/event_loop.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/event_loop.rs b/src/event_loop.rs
index 44d71f94..a6eed40e 100644
--- a/src/event_loop.rs
+++ b/src/event_loop.rs
@@ -11,6 +11,7 @@ use mio::unix::EventedFd;
use ansi;
use display;
+use event;
use term::Term;
use util::thread;
use sync::FairMutex;
@@ -52,6 +53,21 @@ pub struct State {
parser: ansi::Processor,
}
+pub struct Notifier(pub ::mio::channel::Sender<Msg>);
+
+impl event::Notify for Notifier {
+ fn notify<B>(&mut self, bytes: B)
+ where B: Into<Cow<'static, [u8]>>
+ {
+ let bytes = bytes.into();
+ match self.0.send(Msg::Input(bytes)) {
+ Ok(_) => (),
+ Err(_) => panic!("expected send event loop msg"),
+ }
+ }
+}
+
+
impl Default for State {
fn default() -> State {
State {