diff options
author | qkzk <qu3nt1n@gmail.com> | 2022-12-17 23:53:20 +0100 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2022-12-17 23:53:20 +0100 |
commit | b7d78da0b255ef246c8c0f4698a2eb07a5bed891 (patch) | |
tree | 3b602d6855d344051c90c6b22a7cc42adab19b72 | |
parent | 95107a477d3ab96074abca0ac6e8cd50c5b509c6 (diff) |
rename modes requiring inputmode-refactor
-rw-r--r-- | development.md | 5 | ||||
-rw-r--r-- | src/completion.rs | 2 | ||||
-rw-r--r-- | src/event_dispatch.rs | 12 | ||||
-rw-r--r-- | src/event_exec.rs | 66 | ||||
-rw-r--r-- | src/mode.rs | 30 | ||||
-rw-r--r-- | src/term_manager.rs | 54 |
6 files changed, 97 insertions, 72 deletions
diff --git a/development.md b/development.md index 1683f62..9b19e91 100644 --- a/development.md +++ b/development.md @@ -222,10 +222,13 @@ - [x] group every mode requiring input (2 variants with subvariants: with or wirtout completion) - [x] combine help & preview + - [x] better first line for mode filter - [ ] BUG: help has wrong first line +- [ ] Version 0.1.2 + + - [ ] refactor Preview::new() an enum may be useful ? - [ ] parse .. in goto - - [ ] better first line for mode filter - [ ] Version 0.2.0 diff --git a/src/completion.rs b/src/completion.rs index 1bf9aa1..c3c9d9d 100644 --- a/src/completion.rs +++ b/src/completion.rs @@ -31,7 +31,7 @@ pub struct Completion { impl Completion { pub fn set_kind(&mut self, mode: &Mode) { - if let Mode::Completed(completion_kind) = mode { + if let Mode::InputCompleted(completion_kind) = mode { self.kind = completion_kind.clone() } else { self.kind = CompletionKind::Nothing diff --git a/src/event_dispatch.rs b/src/event_dispatch.rs index 3821505..3e5ab28 100644 --- a/src/event_dispatch.rs +++ b/src/event_dispatch.rs @@ -53,26 +53,26 @@ impl EventDispatcher { fn char(&self, status: &mut Status, key_char: Key) -> FmResult<()> { match key_char { Key::Char(c) => match status.selected_non_mut().mode { - Mode::ReadInput(InputKind::Marks(MarkAction::Jump)) => { + Mode::InputSimple(InputKind::Marks(MarkAction::Jump)) => { EventExec::exec_marks_jump(status, c) } - Mode::ReadInput(InputKind::Marks(MarkAction::New)) => { + Mode::InputSimple(InputKind::Marks(MarkAction::New)) => { EventExec::exec_marks_new(status, c) } - Mode::ReadInput(InputKind::Sort) => { + Mode::InputSimple(InputKind::Sort) => { EventExec::event_leave_sort(status.selected(), c); Ok(()) } - Mode::ReadInput(InputKind::RegexMatch) => { + Mode::InputSimple(InputKind::RegexMatch) => { EventExec::event_text_insertion(status.selected(), c); status.select_from_regex()?; Ok(()) } - Mode::ReadInput(_) => { + Mode::InputSimple(_) => { EventExec::event_text_insertion(status.selected(), c); Ok(()) } - Mode::Completed(_) => { + Mode::InputCompleted(_) => { EventExec::event_text_insert_and_complete(status.selected(), c) } Mode::Normal => match self.binds.get(&key_char) { diff --git a/src/event_exec.rs b/src/event_exec.rs index 61ff3cc..27cc316 100644 --- a/src/event_exec.rs +++ b/src/event_exec.rs @@ -118,7 +118,7 @@ impl EventExec { if status.selected().path_content.files.is_empty() { return Ok(()); } - status.selected().mode = Mode::ReadInput(InputKind::Chmod); + status.selected().mode = Mode::InputSimple(InputKind::Chmod); if status.flagged.is_empty() { status.flagged.insert( status.tabs[status.index] @@ -144,13 +144,13 @@ impl EventExec { /// Enter Marks new mode, allowing to bind a char to a path. pub fn event_marks_new(status: &mut Status) -> FmResult<()> { - status.selected().mode = Mode::ReadInput(InputKind::Marks(MarkAction::New)); + status.selected().mode = Mode::InputSimple(InputKind::Marks(MarkAction::New)); Ok(()) } /// Enter Marks jump mode, allowing to jump to a marked file. pub fn event_marks_jump(status: &mut Status) -> FmResult<()> { - status.selected().mode = Mode::ReadInput(InputKind::Marks(MarkAction::Jump)); + status.selected().mode = Mode::InputSimple(InputKind::Marks(MarkAction::Jump)); Ok(()) } @@ -513,20 +513,20 @@ impl EventExec { /// Enter the new dir mode. pub fn event_new_dir(tab: &mut Tab) -> FmResult<()> { - tab.mode = Mode::ReadInput(InputKind::Newdir); + tab.mode = Mode::InputSimple(InputKind::Newdir); Ok(()) } /// Enter the new file mode. pub fn event_new_file(tab: &mut Tab) -> FmResult<()> { - tab.mode = Mode::ReadInput(InputKind::Newfile); + tab.mode = Mode::InputSimple(InputKind::Newfile); Ok(()) } /// Enter the execute mode. Most commands must be executed to allow for /// a confirmation. pub fn event_exec(tab: &mut Tab) -> FmResult<()> { - tab.mode = Mode::Completed(CompletionKind::Exec); + tab.mode = Mode::InputCompleted(CompletionKind::Exec); Ok(()) } @@ -572,20 +572,20 @@ impl EventExec { /// Matching items are displayed as you type them. pub fn event_search(tab: &mut Tab) -> FmResult<()> { tab.searched = None; - tab.mode = Mode::Completed(CompletionKind::Search); + tab.mode = Mode::InputCompleted(CompletionKind::Search); Ok(()) } /// Enter the regex mode. /// Every file matching the typed regex will be flagged. pub fn event_regex_match(tab: &mut Tab) -> FmResult<()> { - tab.mode = Mode::ReadInput(InputKind::RegexMatch); + tab.mode = Mode::InputSimple(InputKind::RegexMatch); Ok(()) } /// Enter the sort mode, allowing the user to select a sort method. pub fn event_sort(tab: &mut Tab) -> FmResult<()> { - tab.mode = Mode::ReadInput(InputKind::Sort); + tab.mode = Mode::InputSimple(InputKind::Sort); Ok(()) } @@ -680,13 +680,13 @@ impl EventExec { /// Enter the rename mode. pub fn event_rename(tab: &mut Tab) -> FmResult<()> { - tab.mode = Mode::ReadInput(InputKind::Rename); + tab.mode = Mode::InputSimple(InputKind::Rename); Ok(()) } /// Enter the goto mode where an user can type a path to jump to. pub fn event_goto(tab: &mut Tab) -> FmResult<()> { - tab.mode = Mode::Completed(CompletionKind::Goto); + tab.mode = Mode::InputCompleted(CompletionKind::Goto); tab.completion.reset(); Ok(()) } @@ -819,7 +819,7 @@ impl EventExec { /// Enter the filter mode, where you can filter. /// See `crate::filter::Filter` for more details. pub fn event_filter(tab: &mut Tab) -> FmResult<()> { - tab.mode = Mode::ReadInput(InputKind::Filter); + tab.mode = Mode::InputSimple(InputKind::Filter); Ok(()) } @@ -1079,7 +1079,7 @@ impl EventExec { Mode::Jump => EventExec::event_jumplist_prev(status), Mode::History => EventExec::event_history_prev(status.selected()), Mode::Shortcut => EventExec::event_shortcut_prev(status.selected()), - Mode::Completed(_) => { + Mode::InputCompleted(_) => { status.selected().completion.prev(); } _ => (), @@ -1095,7 +1095,7 @@ impl EventExec { Mode::Jump => EventExec::event_jumplist_next(status), Mode::History => EventExec::event_history_next(status.selected()), Mode::Shortcut => EventExec::event_shortcut_next(status.selected()), - Mode::Completed(_) => status.selected().completion.next(), + Mode::InputCompleted(_) => status.selected().completion.next(), _ => (), }; Ok(()) @@ -1106,7 +1106,7 @@ impl EventExec { pub fn event_move_left(status: &mut Status) -> FmResult<()> { match status.selected().mode { Mode::Normal => EventExec::event_move_to_parent(status.selected()), - Mode::ReadInput(_) | Mode::Completed(_) => { + Mode::InputSimple(_) | Mode::InputCompleted(_) => { EventExec::event_move_cursor_left(status.selected()); Ok(()) } @@ -1120,7 +1120,7 @@ impl EventExec { pub fn event_move_right(status: &mut Status) -> FmResult<()> { match status.selected().mode { Mode::Normal => EventExec::exec_file(status), - Mode::ReadInput(_) | Mode::Completed(_) => { + Mode::InputSimple(_) | Mode::InputCompleted(_) => { EventExec::event_move_cursor_right(status.selected()); Ok(()) } @@ -1131,7 +1131,7 @@ impl EventExec { /// Delete a char to the left in modes allowing edition. pub fn event_backspace(status: &mut Status) -> FmResult<()> { match status.selected().mode { - Mode::ReadInput(_) | Mode::Completed(_) => { + Mode::InputSimple(_) | Mode::InputCompleted(_) => { EventExec::event_delete_char_left(status.selected()); Ok(()) } @@ -1143,7 +1143,7 @@ impl EventExec { /// Delete all chars to the right in mode allowing edition. pub fn event_delete(status: &mut Status) -> FmResult<()> { match status.selected().mode { - Mode::ReadInput(_) | Mode::Completed(_) => { + Mode::InputSimple(_) | Mode::InputCompleted(_) => { EventExec::event_delete_chars_right(status.selected()); Ok(()) } @@ -1194,24 +1194,26 @@ impl EventExec { /// Reset to normal mode afterwards. pub fn enter(status: &mut Status) -> FmResult<()> { match status.selected().mode { - Mode::ReadInput(InputKind::Rename) => EventExec::exec_rename(status.selected())?, - Mode::ReadInput(InputKind::Newfile) => EventExec::exec_newfile(status.selected())?, - Mode::ReadInput(InputKind::Newdir) => EventExec::exec_newdir(status.selected())?, - Mode::ReadInput(InputKind::Chmod) => EventExec::exec_chmod(status)?, - Mode::ReadInput(InputKind::RegexMatch) => EventExec::exec_regex(status)?, - Mode::ReadInput(InputKind::Filter) => EventExec::exec_filter(status.selected())?, + Mode::InputSimple(InputKind::Rename) => EventExec::exec_rename(status.selected())?, + Mode::InputSimple(InputKind::Newfile) => EventExec::exec_newfile(status.selected())?, + Mode::InputSimple(InputKind::Newdir) => EventExec::exec_newdir(status.selected())?, + Mode::InputSimple(InputKind::Chmod) => EventExec::exec_chmod(status)?, + Mode::InputSimple(InputKind::RegexMatch) => EventExec::exec_regex(status)?, + Mode::InputSimple(InputKind::Filter) => EventExec::exec_filter(status.selected())?, Mode::Jump => EventExec::exec_jump(status)?, - Mode::Completed(CompletionKind::Exec) => EventExec::exec_exec(status.selected())?, - Mode::Completed(CompletionKind::Search) => EventExec::exec_search(status.selected()), - Mode::Completed(CompletionKind::Goto) => EventExec::exec_goto(status.selected())?, + Mode::InputCompleted(CompletionKind::Exec) => EventExec::exec_exec(status.selected())?, + Mode::InputCompleted(CompletionKind::Search) => { + EventExec::exec_search(status.selected()) + } + Mode::InputCompleted(CompletionKind::Goto) => EventExec::exec_goto(status.selected())?, Mode::History => EventExec::exec_history(status.selected())?, Mode::Shortcut => EventExec::exec_shortcut(status.selected())?, Mode::Normal => EventExec::exec_file(status)?, Mode::NeedConfirmation(_) | Mode::Preview - | Mode::Completed(CompletionKind::Nothing) - | Mode::ReadInput(InputKind::Sort) - | Mode::ReadInput(InputKind::Marks(_)) => (), + | Mode::InputCompleted(CompletionKind::Nothing) + | Mode::InputSimple(InputKind::Sort) + | Mode::InputSimple(InputKind::Marks(_)) => (), }; status.selected().input.reset(); @@ -1223,7 +1225,9 @@ impl EventExec { /// insert a completion in modes allowing completion. pub fn tab(status: &mut Status) -> FmResult<()> { match status.selected().mode { - Mode::Completed(_) => EventExec::event_replace_input_with_completion(status.selected()), + Mode::InputCompleted(_) => { + EventExec::event_replace_input_with_completion(status.selected()) + } Mode::Normal => status.next(), _ => (), }; diff --git a/src/mode.rs b/src/mode.rs index 4c2459e..1677b7a 100644 --- a/src/mode.rs +++ b/src/mode.rs @@ -76,7 +76,7 @@ pub enum Mode { Normal, /// We'll be able to complete the input string with /// different kind of completed items (exec, goto, search) - Completed(CompletionKind), + InputCompleted(CompletionKind), /// Display the help Jump, /// Confirmation is required before modification is made to existing files : @@ -89,25 +89,25 @@ pub enum Mode { /// Display predefined shortcuts Shortcut, /// Modes requiring an input that can't be completed - ReadInput(InputKind), + InputSimple(InputKind), } -impl fmt::Debug for Mode { +impl fmt::Display for Mode { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { Mode::Normal => write!(f, "Normal: "), - Mode::ReadInput(InputKind::Rename) => write!(f, "Rename: "), - Mode::ReadInput(InputKind::Chmod) => write!(f, "Chmod: "), - Mode::ReadInput(InputKind::Newfile) => write!(f, "Newfile: "), - Mode::ReadInput(InputKind::Newdir) => write!(f, "Newdir: "), - Mode::ReadInput(InputKind::RegexMatch) => write!(f, "Regex : "), - Mode::ReadInput(InputKind::Sort) => write!(f, "Sort: Kind Name Modif Size Ext Rev :"), - Mode::ReadInput(InputKind::Marks(_)) => write!(f, "Marks jump:"), - Mode::ReadInput(InputKind::Filter) => write!(f, "Filter: "), - Mode::Completed(CompletionKind::Exec) => write!(f, "Exec: "), - Mode::Completed(CompletionKind::Goto) => write!(f, "Goto : "), - Mode::Completed(CompletionKind::Search) => write!(f, "Search: "), - Mode::Completed(CompletionKind::Nothing) => write!(f, "Nothing: "), + Mode::InputSimple(InputKind::Rename) => write!(f, "Rename: "), + Mode::InputSimple(InputKind::Chmod) => write!(f, "Chmod: "), + Mode::InputSimple(InputKind::Newfile) => write!(f, "Newfile: "), + Mode::InputSimple(InputKind::Newdir) => write!(f, "Newdir: "), + Mode::InputSimple(InputKind::RegexMatch) => write!(f, "Regex: "), + Mode::InputSimple(InputKind::Sort) => write!(f, "Sort: Kind Name Modif Size Ext Rev :"), + Mode::InputSimple(InputKind::Marks(_)) => write!(f, "Marks jump:"), + Mode::InputSimple(InputKind::Filter) => write!(f, "Filter: "), + Mode::InputCompleted(CompletionKind::Exec) => write!(f, "Exec: "), + Mode::InputCompleted(CompletionKind::Goto) => write!(f, "Goto : "), + Mode::InputCompleted(CompletionKind::Search) => write!(f, "Search: "), + Mode::InputCompleted(CompletionKind::Nothing) => write!(f, "Nothing: "), Mode::Jump => write!(f, "Jump : "), Mode::History => write!(f, "History :"), Mode::NeedConfirmation(_) => write!(f, "Y/N :"), diff --git a/src/term_manager.rs b/src/term_manager.rs index f0d65d6..7af354c 100644 --- a/src/term_manager.rs +++ b/src/term_manager.rs @@ -59,13 +59,13 @@ impl<'a> Draw for WinTab<'a> { match self.tab.mode { Mode::Jump => self.jump_list(self.status, canvas), Mode::History => self.history(self.tab, canvas), - Mode::Completed(_) => self.completion(self.tab, canvas), + Mode::InputCompleted(_) => self.completion(self.tab, canvas), Mode::NeedConfirmation(confirmed_mode) => { self.confirmation(self.status, self.tab, confirmed_mode, canvas) } Mode::Preview => self.preview(self.tab, canvas), Mode::Shortcut => self.shortcuts(self.tab, canvas), - Mode::ReadInput(InputKind::Marks(_)) => self.marks(self.status, self.tab, canvas), + Mode::InputSimple(InputKind::Marks(_)) => self.marks(self.status, self.tab, canvas), _ => self.files(self.status, self.tab, canvas), }?; self.cursor(self.tab, canvas)?; @@ -106,12 +106,32 @@ impl<'a> WinTab<'a> { } fn second_line(&self, status: &Status, tab: &Tab, canvas: &mut dyn Canvas) -> FmResult<()> { - if let Some(file) = tab.path_content.selected_file() { - let owner_size = file.owner.len(); - let group_size = file.group.len(); - let mut attr = fileinfo_attr(status, file, self.colors); - attr.effect ^= Effect::REVERSE; - canvas.print_with_attr(1, 0, &file.format(owner_size, group_size)?, attr)?; + match tab.mode { + Mode::Normal => { + if !status.display_full { + if let Some(file) = tab.path_content.selected_file() { + let owner_size = file.owner.len(); + let group_size = file.group.len(); + let mut attr = fileinfo_attr(status, file, self.colors); + attr.effect ^= Effect::REVERSE; + canvas.print_with_attr( + 1, + 0, + &file.format(owner_size, group_size)?, + attr, + )?; + } + } + } + Mode::InputSimple(InputKind::Filter) => { + canvas.print_with_attr( + 1, + 0, + "by name: n name, by ext: e ext, only directories: d, reset: a", + Self::ATTR_YELLOW_BOLD, + )?; + } + _ => (), } Ok(()) @@ -134,17 +154,17 @@ impl<'a> WinTab<'a> { Mode::Preview => match tab.path_content.selected_file() { Some(fileinfo) => { vec![ - format!("{:?}", tab.mode.clone()), + format!("{}", tab.mode.clone()), format!("{}", fileinfo.path.to_string_lossy()), ] } None => vec!["".to_owned()], }, - Mode::ReadInput(InputKind::Marks(MarkAction::Jump)) => vec!["Jump to...".to_owned()], - Mode::ReadInput(InputKind::Marks(MarkAction::New)) => vec!["Save mark...".to_owned()], + Mode::InputSimple(InputKind::Marks(MarkAction::Jump)) => vec!["Jump to...".to_owned()], + Mode::InputSimple(InputKind::Marks(MarkAction::New)) => vec!["Save mark...".to_owned()], _ => { vec![ - format!("{:?}", tab.mode.clone()), + format!("{}", tab.mode.clone()), format!("{}", tab.input.string()), ] } @@ -191,9 +211,7 @@ impl<'a> WinTab<'a> { } canvas.print_with_attr(row, 0, string, attr)?; } - if !status.display_full { - self.second_line(status, tab, canvas)? - } + self.second_line(status, tab, canvas)?; Ok(()) } @@ -201,17 +219,17 @@ impl<'a> WinTab<'a> { fn cursor(&self, tab: &Tab, canvas: &mut dyn Canvas) -> FmResult<()> { match tab.mode { Mode::Normal - | Mode::ReadInput(InputKind::Marks(_)) + | Mode::InputSimple(InputKind::Marks(_)) | Mode::Preview | Mode::Shortcut | Mode::Jump | Mode::History => { canvas.show_cursor(false)?; } - Mode::ReadInput(InputKind::Sort) => { + Mode::InputSimple(InputKind::Sort) => { canvas.set_cursor(0, Self::SORT_CURSOR_OFFSET)?; } - Mode::ReadInput(_) | Mode::Completed(_) => { + Mode::InputSimple(_) | Mode::InputCompleted(_) => { canvas.show_cursor(true)?; canvas.set_cursor(0, tab.input.cursor_index + Self::EDIT_BOX_OFFSET)?; } |