summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2023-01-30 15:47:07 +0100
committerqkzk <qu3nt1n@gmail.com>2023-01-30 15:47:07 +0100
commit16016112acbc7861af1cc2d050f47e46f19749e0 (patch)
treec7e17a70deb9613c44e1bf0d2b3cc8f53ac69246
parent3365c8d5a7a2906001a2baf2d97db6919c1d6901 (diff)
moved colors to a variable in main instead of an attr of status
-rw-r--r--src/action_map.rs33
-rw-r--r--src/color_cache.rs2
-rw-r--r--src/config.rs1
-rw-r--r--src/event_dispatch.rs39
-rw-r--r--src/event_exec.rs150
-rw-r--r--src/main.rs13
-rw-r--r--src/preview.rs3
-rw-r--r--src/status.rs7
-rw-r--r--src/term_manager.rs40
9 files changed, 147 insertions, 141 deletions
diff --git a/src/action_map.rs b/src/action_map.rs
index f3b6f6b9..216c8b78 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::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(status, 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/color_cache.rs b/src/color_cache.rs
index 9b094392..3052ff33 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/config.rs b/src/config.rs
index 74e91676..d0923fb7 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 722cb8f2..4ff6ac75 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 0da4bc39..1b39020f 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();
@@ -1101,8 +1107,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 +1122,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 +1132,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, colors)?,
Mode::InputCompleted(_) => {
status.selected().completion.prev();
}
@@ -1138,7 +1143,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 +1154,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, colors)?,
_ => (),
};
Ok(())
@@ -1157,10 +1162,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 +1177,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,20 +1213,20 @@ 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.
- pub fn event_end(status: &mut Status) -> FmResult<()> {
+ pub fn event_end(status: &mut Status, colors: &Colors) -> FmResult<()> {
match status.selected().mode {
Mode::Normal | Mode::Preview => EventExec::event_go_bottom(status.selected()),
- Mode::Tree => EventExec::event_tree_go_to_bottom_leaf(status)?,
+ Mode::Tree => EventExec::event_tree_go_to_bottom_leaf(status, colors)?,
_ => EventExec::event_cursor_end(status.selected()),
};
Ok(())
@@ -1250,7 +1255,7 @@ impl EventExec {
/// related action.
/// In normal mode, it will open the file.
/// Reset to normal mode afterwards.
- pub fn event_enter(status: &mut Status) -> FmResult<()> {
+ pub fn event_enter(status: &mut Status, colors: &Colors) -> FmResult<()> {
let mut must_refresh = true;
let mut must_reset_mode = true;
match status.selected_non_mut().mode {
@@ -1261,7 +1266,7 @@ impl EventExec {
Mode::InputSimple(InputSimple::RegexMatch) => EventExec::exec_regex(status)?,
Mode::InputSimple(InputSimple::Filter) => {
must_refresh = false;
- EventExec::exec_filter(status)?
+ EventExec::exec_filter(status, colors)?
}
Mode::InputSimple(InputSimple::Password(password_kind, encrypted_action)) => {
must_refresh = false;
@@ -1280,11 +1285,11 @@ impl EventExec {
Mode::InputCompleted(InputCompleted::Exec) => EventExec::exec_exec(status.selected())?,
Mode::InputCompleted(InputCompleted::Search) => {
must_refresh = false;
- EventExec::exec_search(status)?
+ EventExec::exec_search(status, colors)?
}
Mode::InputCompleted(InputCompleted::Goto) => EventExec::exec_goto(status.selected())?,
Mode::Normal => EventExec::exec_file(status)?,
- Mode::Tree => EventExec::exec_tree(status)?,
+ Mode::Tree => EventExec::exec_tree(status, colors)?,
Mode::NeedConfirmation(_)
| Mode::Preview
| Mode::InputCompleted(InputCompleted::Nothing)
@@ -1297,7 +1302,7 @@ impl EventExec {
status.selected().reset_mode();
}
if must_refresh {
- Self::refresh_status(status)?;
+ Self::refresh_status(status, colors)?;
}
Ok(())
}
@@ -1347,9 +1352,9 @@ impl EventExec {
}
/// Refresh the current view, reloading the files. Move the selection to top.
- pub fn event_refreshview(status: &mut Status) -> FmResult<()> {
+ pub fn event_refreshview(status: &mut Status, colors: &Colors) -> FmResult<()> {
status.encrypted_devices.update()?;
- Self::refresh_status(status)
+ Self::refresh_status(status, colors)
}
/// Open a thumbnail of an image, scaled up to the whole window.
@@ -1459,13 +1464,12 @@ impl EventExec {
/// Creates a tree in every mode but "Tree".
/// It tree mode it will exit this view.
- pub fn event_tree(status: &mut Status) -> FmResult<()> {
+ pub fn event_tree(status: &mut Status, colors: &Colors) -> FmResult<()> {
if let Mode::Tree = status.selected_non_mut().mode {
Self::event_normal(status.selected())?;
status.selected().set_mode(Mode::Normal)
} else {
status.display_full = true;
- let colors = &status.config_colors.clone();
status.selected().make_tree(colors)?;
status.selected().set_mode(Mode::Tree);
let len = status.selected_non_mut().directory.len();
@@ -1476,21 +1480,19 @@ impl EventExec {
/// Fold the current node of the tree.
/// Has no effect on "file" nodes.
- pub fn event_tree_fold(status: &mut Status) -> FmResult<()> {
- let colors = &status.config_colors.clone();
+ pub fn event_tree_fold(status: &mut Status, colors: &Colors) -> FmResult<()> {
let tab = status.selected();
let (tree, _, _) = tab.directory.tree.explore_position(false);
tree.node.toggle_fold();
tab.directory.make_preview(colors);
- Self::event_select_next(status)
+ Self::event_select_next(status, colors)
}
/// Unfold every child node in the tree.
/// Recursively explore the tree and unfold every node.
/// Reset the display.
- pub fn event_tree_unfold_all(status: &mut Status) -> FmResult<()> {
- let colors = &status.config_colors.clone();
+ pub fn event_tree_unfold_all(status: &mut Status, colors: &Colors) -> FmResult<()> {
status.selected().directory.tree.unfold_children();
status.selected().directory.make_preview(colors);
Ok(())
@@ -1499,8 +1501,7 @@ impl EventExec {
/// Fold every child node in the tree.
/// Recursively explore the tree and fold every node.
/// Reset the display.
- pub fn event_tree_fold_all(status: &mut Status) -> FmResult<()> {
- let colors = &status.config_colors.clone();
+ pub fn event_tree_fold_all(status: &mut Status, colors: &Colors) -> FmResult<()> {
status.selected().directory.tree.fold_children();
status.selected().directory.make_preview(colors);
Ok(())
@@ -1508,45 +1509,38 @@ impl EventExec {
/// Fold every child node in the tree.
/// Recursively explore the tree and fold every node. Reset the display. pub fn event_tree_fold_all(status: &mut Status) -> FmResult<()> { let colors = &status.config_colors.clone(); status.selected().directory.tree.fold_children(); status.selected().directory.make_preview(colors); Ok(()) }
- pub fn event_tree_go_to_root(status: &mut Status) -> FmResult<()> {
- let colors = status.config_colors.clone();
- status.selected().tree_select_root(&colors)
+ pub fn event_tree_go_to_root(status: &mut Status, colors: &Colors) -> FmResult<()> {
+ status.selected().tree_select_root(colors)
}
/// Select the first child of the current node and reset the display.
- pub fn event_select_first_child(status: &mut Status) -> FmResult<()> {
- let colors = status.config_colors.clone();
- status.selected().tree_select_first_child(&colors)
+ pub fn event_select_first_child(status: &mut Status, colors: &Colors) -> FmResult<()> {
+ status.selected().tree_select_first_child(colors)
}
/// Select the parent of the current node and reset the display.
/// Move to the parent and reset the tree if we were in the root node.
- pub fn event_select_parent(status: &mut Status) -> FmResult<()> {
- let colors = status.config_colors.clone();
- status.selected().tree_select_parent(&colors)
+ pub fn event_select_parent(status: &mut Status, colors: &Colors) -> FmResult<()> {
+ status.selected().tree_select_parent(colors)
}
/// Select the next sibling of the current node.
- pub fn event_select_next(status: &mut Status) -> FmResult<()> {
- let colors = status.config_colors.clone();
- status.selected().tree_select_next(&colors)
+ pub fn event_select_next(status: &mut Status, colors: &Colors) -> FmResult<()> {
+ status.selected().tree_select_next(colors)
}
/// Select the previous sibling of the current node.
- pub fn event_select_prev(status: &mut Status) -> FmResult<()> {
- let colors = status.config_colors.clone();
- status.selected().tree_select_prev(&colors)
+ pub fn event_select_prev(status: &mut Status, colors: &Colors) -> FmResult<()> {
+ status.selected().tree_select_prev(colors)
}
/// Select the last leaf of the tree and reset the view.
- pub fn event_tree_go_to_bottom_leaf(status: &mut Status) -> FmResult<()> {
- let colors = status.config_colors.clone();
- status.selected().tree_go_to_bottom_leaf(&colors)
+ pub fn event_tree_go_to_bottom_leaf(status: &mut Status, colors: &Colors) -> FmResult<()> {
+ status.selected().tree_go_to_bottom_leaf(colors)
}
//