diff options
author | qkzk <qu3nt1n@gmail.com> | 2022-12-10 23:52:09 +0100 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2022-12-10 23:52:09 +0100 |
commit | ba3c218ac7aa99177fe6fcbca878d72667161605 (patch) | |
tree | 33a8c1ede9b584f24b22c1f5d0a9158484002e2b /src/actioner.rs | |
parent | 3f332986bc89fda5e83bc65d1c647b5069294fde (diff) |
more detail on errors, parse keymaps directly
Diffstat (limited to 'src/actioner.rs')
-rw-r--r-- | src/actioner.rs | 81 |
1 files changed, 42 insertions, 39 deletions
diff --git a/src/actioner.rs b/src/actioner.rs index 02954d0..002be24 100644 --- a/src/actioner.rs +++ b/src/actioner.rs @@ -2,7 +2,7 @@ use tuikit::prelude::{Event, Key, MouseButton}; use crate::event_exec::EventExec; use crate::fm_error::FmResult; -use crate::keybindings::Keybindings; +use crate::keybindings::Bindings; use crate::mode::{MarkAction, Mode}; use crate::status::Status; @@ -11,13 +11,13 @@ use crate::status::Status; /// All keys are mapped to relevent events on tabs.selected(). /// Keybindings are read from `Config`. pub struct Actioner { - binds: Keybindings, + binds: Bindings, } impl Actioner { /// Creates a map of configurable keybindings to `EventChar` /// The `EventChar` is then associated to a `tabs.selected(). method. - pub fn new(binds: Keybindings) -> Self { + pub fn new(binds: Bindings) -> Self { Self { binds } } /// Reaction to received events. @@ -31,7 +31,7 @@ impl Actioner { Event::Key(Key::Backspace) => Self::backspace(status), Event::Key(Key::Ctrl('d')) => Self::delete(status), Event::Key(Key::Ctrl('q')) => Self::escape(status), - Event::Key(Key::Char(c)) => Self::char(status, c, &self.binds), + Event::Key(Key::Char(c)) => Self::char(status, Key::Char(c), &self.binds), Event::Key(Key::Home) => Self::home(status), Event::Key(Key::End) => Self::end(status), Event::Key(Key::PageDown) => Self::page_down(status), @@ -316,42 +316,45 @@ impl Actioner { /// Match read key to a relevent event, depending on keybindings. /// Keybindings are read from `Config`. - fn char(status: &mut Status, c: char, binds: &Keybindings) -> FmResult<()> { - match status.selected().mode { - Mode::Newfile | Mode::Newdir | Mode::Chmod | Mode::Rename | Mode::Filter => { - EventExec::event_text_insertion(status.selected(), c); - Ok(()) - } - Mode::RegexMatch => { - EventExec::event_text_insertion(status.selected(), c); - status.select_from_regex()?; - Ok(()) - } - Mode::Goto | Mode::Exec | Mode::Search => { - EventExec::event_text_insert_and_complete(status.selected(), c) - } - Mode::Normal => match binds.get(&c) { - Some(event_char) => event_char.match_char(status), - None => Ok(()), - }, - Mode::Help | Mode::Preview | Mode::Shortcut => { - EventExec::event_normal(status.selected()) - } - Mode::Jump => Ok(()), - Mode::History => Ok(()), - Mode::NeedConfirmation => { - if c == 'y' { - let _ = EventExec::exec_last_edition(status); + fn char(status: &mut Status, k: Key, binds: &Bindings) -> FmResult<()> { + match k { + Key::Char(c) => match status.selected().mode { + Mode::Newfile | Mode::Newdir | Mode::Chmod | Mode::Rename | Mode::Filter => { + EventExec::event_text_insertion(status.selected(), c); + Ok(()) } - EventExec::event_leave_need_confirmation(status.selected()); - Ok(()) - } - Mode::Marks(MarkAction::Jump) => EventExec::exec_marks_jump(status, c), - Mode::Marks(MarkAction::New) => EventExec::exec_marks_new(status, c), - Mode::Sort => { - EventExec::event_leave_sort(status.selected(), c); - Ok(()) - } + Mode::RegexMatch => { + EventExec::event_text_insertion(status.selected(), c); + status.select_from_regex()?; + Ok(()) + } + Mode::Goto | Mode::Exec | Mode::Search => { + EventExec::event_text_insert_and_complete(status.selected(), c) + } + Mode::Normal => match binds.get(&k) { + Some(event_char) => event_char.match_char(status), + None => Ok(()), + }, + Mode::Help | Mode::Preview | Mode::Shortcut => { + EventExec::event_normal(status.selected()) + } + Mode::Jump => Ok(()), + Mode::History => Ok(()), + Mode::NeedConfirmation => { + if c == 'y' { + let _ = EventExec::exec_last_edition(status); + } + EventExec::event_leave_need_confirmation(status.selected()); + Ok(()) + } + Mode::Marks(MarkAction::Jump) => EventExec::exec_marks_jump(status, c), + Mode::Marks(MarkAction::New) => EventExec::exec_marks_new(status, c), + Mode::Sort => { + EventExec::event_leave_sort(status.selected(), c); + Ok(()) + } + }, + _ => Ok(()), } } } |