diff options
author | Jeff Zhao <jeff.no.zhao@gmail.com> | 2023-08-12 15:52:52 -0400 |
---|---|---|
committer | Jeff Zhao <jeff.no.zhao@gmail.com> | 2023-08-12 15:52:52 -0400 |
commit | 541f16850e33145ff657211e43a12f2327f188a6 (patch) | |
tree | 7f706b804c6e9d04a0425eadae628aef78108bd4 /src/config/keymap | |
parent | f9ebd1055b916532e307e1b64be296d74e760d0b (diff) |
add optional description to keymaps
Diffstat (limited to 'src/config/keymap')
-rw-r--r-- | src/config/keymap/keymapping.rs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/config/keymap/keymapping.rs b/src/config/keymap/keymapping.rs index b81e4fc..6bccc2a 100644 --- a/src/config/keymap/keymapping.rs +++ b/src/config/keymap/keymapping.rs @@ -18,19 +18,20 @@ enum KeymapError { Conflict, } -#[derive(Debug, Deserialize)] +#[derive(Clone, Debug, Deserialize)] struct CommandKeymap { pub command: String, + pub description: Option<String>, pub keys: Vec<String>, } -#[derive(Debug, Deserialize)] +#[derive(Clone, Debug, Deserialize)] struct AppModeKeyMapping { #[serde(default)] pub keymap: Vec<CommandKeymap>, } -#[derive(Debug, Deserialize)] +#[derive(Clone, Debug, Deserialize)] struct AppKeyMappingRaw { pub default_view: AppModeKeyMapping, pub task_view: AppModeKeyMapping, @@ -80,7 +81,8 @@ fn vec_to_map(vec: &[CommandKeymap]) -> HashMap<Event, CommandKeybind> { } let command_str = command.command(); - let result = insert_keycommand(&mut hashmap, command, &events); + let command_description = m.description.to_owned(); + let result = insert_keycommand(&mut hashmap, command, command_description, &events); match result { Ok(_) => {} Err(e) => match e { @@ -125,6 +127,7 @@ impl std::default::Default for AppKeyMapping { fn insert_keycommand( keymap: &mut KeyMapping, keycommand: Command, + description: Option<String>, events: &[Event], ) -> Result<(), KeymapError> { let num_events = events.len(); @@ -136,7 +139,10 @@ fn insert_keycommand( if num_events == 1 { match keymap.entry(event) { Entry::Occupied(_) => return Err(KeymapError::Conflict), - Entry::Vacant(entry) => entry.insert(CommandKeybind::SimpleKeybind(keycommand)), + Entry::Vacant(entry) => entry.insert(CommandKeybind::SimpleKeybind { + command: keycommand, + description: description, + }), }; return Ok(()); } @@ -144,13 +150,13 @@ fn insert_keycommand( match keymap.entry(event) { Entry::Occupied(mut entry) => match entry.get_mut() { CommandKeybind::CompositeKeybind(ref mut m) => { - insert_keycommand(m, keycommand, &events[1..]) + insert_keycommand(m, keycommand, description, &events[1..]) } _ => Err(KeymapError::Conflict), }, Entry::Vacant(entry) => { let mut new_map = KeyMapping::new(); - let result = insert_keycommand(&mut new_map, keycommand, &events[1..]); + let result = insert_keycommand(&mut new_map, keycommand, description, &events[1..]); if result.is_ok() { let composite_command = CommandKeybind::CompositeKeybind(new_map); entry.insert(composite_command); |