summaryrefslogtreecommitdiff
path: root/src/input.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/input.rs')
-rw-r--r--src/input.rs46
1 files changed, 44 insertions, 2 deletions
diff --git a/src/input.rs b/src/input.rs
index be8ed0d1..c2473448 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -81,7 +81,7 @@ pub trait ActionContext {
/// Describes a state and action to take in that state
///
/// This is the shared component of `MouseBinding` and `KeyBinding`
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Binding<T> {
/// Modifier keys required to activate binding
pub mods: ModifiersState,
@@ -107,6 +107,30 @@ pub type KeyBinding = Binding<Key>;
/// Bindings that are triggered by a mouse button
pub type MouseBinding = Binding<MouseButton>;
+impl Default for KeyBinding {
+ fn default() -> KeyBinding {
+ KeyBinding {
+ mods: Default::default(),
+ action: Action::Esc(String::new()),
+ mode: TermMode::NONE,
+ notmode: TermMode::NONE,
+ trigger: Key::A,
+ }
+ }
+}
+
+impl Default for MouseBinding {
+ fn default() -> MouseBinding {
+ MouseBinding {
+ mods: Default::default(),
+ action: Action::Esc(String::new()),
+ mode: TermMode::NONE,
+ notmode: TermMode::NONE,
+ trigger: MouseButton::Left,
+ }
+ }
+}
+
impl<T: Eq> Binding<T> {
#[inline]
fn is_triggered_by(
@@ -124,6 +148,14 @@ impl<T: Eq> Binding<T> {
self.not_mode_matches(mode) &&
self.mods_match(mods, relaxed)
}
+
+ #[inline]
+ pub fn triggers_match(&self, binding: &Binding<T>) -> bool {
+ self.trigger == binding.trigger
+ && self.mode == binding.mode
+ && self.notmode == binding.notmode
+ && self.mods == binding.mods
+ }
}
impl<T> Binding<T> {
@@ -154,7 +186,7 @@ impl<T> Binding<T> {
}
}
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Action {
/// Write an escape sequence
Esc(String),
@@ -206,6 +238,15 @@ pub enum Action {
/// Spawn a new instance of Alacritty.
SpawnNewInstance,
+
+ /// No action.
+ None,
+}
+
+impl Default for Action {
+ fn default() -> Action {
+ Action::None
+ }
}
impl Action {
@@ -287,6 +328,7 @@ impl Action {
Action::SpawnNewInstance => {
ctx.spawn_new_instance();
},
+ Action::None => (),
}
}