summaryrefslogtreecommitdiffstats
path: root/src/config/keymap/keymapping.rs
diff options
context:
space:
mode:
authorJeff Zhao <jeff.no.zhao@gmail.com>2022-07-24 10:31:06 -0400
committerJeff Zhao <jeff.no.zhao@gmail.com>2022-07-24 10:31:06 -0400
commitf39c918bb7e454d622a06d25096f68e19d3fc915 (patch)
tree1a7d18e263c7f37d4f092e900393bc97ce297019 /src/config/keymap/keymapping.rs
parentaaa99c2d98a8dfa791813c350677af59a896068e (diff)
make ambiguous command message more clear
Diffstat (limited to 'src/config/keymap/keymapping.rs')
-rw-r--r--src/config/keymap/keymapping.rs21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/config/keymap/keymapping.rs b/src/config/keymap/keymapping.rs
index a14cb12..5b8ba94 100644
--- a/src/config/keymap/keymapping.rs
+++ b/src/config/keymap/keymapping.rs
@@ -9,10 +9,15 @@ use termion::event::Event;
use crate::config::{parse_to_config_file, TomlConfigFile};
use crate::error::JoshutoResult;
use crate::key_command::{Command, CommandKeybind};
+use crate::traits::ToString;
use crate::util::keyparse::str_to_event;
use super::DEFAULT_CONFIG_FILE_PATH;
+enum KeymapError {
+ Conflict,
+}
+
#[derive(Debug, Deserialize)]
struct CommandKeymap {
pub command: String,
@@ -77,7 +82,13 @@ fn vec_to_map(vec: &[CommandKeymap]) -> HashMap<Event, CommandKeybind> {
let result = insert_keycommand(&mut hashmap, command, &events);
match result {
Ok(_) => {}
- Err(e) => eprintln!("{}", e),
+ Err(e) => match e {
+ KeymapError::Conflict => {
+ let events_str: Vec<String> =
+ events.iter().map(|e| e.to_string()).collect();
+ eprintln!("Error: Ambiguous Keymapping: Multiple commands mapped to key sequence {:?}", events_str);
+ }
+ },
}
}
Err(e) => eprintln!("{}", e),
@@ -117,7 +128,7 @@ fn insert_keycommand(
keymap: &mut KeyMapping,
keycommand: Command,
events: &[Event],
-) -> Result<(), String> {
+) -> Result<(), KeymapError> {
let num_events = events.len();
if num_events == 0 {
return Ok(());
@@ -126,9 +137,7 @@ fn insert_keycommand(
let event = events[0].clone();
if num_events == 1 {
match keymap.entry(event) {
- Entry::Occupied(_) => {
- return Err(format!("Error: Keybindings ambiguous for {}", keycommand))
- }
+ Entry::Occupied(_) => return Err(KeymapError::Conflict),
Entry::Vacant(entry) => entry.insert(CommandKeybind::SimpleKeybind(keycommand)),
};
return Ok(());
@@ -139,7 +148,7 @@ fn insert_keycommand(
CommandKeybind::CompositeKeybind(ref mut m) => {
insert_keycommand(m, keycommand, &events[1..])
}
- _ => Err(format!("Error: Keybindings ambiguous for {}", keycommand)),
+ _ => Err(KeymapError::Conflict),
},
Entry::Vacant(entry) => {
let mut new_map = KeyMapping::new();