summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--development.md2
-rw-r--r--src/event_dispatch.rs4
-rw-r--r--src/event_exec.rs33
-rw-r--r--src/mode.rs31
-rw-r--r--src/term_manager.rs75
5 files changed, 66 insertions, 79 deletions
diff --git a/development.md b/development.md
index d4df011..2754ec5 100644
--- a/development.md
+++ b/development.md
@@ -244,8 +244,8 @@
- [x] harmonize code for multiple instances
- [x] macro to impl auto
- [x] struct for flagged. Use a vector instead of hashset... :(
+ - [x] regroup shortcut, history, jump, visited
- [ ] derive
- - [ ] regroup shortcut, history, jump, visited
- [ ] Version 0.2.0 : tests
diff --git a/src/event_dispatch.rs b/src/event_dispatch.rs
index bc773ba..71bfae6 100644
--- a/src/event_dispatch.rs
+++ b/src/event_dispatch.rs
@@ -79,9 +79,7 @@ impl EventDispatcher {
Some(event_char) => event_char.matcher(status),
None => Ok(()),
},
- Mode::Preview | Mode::Shortcut | Mode::Jump | Mode::History => {
- EventExec::event_normal(status.selected())
- }
+ Mode::Preview | Mode::Navigable(_) => EventExec::event_normal(status.selected()),
Mode::NeedConfirmation(confirmed_action) => {
if c == 'y' {
let _ = EventExec::exec_confirmed_action(status, confirmed_action);
diff --git a/src/event_exec.rs b/src/event_exec.rs
index e9bfea2..7c61952 100644
--- a/src/event_exec.rs
+++ b/src/event_exec.rs
@@ -12,6 +12,7 @@ use crate::copy_move::CopyMove;
use crate::fileinfo::{FileKind, PathContent};
use crate::filter::FilterKind;
use crate::fm_error::{FmError, FmResult};
+use crate::mode::Navigate;
use crate::mode::{ConfirmedAction, InputKind, MarkAction, Mode};
use crate::opener::execute_in_child;
use crate::preview::Preview;
@@ -123,7 +124,7 @@ impl EventExec {
if !status.flagged.is_empty() {
status.flagged.index = 0;
info!("entering jump mode");
- status.selected().mode = Mode::Jump
+ status.selected().mode = Mode::Navigable(Navigate::Jump)
}
Ok(())
}
@@ -413,14 +414,14 @@ impl EventExec {
/// Watchout! Since the history is displayed in reverse order,
/// we call the "prev" method of the `History` instance instead.
pub fn event_history_next(tab: &mut Tab) {
- tab.history.prev()
+ tab.history.next()
}
/// Select the previous element in history of visited files.
/// Watchout! Since the history is displayed in reverse order,
/// we call the "next" method of the `History` instance instead.
pub fn event_history_prev(tab: &mut Tab) {
- tab.history.next()
+ tab.history.prev()
}
/// Move to parent directory if there's one.
@@ -662,7 +663,7 @@ impl EventExec {
/// Enter the history mode, allowing to navigate to previously visited
/// directory.
pub fn event_history(tab: &mut Tab) -> FmResult<()> {
- tab.mode = Mode::History;
+ tab.mode = Mode::Navigable(Navigate::History);
Ok(())
}
@@ -670,7 +671,7 @@ impl EventExec {
/// Basic folders (/, /dev... $HOME) and mount points (even impossible to
/// visit ones) are proposed.
pub fn event_shortcut(tab: &mut Tab) -> FmResult<()> {
- tab.mode = Mode::Shortcut;
+ tab.mode = Mode::Navigable(Navigate::Shortcut);
Ok(())
}
@@ -1007,9 +1008,11 @@ impl EventExec {
pub fn event_move_up(status: &mut Status) -> FmResult<()> {
match status.selected().mode {
Mode::Normal | Mode::Preview => EventExec::event_up_one_row(status.selected()),
- Mode::Jump => EventExec::event_jumplist_prev(status),
- Mode::History => EventExec::event_history_prev(status.selected()),
- Mode::Shortcut => EventExec::event_shortcut_prev(status.selected()),
+ Mode::Navigable(Navigate::Jump) => EventExec::event_jumplist_prev(status),
+ Mode::Navigable(Navigate::History) => EventExec::event_history_prev(status.selected()),
+ Mode::Navigable(Navigate::Shortcut) => {
+ EventExec::event_shortcut_prev(status.selected())
+ }
Mode::InputCompleted(_) => {
status.selected().completion.prev();
}
@@ -1023,9 +1026,11 @@ impl EventExec {
pub fn event_move_down(status: &mut Status) -> FmResult<()> {
match status.selected().mode {
Mode::Normal | Mode::Preview => EventExec::event_down_one_row(status.selected()),
- Mode::Jump => EventExec::event_jumplist_next(status),
- Mode::History => EventExec::event_history_next(status.selected()),
- Mode::Shortcut => EventExec::event_shortcut_next(status.selected()),
+ Mode::Navigable(Navigate::Jump) => EventExec::event_jumplist_next(status),
+ Mode::Navigable(Navigate::History) => EventExec::event_history_next(status.selected()),
+ Mode::Navigable(Navigate::Shortcut) => {
+ EventExec::event_shortcut_next(status.selected())
+ }
Mode::InputCompleted(_) => status.selected().completion.next(),
_ => (),
};
@@ -1131,14 +1136,14 @@ impl EventExec {
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::Navigable(Navigate::Jump) => EventExec::exec_jump(status)?,
+ Mode::Navigable(Navigate::History) => EventExec::exec_history(status.selected())?,
+ Mode::Navigable(Navigate::Shortcut) => EventExec::exec_shortcut(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
diff --git a/src/mode.rs b/src/mode.rs
index 1677b7a..3293264 100644
--- a/src/mode.rs
+++ b/src/mode.rs
@@ -48,6 +48,11 @@ impl std::fmt::Display for ConfirmedAction {
}
}
+/// Different modes in which the user is expeted to type something.
+/// It may be a new filename, a mode (aka an octal permission),
+/// the name of a new file, of a new directory,
+/// A regex to match all files in current directory,
+/// a kind of sort, a mark name, a new mark or a filter.
#[derive(Clone)]
pub enum InputKind {
/// Rename the selected file
@@ -68,6 +73,18 @@ pub enum InputKind {
Filter,
}
+/// Different modes in which we display a bunch of possible destinations.
+/// In all those mode we can select a destination and move there.
+#[derive(Clone)]
+pub enum Navigate {
+ /// Navigate to a flagged file
+ Jump,
+ /// Navigate back to a visited path
+ History,
+ /// Navigate to a predefined shortcut
+ Shortcut,
+}
+
/// Different mode in which the application can be.
/// It dictates the reaction to event and what to display.
#[derive(Clone)]
@@ -77,17 +94,13 @@ pub enum Mode {
/// We'll be able to complete the input string with
/// different kind of completed items (exec, goto, search)
InputCompleted(CompletionKind),
- /// Display the help
- Jump,
+ /// Select a target and navigate to it
+ Navigable(Navigate),
/// Confirmation is required before modification is made to existing files :
/// delete, move, copy
NeedConfirmation(ConfirmedAction),
/// Preview a file content
Preview,
- /// Display a sort of stack of visited directories
- History,
- /// Display predefined shortcuts
- Shortcut,
/// Modes requiring an input that can't be completed
InputSimple(InputKind),
}
@@ -108,11 +121,11 @@ impl fmt::Display for Mode {
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::Navigable(Navigate::Jump) => write!(f, "Jump : "),
+ Mode::Navigable(Navigate::History) => write!(f, "History :"),
+ Mode::Navigable(Navigate::Shortcut) => write!(f, "Shortcut :"),
Mode::NeedConfirmation(_) => write!(f, "Y/N :"),
Mode::Preview => write!(f, "Preview : "),
- Mode::Shortcut => write!(f, "Shortcut :"),
}
}
}
diff --git a/src/term_manager.rs b/src/term_manager.rs
index be7cc37..00eac5f 100644
--- a/src/term_manager.rs
+++ b/src/term_manager.rs
@@ -15,7 +15,7 @@ use crate::constant_strings_paths::{
use crate::content_window::ContentWindow;
use crate::fileinfo::fileinfo_attr;
use crate::fm_error::{FmError, FmResult};
-use crate::mode::{ConfirmedAction, InputKind, MarkAction, Mode};
+use crate::mode::{ConfirmedAction, InputKind, MarkAction, Mode, Navigate};
use crate::preview::{Preview, TextKind, Window};
use crate::selectable_content::SelectableContent;
use crate::status::Status;
@@ -61,14 +61,22 @@ struct WinTab<'a> {
impl<'a> Draw for WinTab<'a> {
fn draw(&self, canvas: &mut dyn Canvas) -> DrawResult<()> {
match self.tab.mode {
- Mode::Jump => self.jump_list(self.status, canvas),
- Mode::History => self.history(self.tab, canvas),
+ Mode::Navigable(Navigate::Jump) => self.navigate(
+ canvas,
+ &self.status.flagged.content,
+ self.status.flagged.index,
+ ),
+ Mode::Navigable(Navigate::History) => {
+ self.navigate(canvas, &self.tab.history.content, self.tab.history.index)
+ }
+ Mode::Navigable(Navigate::Shortcut) => {
+ self.navigate(canvas, &self.tab.shortcut.content, self.tab.shortcut.index)
+ }
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::InputSimple(InputKind::Marks(_)) => self.marks(self.status, self.tab, canvas),
_ => self.files(self.status, self.tab, canvas),
}?;
@@ -242,10 +250,8 @@ impl<'a> WinTab<'a> {
match tab.mode {
Mode::Normal
| Mode::InputSimple(InputKind::Marks(_))
- | Mode::Preview
- | Mode::Shortcut
- | Mode::Jump
- | Mode::History => {
+ | Mode::Navigable(_)
+ | Mode::Preview => {
canvas.show_cursor(false)?;
}
Mode::InputSimple(InputKind::Sort) => {
@@ -262,52 +268,17 @@ impl<'a> WinTab<'a> {
Ok(())
}
- /// Display the possible jump destination from flagged files.
- fn jump_list(&self, tabs: &Status, canvas: &mut dyn Canvas) -> FmResult<()> {
- canvas.print(0, 0, "Jump to...")?;
- for (row, path) in tabs.flagged.content.iter().enumerate() {
- let mut attr = Attr::default();
- if row == tabs.flagged.index {
- attr.effect |= Effect::REVERSE;
- }
- let _ = canvas.print_with_attr(
- row + ContentWindow::WINDOW_MARGIN_TOP,
- 4,
- path.to_str()
- .ok_or_else(|| FmError::custom("display", "Unreadable filename"))?,
- attr,
- );
- }
- Ok(())
- }
-
- /// Display the history of visited directories.
- fn history(&self, tab: &Tab, canvas: &mut dyn Canvas) -> FmResult<()> {
- canvas.print(0, 0, "Go to...")?;
- for (row, path) in tab.history.content.iter().rev().enumerate() {
- let mut attr = Attr::default();
- if tab.history.len() > tab.history.index
- && row == tab.history.len() - tab.history.index - 1
- {
- attr.effect |= Effect::REVERSE;
- }
- canvas.print_with_attr(
- row + ContentWindow::WINDOW_MARGIN_TOP,
- 4,
- path.to_str()
- .ok_or_else(|| FmError::custom("display", "Unreadable filename"))?,
- attr,
- )?;
- }
- Ok(())
- }
-
- /// Display the predefined shortcuts.
- fn shortcuts(&self, tab: &Tab, canvas: &mut dyn Canvas) -> FmResult<()> {
+ /// Display the possible destinations from a content.
+ fn navigate(
+ &self,
+ canvas: &mut dyn Canvas,
+ content: &Vec<std::path::PathBuf>,
+ index: usize,
+ ) -> FmResult<()> {
canvas.print(0, 0, "Go to...")?;
- for (row, path) in tab.shortcut.content.iter().enumerate() {
+ for (row, path) in content.iter().enumerate() {
let mut attr = Attr::default();
- if row == tab.shortcut.index {
+ if row == index {
attr.effect |= Effect::REVERSE;
}
let _ = canvas.print_with_attr(