summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqkzk <qkzk@users.noreply.github.com>2023-02-06 09:18:52 +0100
committerGitHub <noreply@github.com>2023-02-06 09:18:52 +0100
commit494cd8494fbdf6d89043933ec5cbfd78b5c848b4 (patch)
tree6c250e42e001ed6516069195c30b1ee385ab4ecf
parent3365c8d5a7a2906001a2baf2d97db6919c1d6901 (diff)
parented87ec24fc2c0a3f732edf425d43614ac5fb4609 (diff)
Merge pull request #70 from qkzk/refactored-colorsv0.1.16
Refactored colors
-rw-r--r--development.md8
-rw-r--r--src/action_map.rs37
-rw-r--r--src/args.rs2
-rw-r--r--src/color_cache.rs2
-rw-r--r--src/completion.rs51
-rw-r--r--src/config.rs1
-rw-r--r--src/event_dispatch.rs39
-rw-r--r--src/event_exec.rs175
-rw-r--r--src/fileinfo.rs71
-rw-r--r--src/filter.rs20
-rw-r--r--src/main.rs14
-rw-r--r--src/preview.rs36
-rw-r--r--src/status.rs29
-rw-r--r--src/tab.rs52
-rw-r--r--src/term_manager.rs71
-rw-r--r--src/tree.rs98
16 files changed, 398 insertions, 308 deletions
diff --git a/development.md b/development.md
index 2b49cf3..f1ce896 100644
--- a/development.md
+++ b/development.md
@@ -369,8 +369,12 @@ New view: Tree ! Toggle with 't', fold with 'z'. Navigate normally.
- [x] FIX: can't parse uid gid if they only exists on a remote machine. See https://serverfault.com/questions/514118/mapping-uid-and-gid-of-local-user-to-the-mounted-nfs-share
for a fix.
- [x] FIX: truncate file size in preview mode.
- - [ ] BUG: when searching from tree mode, it only completes with level 1 elements, not nested ones.
- - [ ] BUG: when filtering in free mode, only the level 1 matching elements are displayed
+ - [x] FIX: in tree mode search is backward
+ - [x] FIX: when searching from tree mode, it only completes with level 1 elements, not nested ones.
+ - [x] FIX: when exiting search in tree mode, second line isn't updated
+ - [x] FIX: when filtering in tree mode, only the level 1 matching elements are displayed
+ Decided to keep directories when filtering in tree mode. Those are excluded when filtering in normal mode.
+ - [x] Tree: move 10 rows at a time
- [ ] Version 0.1.50 : safety & memory usage
diff --git a/src/action_map.rs b/src/action_map.rs
index f3b6f6b..f84d60b 100644
--- a/src/action_map.rs
+++ b/src/action_map.rs
@@ -1,5 +1,6 @@
use strum_macros::{Display, EnumString};
+use crate::config::Colors;
use crate::event_exec::EventExec;
use crate::fm_error::FmResult;
use crate::status::Status;
@@ -82,10 +83,10 @@ pub enum ActionMap {
impl ActionMap {
/// Makes the junction between `Actions` and `Events`.
/// Every Action links to a different `EventExec` method.
- pub fn matcher(&self, status: &mut Status) -> FmResult<()> {
+ pub fn matcher(&self, status: &mut Status, colors: &Colors) -> FmResult<()> {
let current_tab = status.selected();
match *self {
- ActionMap::Back => EventExec::event_back(status),
+ ActionMap::Back => EventExec::event_back(status, colors),
ActionMap::BackTab => EventExec::backtab(status),
ActionMap::Backspace => EventExec::event_backspace(status),
ActionMap::Bulkrename => EventExec::event_bulkrename(status),
@@ -100,8 +101,8 @@ impl ActionMap {
ActionMap::DisplayFull => EventExec::event_toggle_display_full(status),
ActionMap::DragNDrop => EventExec::event_drag_n_drop(status),
ActionMap::EncryptedDrive => EventExec::event_encrypted_drive(status),
- ActionMap::End => EventExec::event_end(status),
- ActionMap::Enter => EventExec::event_enter(status),
+ ActionMap::End => EventExec::event_end(status, colors),
+ ActionMap::Enter => EventExec::event_enter(status, colors),
ActionMap::Exec => EventExec::event_exec(current_tab),
ActionMap::Filter => EventExec::event_filter(current_tab),
ActionMap::FlagAll => EventExec::event_flag_all(status),
@@ -111,23 +112,23 @@ impl ActionMap {
ActionMap::History => EventExec::event_history(current_tab),
ActionMap::Home => EventExec::event_home(current_tab),
ActionMap::Jump => EventExec::event_jump(status),
- ActionMap::KeyHome => EventExec::event_key_home(status),
+ ActionMap::KeyHome => EventExec::event_key_home(status, colors),
ActionMap::MarksJump => EventExec::event_marks_jump(status),
ActionMap::MarksNew => EventExec::event_marks_new(current_tab),
ActionMap::ModeNormal => EventExec::event_reset_mode(current_tab),
- ActionMap::MoveDown => EventExec::event_move_down(status),
- ActionMap::MoveLeft => EventExec::event_move_left(status),
- ActionMap::MoveRight => EventExec::event_move_right(status),
- ActionMap::MoveUp => EventExec::event_move_up(status),
+ ActionMap::MoveDown => EventExec::event_move_down(status, colors),
+ ActionMap::MoveLeft => EventExec::event_move_left(status, colors),
+ ActionMap::MoveRight => EventExec::event_move_right(status, colors),
+ ActionMap::MoveUp => EventExec::event_move_up(status, colors),
ActionMap::NewDir => EventExec::event_new_dir(current_tab),
ActionMap::NewFile => EventExec::event_new_file(current_tab),
ActionMap::NvimFilepicker => EventExec::event_nvim_filepicker(current_tab),
ActionMap::OpenFile => EventExec::event_open_file(status),
- ActionMap::PageDown => EventExec::event_page_down(status),
- ActionMap::PageUp => EventExec::event_page_up(status),
- ActionMap::Preview => EventExec::event_preview(status),
+ ActionMap::PageDown => EventExec::event_page_down(status, colors),
+ ActionMap::PageUp => EventExec::event_page_up(status, colors),
+ ActionMap::Preview => EventExec::event_preview(status, colors),
ActionMap::Quit => EventExec::event_quit(current_tab),
- ActionMap::RefreshView => EventExec::event_refreshview(status),
+ ActionMap::RefreshView => EventExec::event_refreshview(status, colors),
ActionMap::RegexMatch => EventExec::event_regex_match(current_tab),
ActionMap::Rename => EventExec::event_rename(current_tab),
ActionMap::ReverseFlags => EventExec::event_reverse_flags(status),
@@ -141,15 +142,15 @@ impl ActionMap {
ActionMap::Thumbnail => EventExec::event_thumbnail(current_tab),
ActionMap::ToggleDualPane => EventExec::event_toggle_dualpane(status),
ActionMap::ToggleFlag => EventExec::event_toggle_flag(status),
- ActionMap::ToggleHidden => EventExec::event_toggle_hidden(status),
+ ActionMap::ToggleHidden => EventExec::event_toggle_hidden(status, colors),
ActionMap::TrashMoveFile => EventExec::event_trash_move_file(status),
ActionMap::TrashRestoreFile => EventExec::event_trash_restore_file(status),
ActionMap::TrashEmpty => EventExec::exec_trash_empty(status),
ActionMap::TrashOpen => EventExec::event_trash_open(status),
- ActionMap::Tree => EventExec::event_tree(status),
- ActionMap::TreeFold => EventExec::event_tree_fold(status),
- ActionMap::TreeFoldAll => EventExec::event_tree_fold_all(status),
- ActionMap::TreeUnFoldAll => EventExec::event_tree_unfold_all(status),
+ ActionMap::Tree => EventExec::event_tree(status, colors),
+ ActionMap::TreeFold => EventExec::event_tree_fold(current_tab, colors),
+ ActionMap::TreeFoldAll => EventExec::event_tree_fold_all(status, colors),
+ ActionMap::TreeUnFoldAll => EventExec::event_tree_unfold_all(status, colors),
ActionMap::OpenConfig => EventExec::event_open_config(status),
ActionMap::Nothing => Ok(()),
diff --git a/src/args.rs b/src/args.rs
index b25fffc..4034d44 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -1,6 +1,6 @@
use clap::Parser;
-#[derive(Parser, Debug)]
+#[derive(Parser, Debug, Clone)]
#[clap(author, version, about)]
/// FM : dired like file manager{n}
pub struct Args {
diff --git a/src/color_cache.rs b/src/color_cache.rs
index 9b09439..3052ff3 100644
--- a/src/color_cache.rs
+++ b/src/color_cache.rs
@@ -38,7 +38,7 @@ fn color(coords: usize) -> Color {
.unwrap()
}
-fn extension_color(extension: &str) -> Color {
+pub fn extension_color(extension: &str) -> Color {
let mut hasher = std::collections::hash_map::DefaultHasher::new();
hasher.write(extension.as_bytes());
color(hasher.finish() as usize)
diff --git a/src/completion.rs b/src/completion.rs
index 5097993..6894bb8 100644
--- a/src/completion.rs
+++ b/src/completion.rs
@@ -3,6 +3,7 @@ use std::fs::{self, ReadDir};
use crate::fileinfo::PathContent;
use crate::fm_error::FmResult;
use crate::mode::Mode;
+use crate::tree::ColoredString;
/// Different kind of completions
#[derive(Clone, Default, Copy)]
@@ -22,7 +23,7 @@ pub enum InputCompleted {
/// showing where the user is in the vec.
#[derive(Clone, Default)]
pub struct Completion {
- pub kind: InputCompleted,
+ kind: InputCompleted,
/// Possible completions
pub proposals: Vec<String>,
/// Which completion is selected by the user
@@ -93,27 +94,9 @@ impl Completion {
self.proposals.clear();
}
- /// Fill the completions items from some parameters, depending on the mode.
- /// In Exec mode, we search for executable in $PATH starting with what the user typed.
- /// In Goto mode, we search for valid absolute & relative paths starting with what the user typed.
- /// In Search mode, we search for filenames in current directory starting with what the user typed.
- pub fn complete(
- &mut self,
- input_string: &str,
- path_content: &PathContent,
- current_path: &str,
- ) -> FmResult<()> {
- match self.kind {
- InputCompleted::Exec => self.exec(input_string),
- InputCompleted::Goto => self.goto(input_string, current_path),
- InputCompleted::Search => self.search(input_string, path_content),
- InputCompleted::Nothing => Ok(()),
- }
- }
-
/// Goto completion.
/// Looks for the valid path completing what the user typed.
- fn goto(&mut self, input_string: &str, current_path: &str) -> FmResult<()> {
+ pub fn goto(&mut self, input_string: &str, current_path: &str) -> FmResult<()> {
self.update_from_input(input_string, current_path);
let (parent, last_name) = split_input_string(input_string);
if last_name.is_empty() {
@@ -164,7 +147,7 @@ impl Completion {
}
/// Looks for programs in $PATH completing the one typed by the user.
- fn exec(&mut self, input_string: &str) -> FmResult<()> {
+ pub fn exec(&mut self, input_string: &str) -> FmResult<()> {
let mut proposals: Vec<String> = vec![];
if let Some(paths) = std::env::var_os("PATH") {
for path in std::env::split_paths(&paths).filter(|path| path.exists()) {
@@ -187,7 +170,11 @@ impl Completion {
}
/// Looks for file within current folder completing what the user typed.
- fn search(&mut self, input_string: &str, path_content: &PathContent) -> FmResult<()> {
+ pub fn search_from_normal(
+ &mut self,
+ input_string: &str,
+ path_content: &PathContent,
+ ) -> FmResult<()> {
self.update(
path_content
.content
@@ -198,6 +185,26 @@ impl Completion {
);
Ok(())
}
+
+ /// Looks for file within tree completing what the user typed.
+ pub fn search_from_tree(
+ &mut self,
+ input_string: &str,
+ content: &[(String, ColoredString)],
+ ) -> FmResult<()> {
+ self.update(
+ content
+ .iter()
+ .filter(|(_, s)| s.text.contains(input_string))
+ .map(|(_, s)| {
+ let text = s.text.replace("▸ ", "");
+ text.replace("▾ ", "")
+ })
+ .collect(),
+ );
+
+ Ok(())
+ }
}
/// true if the filename starts with a pattern
diff --git a/src/config.rs b/src/config.rs
index 74e9167..d0923fb 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -4,6 +4,7 @@ use serde_yaml;
use tuikit::attr::Color;
use crate::color_cache::ColorCache;
+// use crate::color_cache::extension_color;
use crate::constant_strings_paths::DEFAULT_TERMINAL_APPLICATION;
use crate::fm_error::FmResult;
use crate::keybindings::Bindings;
diff --git a/src/event_dispatch.rs b/src/event_dispatch.rs
index 722cb8f..4ff6ac7 100644
--- a/src/event_dispatch.rs
+++ b/src/event_dispatch.rs
@@ -1,5 +1,6 @@
use tuikit::prelude::{Event, Key, MouseButton};
+use crate::config::Colors;
use crate::event_exec::EventExec;
use crate::fm_error::FmResult;
use crate::keybindings::Bindings;
@@ -25,51 +26,53 @@ impl EventDispatcher {
/// Only non keyboard events are dealt here directly.
/// Keyboard events are configurable and are sent to specific functions
/// which needs to know those keybindings.
- pub fn dispatch(&self, status: &mut Status, ev: Event) -> FmResult<()> {
+ pub fn dispatch(&self, status: &mut Status, ev: Event, colors: &Colors) -> FmResult<()> {
match ev {
Event::Key(Key::WheelUp(_, col, _)) => {
EventExec::event_select_pane(status, col)?;
- EventExec::event_move_up(status)
+ EventExec::event_move_up(status, colors)
}
Event::Key(Key::WheelDown(_, col, _)) => {
EventExec::event_select_pane(status, col)?;
- EventExec::event_move_down(status)
+ EventExec::event_move_down(status, colors)
}
Event::Key(Key::SingleClick(MouseButton::Left, row, col)) => {
EventExec::event_select_pane(status, col)?;
- EventExec::event_select_row(status, row)
+ EventExec::event_select_row(status, row, colors)
}
Event::Key(Key::SingleClick(MouseButton::Right, row, col))
| Event::Key(Key::DoubleClick(MouseButton::Left, row, col)) => {
EventExec::event_select_pane(status, col)?;
- EventExec::event_select_row(status, row)?;
- EventExec::event_right_click(status)
+ EventExec::event_select_row(status, row, colors)?;
+ EventExec::event_right_click(status, colors)
}
- Event::User(_) => EventExec::refresh_status(status),
- Event::Resize { width, height } => EventExec::resize(status, width, height),
- Event::Key(Key::Char(c)) => self.char(status, Key::Char(c)),
- Event::Key(key) => self.key_matcher(status, key),
+ Event::User(_) => EventExec::refresh_status(status, colors),
+ Event::Resize { width, height } => EventExec::resize(status, width, height, colors),
+ Event::Key(Key::Char(c)) => self.char(status, Key::Char(c), colors),
+ Event::Key(key) => self.key_matcher(status, key, colors),
_ => Ok(()),
}
}
- fn key_matcher(&self, status: &mut Status, key: Key) -> FmResult<()> {
+ fn key_matcher(&self, status: &mut Status, key: Key, colors: &Colors) -> FmResult<()> {
match self.binds.get(&key) {
- Some(action) => action.matcher(status),
+ Some(action) => action.matcher(status, colors),
None => Ok(()),
}
}
- fn char(&self, status: &mut Status, key_char: Key) -> FmResult<()> {
+ fn char(&self, status: &mut Status, key_char: Key, colors: &Colors) -> FmResult<()> {
match key_char {
Key::Char(c) => match status.selected_non_mut().mode {
Mode::InputSimple(InputSimple::Marks(MarkAction::Jump)) => {
- EventExec::exec_marks_jump(status, c)
+ EventExec::exec_marks_jump(status, c, colors)
}
Mode::InputSimple(InputSimple::Marks(MarkAction::New)) => {
- EventExec::exec_marks_new(status, c)
+ EventExec::exec_marks_new(status, c, colors)
+ }
+ Mode::InputSimple(InputSimple::Sort) => {
+ EventExec::event_leave_sort(status, c, colors)
}
- Mode::InputSimple(InputSimple::Sort) => EventExec::event_leave_sort(status, c),
Mode::InputSimple(InputSimple::RegexMatch) => {
EventExec::event_text_insertion(status.selected(), c);
status.select_from_regex()?;
@@ -83,12 +86,12 @@ impl EventDispatcher {
EventExec::event_text_insert_and_complete(status.selected(), c)
}
Mode::Normal | Mode::Tree => match self.binds.get(&key_char) {
- Some(event_char) => event_char.matcher(status),
+ Some(event_char) => event_char.matcher(status, colors),
None => Ok(()),
},
Mode::NeedConfirmation(confirmed_action) => {
if c == 'y' {
- let _ = EventExec::exec_confirmed_action(status, confirmed_action);
+ let _ = EventExec::exec_confirmed_action(status, confirmed_action, colors);
}
EventExec::event_leave_need_confirmation(status.selected());
Ok(())
diff --git a/src/event_exec.rs b/src/event_exec.rs
index 0da4bc3..bfa13c7 100644
--- a/src/event_exec.rs
+++ b/src/event_exec.rs
@@ -9,6 +9,7 @@ use sysinfo::SystemExt;
use crate::bulkrename::Bulkrename;
use crate::completion::InputCompleted;
+use crate::config::Colors;
use crate::constant_strings_paths::CONFIG_PATH;
use crate::constant_strings_paths::DEFAULT_DRAGNDROP;
use crate::constant_strings_paths::NVIM_RPC_SENDER;
@@ -35,11 +36,10 @@ pub struct EventExec {}
impl EventExec {
/// Reset the selected tab view to the default.
- pub fn refresh_status(status: &mut Status) -> FmResult<()> {
+ pub fn refresh_status(status: &mut Status, colors: &Colors) -> FmResult<()> {
status.refresh_users()?;
status.selected().refresh_view()?;
if let Mode::Tree = status.selected_non_mut().mode {
- let colors = &status.config_colors.clone();
status.selected().make_tree(colors)?
}
Ok(())
@@ -49,7 +49,12 @@ impl EventExec {
/// isn't sufficiant to display enough information.
/// We also need to know the new height of the terminal to start scrolling
/// up or down.
- pub fn resize(status: &mut Status, width: usize, height: usize) -> FmResult<()> {
+ pub fn resize(
+ status: &mut Status,
+ width: usize,
+ height: usize,
+ colors: &Colors,
+ ) -> FmResult<()> {
if width < MIN_WIDTH_FOR_DUAL_PANE {
status.select_tab(0)?;
status.set_dual_pane(false);
@@ -57,7 +62,7 @@ impl EventExec {
status.set_dual_pane(true);
}
status.selected().set_height(height);
- Self::refresh_status(status)?;
+ Self::refresh_status(status, colors)?;
Ok(())
}
@@ -164,24 +169,24 @@ impl EventExec {
}
/// Execute a new mark, saving it to a config file for futher use.
- pub fn exec_marks_new(status: &mut Status, c: char) -> FmResult<()> {
+ pub fn exec_marks_new(status: &mut Status, c: char, colors: &Colors) -> FmResult<()> {
let path = status.selected().path_content.path.clone();
status.marks.new_mark(c, path)?;
Self::event_normal(status.selected())?;
status.selected().reset_mode();
- Self::refresh_status(status)
+ Self::refresh_status(status, colors)
}
/// Execute a jump to a mark, moving to a valid path.
/// If the saved path is invalid, it does nothing but reset the view.
- pub fn exec_marks_jump(status: &mut Status, c: char) -> FmResult<()> {
+ pub fn exec_marks_jump(status: &mut Status, c: char, colors: &Colors) -> FmResult<()> {
if let Some(path) = status.marks.get(c) {
let path = path.clone();
status.selected().set_pathcontent(&path)?
}
Self::event_normal(status.selected())?;
status.selected().reset_mode();
- Self::refresh_status(status)
+ Self::refresh_status(status, colors)
}
/// Creates a symlink of every flagged file to the current directory.
@@ -221,7 +226,7 @@ impl EventExec {
}
/// Recursively delete all flagged files.
- pub fn exec_delete_files(status: &mut Status) -> FmResult<()> {
+ pub fn exec_delete_files(status: &mut Status, colors: &Colors) -> FmResult<()> {
for pathbuf in status.flagged.content.iter() {
if pathbuf.is_dir() {
std::fs::remove_dir_all(pathbuf)?;
@@ -231,7 +236,7 @@ impl EventExec {
}
status.selected().reset_mode();
status.clear_flags_and_reset_view()?;
- Self::refresh_status(status)
+ Self::refresh_status(status, colors)
}
/// Change permission of the flagged files.
@@ -282,8 +287,9 @@ impl EventExec {
pub fn exec_confirmed_action(
status: &mut Status,
confirmed_action: NeedConfirmation,
+ colors: &Colors,
) -> FmResult<()> {
- Self::_exec_confirmed_action(status, confirmed_action)?;
+ Self::_exec_confirmed_action(status, confirmed_action, colors)?;
status.selected().set_mode(Mode::Normal);
Ok(())
}
@@ -291,9 +297,10 @@ impl EventExec {
fn _exec_confirmed_action(
status: &mut Status,
confirmed_action: NeedConfirmation,
+ colors: &Colors,
) -> FmResult<()> {
match confirmed_action {
- NeedConfirmation::Delete => Self::exec_delete_files(status),
+ NeedConfirmation::Delete => Self::exec_delete_files(status, colors),
NeedConfirmation::Move => Self::exec_cut_paste(status),
NeedConfirmation::Copy => Self::exec_copy_paste(status),
NeedConfirmation::EmptyTrash => Self::exec_trash_empty(status),
@@ -442,8 +449,7 @@ impl EventExec {
}
/// Select a given row, if there's something in it.
- pub fn event_select_row(status: &mut Status, row: u16) -> FmResult<()> {
- let colors = &status.config_colors.clone();
+ pub fn event_select_row(status: &mut Status, row: u16, colors: &Colors) -> FmResult<()> {
let tab = status.selected();
match tab.mode {
Mode::Normal => {
@@ -585,7 +591,7 @@ impl EventExec {
/// Every file can be previewed. See the `crate::enum::Preview` for
/// more details on previewinga file.
/// Does nothing if the directory is empty.
- pub fn event_preview(status: &mut Status) -> FmResult<()> {
+ pub fn event_preview(status: &mut Status, colors: &Colors) -> FmResult<()> {
if status.selected_non_mut().path_content.is_empty() {
return Ok(());
}
@@ -593,13 +599,17 @@ impl EventExec {
let Some(file_info) = unmutable_tab.selected() else { return Ok(()) };
match file_info.file_kind {
FileKind::NormalFile => {
- let preview =
- Preview::new(file_info, &unmutable_tab.path_content.users_cache, status)?;
+ let preview = Preview::new(
+ file_info,
+ &unmutable_tab.path_content.users_cache,
+ status,
+ colors,
+ )?;
status.selected().set_mode(Mode::Preview);
status.selected().window.reset(preview.len());
status.selected().preview = preview;
}
- FileKind::Directory => Self::event_tree(status)?,
+ FileKind::Directory => Self::event_tree(status, colors)?,
_ => (),
}
@@ -681,11 +691,10 @@ impl EventExec {
/// by extension.
/// The first letter is used to identify the method.
/// If the user types an uppercase char, the sort is reverse.
- pub fn event_leave_sort(status: &mut Status, c: char) -> FmResult<()> {
+ pub fn event_leave_sort(status: &mut Status, c: char, colors: &Colors) -> FmResult<()> {
if status.selected_non_mut().path_content.content.is_empty() {
return Ok(());
}
- let colors = &status.config_colors.clone();
let tab = status.selected();
tab.reset_mode();
match tab.mode {
@@ -713,8 +722,7 @@ impl EventExec {
}
/// Toggle the display of hidden files.
- pub fn event_toggle_hidden(status: &mut Status) -> FmResult<()> {
- let colors = &status.config_colors.clone();
+ pub fn event_toggle_hidden(status: &mut Status, colors: &Colors) -> FmResult<()> {
let tab = status.selected();
tab.show_hidden = !tab.show_hidden;
tab.path_content.reset_files(&tab.filter, tab.show_hidden)?;
@@ -791,10 +799,10 @@ impl EventExec {
}
/// A right click opens a file or a directory.
- pub fn event_right_click(status: &mut Status) -> FmResult<()> {
+ pub fn event_right_click(status: &mut Status, colors: &Colors) -> FmResult<()> {
match status.selected().mode {
Mode::Normal => Self::exec_file(status),
- Mode::Tree => Self::exec_tree(status),
+ Mode::Tree => Self::exec_tree(status, colors),
_ => Ok(()),
}
}
@@ -864,11 +872,10 @@ impl EventExec {
}
/// Move back in history to the last visited directory.
- pub fn event_back(status: &mut Status) -> FmResult<()> {
+ pub fn event_back(status: &mut Status, colors: &Colors) -> FmResult<()> {
if status.selected_non_mut().history.content.len() <= 1 {
return Ok(());
}
- let colors = &status.config_colors.clone();
let tab = status.selected();
tab.history.content.pop();
let last_index = tab.history.len() - 1;
@@ -1012,8 +1019,7 @@ impl EventExec {
/// ie. If you typed `"jpg"` before, it will move to the first file
/// whose filename contains `"jpg"`.
/// The current order of files is used.
- pub fn exec_search(status: &mut Status) -> FmResult<()> {
- let colors = &status.config_colors.clone();
+ pub fn exec_search(status: &mut Status, colors: &Colors) -> FmResult<()> {
let tab = status.selected();
let searched = tab.input.string();
tab.input.reset();
@@ -1027,7 +1033,8 @@ impl EventExec {
tab.directory.tree.unselect_children();
if let Some(position) = tab.directory.tree.select_first_match(&searched) {
tab.directory.tree.position = position;
- tab.directory.tree.select_from_position()?;
+ (_, _, tab.directory.tree.current_node) =
+ tab.directory.tree.select_from_position()?;
} else {
tab.directory.tree.select_root()
};
@@ -1101,8 +1108,7 @@ impl EventExec {
/// Apply a filter to the displayed files.
/// See `crate::filter` for more details.
- pub fn exec_filter(status: &mut Status) -> FmResult<()> {
- let colors = &status.config_colors.clone();
+ pub fn exec_filter(status: &mut Status, colors: &Colors) -> FmResult<()> {
let tab = status.selected();
let filter = FilterKind::from_input(&tab.input.string());
tab.set_filter(filter);
@@ -1117,7 +1123,7 @@ impl EventExec {
/// Move up one row in modes allowing movement.
/// Does nothing if the selected item is already the first in list.
- pub fn event_move_up(status: &mut Status) -> FmResult<()> {
+ pub fn event_move_up(status: &mut Status, colors: &Colors) -> FmResult<()> {
match status.selected().mode {
Mode::Normal | Mode::Preview => EventExec::event_up_one_row(status.selected()),
Mode::Navigate(Navigate::Jump) => EventExec::event_jumplist_prev(status),
@@ -1127,7 +1133,7 @@ impl EventExec {
Mode::Navigate(Navigate::EncryptedDrive) => {
EventExec::event_encrypted_drive_prev(status)
}
- Mode::Tree => EventExec::event_select_prev(status)?,
+ Mode::Tree => EventExec::event_select_prev(status.selected(), colors)?,
Mode::InputCompleted(_) => {
status.selected().completion.prev();
}
@@ -1138,7 +1144,7 @@ impl EventExec {
/// Move down one row in modes allowing movements.
/// Does nothing if the user is already at the bottom.
- pub fn event_move_down(status: &mut Status) -> FmResult<()> {
+ pub fn event_move_down(status: &mut Status, colors: &Colors) -> FmResult<()> {
match status.selected().mode {
Mode::Normal | Mode::Preview => EventExec::event_down_one_row(status.selected()),
Mode::Navigate(Navigate::Jump) => EventExec::event_jumplist_next(status),
@@ -1149,7 +1155,7 @@ impl EventExec {
EventExec::event_encrypted_drive_next(status)
}
Mode::InputCompleted(_) => status.selected().completion.next(),
- Mode::Tree => EventExec::event_select_next(status)?,
+ Mode::Tree => EventExec::event_select_next(status.selected(), colors)?,
_ => (),
};
Ok(())
@@ -1157,10 +1163,10 @@ impl EventExec {
/// Move to parent in normal mode,
/// move left one char in mode requiring text input.
- pub fn event_move_left(status: &mut Status) -> FmResult<()> {
+ pub fn event_move_left(status: &mut Status, colors: &Colors) -> FmResult<()> {
match status.selected().mode {
Mode::Normal => EventExec::event_move_to_parent(status.selected()),
- Mode::Tree => EventExec::event_select_parent(status),
+ Mode::Tree => EventExec::event_select_parent(status, colors),
Mode::InputSimple(_) | Mode::InputCompleted(_) => {
EventExec::event_move_cursor_left(status.selected());
Ok(())
@@ -1172,10 +1178,10 @@ impl EventExec {
/// Move to child if any or open a regular file in normal mode.
/// Move the cursor one char to right in mode requiring text input.
- pub fn event_move_right(status: &mut Status) -> FmResult<()> {
+ pub fn event_move_right(status: &mut Status, colors: &Colors) -> FmResult<()> {
match status.selected().mode {
Mode::Normal => EventExec::exec_file(status),
- Mode::Tree => EventExec::event_select_first_child(status),
+ Mode::Tree => EventExec::event_select_first_child(status, colors),
Mode::InputSimple(_) | Mode::InputCompleted(_) => {
EventExec::event_move_cursor_right(status.selected());
Ok(())
@@ -1208,38 +1214,40 @@ impl EventExec {
}
/// Move to leftmost char in mode allowing edition.
- pub fn event_key_home(status: &mut Status) -> FmResult<()> {
+ pub fn event_key_home(status: &mut Status, colors: &Colors) -> FmResult<()> {
match status.selected().mode {
Mode::Normal | Mode::Preview => EventExec::event_go_top(status.selected()),
- Mode::Tree => EventExec::event_tree_go_to_root(status)?,
+ Mode::Tree => EventExec::event_tree_go_to_root(status, colors)?,
_ => EventExec::event_cursor_home(status.selected()),
};
Ok(())
}
/// Move to the bottom in any mode.