aboutsummaryrefslogtreecommitdiff
path: root/src/input.rs
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-07-02 08:32:28 -0700
committerJoe Wilm <joe@jwilm.com>2016-07-02 08:32:28 -0700
commitbc2793a762b505d2d3c7af65e878f864a36cb19b (patch)
treea51d1c5ef9938a3b82ca3802cf1d9982cd77a87b /src/input.rs
parentf2e6d66a5e8ada1bd0c860eaa3d50e100a72f68b (diff)
downloadalacritty-bc2793a762b505d2d3c7af65e878f864a36cb19b.tar.gz
alacritty-bc2793a762b505d2d3c7af65e878f864a36cb19b.zip
Move WriteNotifier type into input module
It's a generic impl of `input::Notify` for `Write` types; as such, it seems completely reasonable to include in the input module. Moving it also serves to declutter main.
Diffstat (limited to 'src/input.rs')
-rw-r--r--src/input.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/input.rs b/src/input.rs
index 6d4d3ab9..ffa19fa8 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -23,6 +23,8 @@
//! APIs
//!
//! TODO handling xmodmap would be good
+use std::io::Write;
+
use glutin::{ElementState, VirtualKeyCode};
use term::mode::{self, TermMode};
@@ -108,6 +110,15 @@ pub trait Notify {
fn notify(&mut self, &str);
}
+/// 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(message.as_bytes()).unwrap();
+ }
+}
+
/// Describes a key combination that should emit a control sequence
///
/// The actual triggering key is omitted here since bindings are grouped by the trigger key.