summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--example/config.yaml1
-rw-r--r--src/common/input/keybinds.rs57
2 files changed, 53 insertions, 5 deletions
diff --git a/example/config.yaml b/example/config.yaml
index 3bb4fbfad..644d4e4f2 100644
--- a/example/config.yaml
+++ b/example/config.yaml
@@ -1,5 +1,6 @@
---
keybinds:
+ unbind: true
normal:
- action: [GoToTab: 1,]
key: [F: 1,]
diff --git a/src/common/input/keybinds.rs b/src/common/input/keybinds.rs
index 6a14a1823..653213a77 100644
--- a/src/common/input/keybinds.rs
+++ b/src/common/input/keybinds.rs
@@ -7,14 +7,29 @@ use serde::Deserialize;
use strum::IntoEnumIterator;
use zellij_tile::data::*;
+/// Used in the config struct
#[derive(Clone, Debug, PartialEq)]
pub struct Keybinds(HashMap<InputMode, ModeKeybinds>);
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ModeKeybinds(HashMap<Key, Vec<Action>>);
/// Intermediate struct used for deserialisation
+/// Used in the config file.
#[derive(Clone, Debug, PartialEq, Deserialize)]
-pub struct KeybindsFromYaml(HashMap<InputMode, Vec<KeyActionFromYaml>>);
+pub struct KeybindsFromYaml {
+ #[serde(flatten)]
+ keybinds: HashMap<InputMode, Vec<KeyActionUnbind>>,
+ unbind: Unbind,
+}
+
+/// Intermediate enum used for deserialisation
+#[derive(Clone, Debug, PartialEq, Deserialize)]
+#[serde(untagged)]
+enum KeyActionUnbind {
+ KeyAction(KeyActionFromYaml),
+ // TODO: use the enum
+ //Unbind(UnbindFromYaml),
+}
/// Intermediate struct used for deserialisation
#[derive(Clone, Debug, PartialEq, Deserialize)]
@@ -23,6 +38,22 @@ pub struct KeyActionFromYaml {
key: Vec<Key>,
}
+/// Intermediate struct used for deserialisation
+#[derive(Clone, Debug, PartialEq, Eq, Hash, Deserialize)]
+struct UnbindFromYaml {
+ unbind: Unbind,
+}
+
+/// List of keys, for which to disable their respective default actions
+/// `All` is a catch all, and will disable the default actions for all keys.
+#[derive(Clone, Debug, PartialEq, Eq, Hash, Deserialize)]
+#[serde(untagged)]
+enum Unbind {
+ All(bool),
+ // TODO: use the enum
+ //Keys(Vec<Key>),
+}
+
impl Default for Keybinds {
fn default() -> Keybinds {
let mut defaults = Keybinds::new();
@@ -41,9 +72,16 @@ impl Keybinds {
Keybinds(HashMap::<InputMode, ModeKeybinds>::new())
}
- pub fn get_default_keybinds_with_config(keybinds: Option<KeybindsFromYaml>) -> Keybinds {
- let default_keybinds = Keybinds::default();
- if let Some(keybinds) = keybinds {
+ pub fn get_default_keybinds_with_config(from_yaml: Option<KeybindsFromYaml>) -> Keybinds {
+ let default_keybinds = match from_yaml.clone() {
+ Some(keybinds) => match keybinds.unbind {
+ Unbind::All(true) => Keybinds::new(),
+ Unbind::All(false) => Keybinds::default(),
+ },
+ None => Keybinds::default(),
+ };
+
+ if let Some(keybinds) = from_yaml {
default_keybinds.merge_keybinds(Keybinds::from(keybinds))
} else {
default_keybinds
@@ -336,7 +374,7 @@ impl From<KeybindsFromYaml> for Keybinds {
for mode in InputMode::iter() {
let mut mode_keybinds = ModeKeybinds::new();
- for key_action in keybinds_from_yaml.0.get(&mode).iter() {
+ for key_action in keybinds_from_yaml.keybinds.get(&mode).iter() {
for keybind in key_action.iter() {
mode_keybinds = mode_keybinds.merge(ModeKeybinds::from(keybind.clone()));
}
@@ -362,6 +400,15 @@ impl From<KeyActionFromYaml> for ModeKeybinds {
}
}
+// Currently an enum for future use
+impl From<KeyActionUnbind> for ModeKeybinds {
+ fn from(key_action_unbind: KeyActionUnbind) -> ModeKeybinds {
+ match key_action_unbind {
+ KeyActionUnbind::KeyAction(key_action) => ModeKeybinds::from(key_action),
+ }
+ }
+}
+
// The unit test location.
#[cfg(test)]
#[path = "./unit/keybinds_test.rs"]