diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/show_tasks.rs | 2 | ||||
-rw-r--r-- | src/config/keymap/keymapping.rs | 21 | ||||
-rw-r--r-- | src/main.rs | 1 | ||||
-rw-r--r-- | src/run.rs | 2 | ||||
-rw-r--r-- | src/traits/mod.rs | 3 | ||||
-rw-r--r-- | src/traits/to_string.rs (renamed from src/util/to_string.rs) | 0 | ||||
-rw-r--r-- | src/ui/views/tui_command_menu.rs | 2 | ||||
-rw-r--r-- | src/util/mod.rs | 1 |
8 files changed, 22 insertions, 10 deletions
diff --git a/src/commands/show_tasks.rs b/src/commands/show_tasks.rs index 64312a1..9dd8ddf 100644 --- a/src/commands/show_tasks.rs +++ b/src/commands/show_tasks.rs @@ -4,9 +4,9 @@ use crate::error::JoshutoResult; use crate::event::process_event; use crate::event::AppEvent; use crate::key_command::{Command, CommandKeybind}; +use crate::traits::ToString; use crate::ui::views::TuiWorkerView; use crate::ui::AppBackend; -use crate::util::to_string::ToString; pub fn show_tasks( context: &mut AppContext, 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(); diff --git a/src/main.rs b/src/main.rs index fc84b99..26f1d59 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ mod key_command; mod preview; mod run; mod tab; +mod traits; mod ui; mod util; @@ -7,10 +7,10 @@ use crate::event::AppEvent; use crate::key_command::{AppExecute, CommandKeybind}; use crate::preview::preview_default; use crate::tab::JoshutoTab; +use crate::traits::ToString; use crate::ui; use crate::ui::views; use crate::ui::views::TuiView; -use crate::util::to_string::ToString; use termion::event::{Event, Key}; use tui::layout::Rect; diff --git a/src/traits/mod.rs b/src/traits/mod.rs new file mode 100644 index 0000000..516d95d --- /dev/null +++ b/src/traits/mod.rs @@ -0,0 +1,3 @@ +mod to_string; + +pub use to_string::*; diff --git a/src/util/to_string.rs b/src/traits/to_string.rs index cbfffb0..cbfffb0 100644 --- a/src/util/to_string.rs +++ b/src/traits/to_string.rs diff --git a/src/ui/views/tui_command_menu.rs b/src/ui/views/tui_command_menu.rs index 2faf0e2..1d0b04b 100644 --- a/src/ui/views/tui_command_menu.rs +++ b/src/ui/views/tui_command_menu.rs @@ -6,9 +6,9 @@ use tui::widgets::{Clear, Widget}; use crate::config::KeyMapping; use crate::context::AppContext; +use crate::traits::ToString; use crate::ui::views::TuiView; use crate::ui::widgets::TuiMenu; -use crate::util::to_string::ToString; const BORDER_HEIGHT: usize = 1; const BOTTOM_MARGIN: usize = 1; diff --git a/src/util/mod.rs b/src/util/mod.rs index 7e43d3a..c7ad758 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -8,5 +8,4 @@ pub mod process; pub mod search; pub mod string; pub mod style; -pub mod to_string; pub mod unix; |