summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorquentin konieczko <konieczko@gmail.com>2023-10-30 09:38:05 +0100
committerquentin konieczko <konieczko@gmail.com>2023-10-30 09:38:05 +0100
commit48875f6d0c22da351a02a5daf538597da06ab6d5 (patch)
treecec3a0941dd40de4915160a0d28ee90b1e165344
parentb9b83fc24df5d14753d67dbfaa7ac693946d67f8 (diff)
remove configurable colors, calc them every time
-rw-r--r--src/action_map.rs55
-rw-r--r--src/color_cache.rs34
-rw-r--r--src/config.rs177
-rw-r--r--src/event_dispatch.rs33
-rw-r--r--src/event_exec.rs206
-rw-r--r--src/fileinfo.rs39
-rw-r--r--src/main.rs16
-rw-r--r--src/preview.rs58
-rw-r--r--src/status.rs67
-rw-r--r--src/tab.rs87
-rw-r--r--src/term_manager.rs28
-rw-r--r--src/tree.rs19
12 files changed, 391 insertions, 428 deletions
diff --git a/src/action_map.rs b/src/action_map.rs
index 8e725a5..daefabd 100644
--- a/src/action_map.rs
+++ b/src/action_map.rs
@@ -1,7 +1,6 @@
use anyhow::Result;
use strum_macros::{Display, EnumIter, EnumString};
-use crate::config::Colors;
use crate::event_exec::{EventAction, LeaveMode};
use crate::status::Status;
@@ -107,10 +106,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, colors: &Colors) -> Result<()> {
+ pub fn matcher(&self, status: &mut Status) -> Result<()> {
let current_tab = status.selected();
match self {
- ActionMap::Back => EventAction::back(current_tab, colors),
+ ActionMap::Back => EventAction::back(current_tab),
ActionMap::BackTab => EventAction::backtab(status),
ActionMap::Backspace => EventAction::backspace(current_tab),
ActionMap::Bulk => EventAction::bulk(status),
@@ -128,48 +127,48 @@ impl ActionMap {
ActionMap::Diff => EventAction::diff(status),
ActionMap::DragNDrop => EventAction::drag_n_drop(status),
ActionMap::EncryptedDrive => EventAction::encrypted_drive(status),
- ActionMap::End => EventAction::end(status, colors),
- ActionMap::Enter => EventAction::enter(status, colors),
+ ActionMap::End => EventAction::end(status),
+ ActionMap::Enter => EventAction::enter(status),
ActionMap::Exec => EventAction::exec(current_tab),
ActionMap::Filter => EventAction::filter(current_tab),
ActionMap::FlagAll => EventAction::flag_all(status),
- ActionMap::FuzzyFind => EventAction::fuzzyfind(status, colors),
+ ActionMap::FuzzyFind => EventAction::fuzzyfind(status),
ActionMap::FuzzyFindHelp => EventAction::fuzzyfind_help(status),
- ActionMap::FuzzyFindLine => EventAction::fuzzyfind_line(status, colors),
- ActionMap::GoRoot => EventAction::go_root(status, colors),
- ActionMap::GoStart => EventAction::go_start(status, colors),
+ ActionMap::FuzzyFindLine => EventAction::fuzzyfind_line(status),
+ ActionMap::GoRoot => EventAction::go_root(status),
+ ActionMap::GoStart => EventAction::go_start(status),
ActionMap::Goto => EventAction::goto(current_tab),
ActionMap::Help => EventAction::help(status),
ActionMap::History => EventAction::history(current_tab),
- ActionMap::Home => EventAction::home(status, colors),
+ ActionMap::Home => EventAction::home(status),
ActionMap::Jump => EventAction::jump(status),
- ActionMap::KeyHome => EventAction::key_home(status, colors),
+ ActionMap::KeyHome => EventAction::key_home(status),
ActionMap::Log => EventAction::log(current_tab),
ActionMap::MarksJump => EventAction::marks_jump(status),
ActionMap::MarksNew => EventAction::marks_new(current_tab),
ActionMap::MediaInfo => EventAction::mediainfo(current_tab),
ActionMap::MocpAddToPlayList => EventAction::mocp_add_to_playlist(current_tab),
ActionMap::MocpClearPlaylist => EventAction::mocp_clear_playlist(),
- ActionMap::MocpGoToSong => EventAction::mocp_go_to_song(status, colors),
+ ActionMap::MocpGoToSong => EventAction::mocp_go_to_song(status),
ActionMap::MocpNext => EventAction::mocp_next(),
ActionMap::MocpPrevious => EventAction::mocp_previous(),
ActionMap::MocpTogglePause => EventAction::mocp_toggle_pause(status),
- ActionMap::MoveDown => EventAction::move_down(status, colors),
- ActionMap::MoveLeft => EventAction::move_left(status, colors),
- ActionMap::MoveRight => EventAction::move_right(status, colors),
- ActionMap::MoveUp => EventAction::move_up(status, colors),
+ ActionMap::MoveDown => EventAction::move_down(status),
+ ActionMap::MoveLeft => EventAction::move_left(status),
+ ActionMap::MoveRight => EventAction::move_right(status),
+ ActionMap::MoveUp => EventAction::move_up(status),
ActionMap::NewDir => EventAction::new_dir(current_tab),
ActionMap::NewFile => EventAction::new_file(current_tab),
ActionMap::NvimFilepicker => EventAction::nvim_filepicker(status),
ActionMap::NvimSetAddress => EventAction::set_nvim_server(current_tab),
ActionMap::OpenConfig => EventAction::open_config(status),
ActionMap::OpenFile => EventAction::open_file(status),
- ActionMap::PageDown => EventAction::page_down(status, colors),
- ActionMap::PageUp => EventAction::page_up(status, colors),
- ActionMap::Preview => EventAction::preview(status, colors),
+ ActionMap::PageDown => EventAction::page_down(status),
+ ActionMap::PageUp => EventAction::page_up(status),
+ ActionMap::Preview => EventAction::preview(status),
ActionMap::Quit => EventAction::quit(current_tab),
ActionMap::RefreshIfNeeded => EventAction::refresh_if_needed(current_tab),
- ActionMap::RefreshView => EventAction::refreshview(status, colors),
+ ActionMap::RefreshView => EventAction::refreshview(status),
ActionMap::RegexMatch => EventAction::regex_match(current_tab),
ActionMap::RemoteMount => EventAction::remote_mount(current_tab),
ActionMap::RemovableDevices => EventAction::removable_devices(status),
@@ -177,7 +176,7 @@ impl ActionMap {
ActionMap::ResetMode => EventAction::reset_mode(current_tab),
ActionMap::ReverseFlags => EventAction::reverse_flags(status),
ActionMap::Search => EventAction::search(current_tab),
- ActionMap::SearchNext => EventAction::search_next(status, colors),
+ ActionMap::SearchNext => EventAction::search_next(status),
ActionMap::SetWallpaper => EventAction::set_wallpaper(current_tab),
ActionMap::Shell => EventAction::shell(status),
ActionMap::ShellCommand => EventAction::shell_command(current_tab),
@@ -189,16 +188,16 @@ impl ActionMap {
ActionMap::ToggleDisplayFull => EventAction::toggle_display_full(status),
ActionMap::ToggleDualPane => EventAction::toggle_dualpane(status),
ActionMap::ToggleFlag => EventAction::toggle_flag(status),
- ActionMap::ToggleHidden => EventAction::toggle_hidden(status, colors),
- ActionMap::TogglePreviewSecond => EventAction::toggle_preview_second(status, colors),
+ ActionMap::ToggleHidden => EventAction::toggle_hidden(status),
+ ActionMap::TogglePreviewSecond => EventAction::toggle_preview_second(status),
ActionMap::TrashEmpty => EventAction::trash_empty(status),
ActionMap::TrashMoveFile => EventAction::trash_move_file(status),
ActionMap::TrashOpen => EventAction::trash_open(status),
- ActionMap::TrashRestoreFile => LeaveMode::trash(status, colors),
- ActionMap::Tree => EventAction::tree(status, colors),
- ActionMap::TreeFold => EventAction::tree_fold(current_tab, colors),
- ActionMap::TreeFoldAll => EventAction::tree_fold_all(current_tab, colors),
- ActionMap::TreeUnFoldAll => EventAction::tree_unfold_all(current_tab, colors),
+ ActionMap::TrashRestoreFile => LeaveMode::trash(status),
+ ActionMap::Tree => EventAction::tree(status),
+ ActionMap::TreeFold => EventAction::tree_fold(current_tab),
+ ActionMap::TreeFoldAll => EventAction::tree_fold_all(current_tab),
+ ActionMap::TreeUnFoldAll => EventAction::tree_unfold_all(current_tab),
ActionMap::Custom(string) => EventAction::custom(status, string),
ActionMap::Nothing => Ok(()),
diff --git a/src/color_cache.rs b/src/color_cache.rs
index 3052ff3..e8af4cd 100644
--- a/src/color_cache.rs
+++ b/src/color_cache.rs
@@ -1,5 +1,5 @@
-use std::cell::RefCell;
-use std::collections::HashMap;
+// use std::cell::RefCell;
+// use std::collections::HashMap;
use std::hash::Hasher;
use tuikit::attr::Color;
@@ -9,23 +9,23 @@ use tuikit::attr::Color;
/// per run. This trades a bit of memory for a bit of CPU.
#[derive(Default, Clone, Debug)]
pub struct ColorCache {
- cache: RefCell<HashMap<String, Color>>,
+ // cache: RefCell<HashMap<String, Color>>,
}
-impl ColorCache {
- /// Returns a color for any possible extension.
- /// The color is cached within the struct, avoiding multiple calculations.
- pub fn extension_color(&self, extension: &str) -> Color {
- let mut cache = self.cache.borrow_mut();
- if let Some(color) = cache.get(extension) {
- color.to_owned()
- } else {
- let color = extension_color(extension);
- cache.insert(extension.to_owned(), color);
- color
- }
- }
-}
+// impl ColorCache {
+// /// Returns a color for any possible extension.
+// /// The color is cached within the struct, avoiding multiple calculations.
+// pub fn extension_color(&self, extension: &str) -> Color {
+// let mut cache = self.cache.borrow_mut();
+// if let Some(color) = cache.get(extension) {
+// color.to_owned()
+// } else {
+// let color = extension_color(extension);
+// cache.insert(extension.to_owned(), color);
+// color
+// }
+// }
+// }
/// Picks a blueish/greenish color on color picker hexagon's perimeter.
fn color(coords: usize) -> Color {
diff --git a/src/config.rs b/src/config.rs
index e986cd3..5a87c64 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -2,9 +2,8 @@ use std::{fs::File, path};
use anyhow::Result;
use serde_yaml;
-use tuikit::attr::Color;
+// use tuikit::attr::Color;
-use crate::color_cache::ColorCache;
use crate::constant_strings_paths::DEFAULT_TERMINAL_APPLICATION;
use crate::keybindings::Bindings;
use crate::utils::is_program_in_path;
@@ -40,21 +39,19 @@ impl Settings {
}
}
-macro_rules! update_attribute {
- ($self_attr:expr, $yaml:ident, $key:expr) => {
- if let Some(attr) = read_yaml_value($yaml, $key) {
- $self_attr = attr;
- }
- };
-}
+// macro_rules! update_attribute {
+// ($self_attr:expr, $yaml:ident, $key:expr) => {
+// if let Some(attr) = read_yaml_value($yaml, $key) {
+// $self_attr = attr;
+// }
+// };
+// }
/// Holds every configurable aspect of the application.
/// All attributes are hardcoded then updated from optional values
/// of the config file.
/// The config file is a YAML file in `~/.config/fm/config.yaml`
#[derive(Debug, Clone)]
pub struct Config {
- /// Color of every kind of file
- pub colors: Colors,
/// The name of the terminal application. It should be installed properly.
pub terminal: String,
/// Configurable keybindings.
@@ -67,7 +64,6 @@ impl Config {
/// Returns a default config with hardcoded values.
fn new() -> Result<Self> {
Ok(Self {
- colors: Colors::default(),
terminal: DEFAULT_TERMINAL_APPLICATION.to_owned(),
binds: Bindings::default(),
settings: Settings::default(),
@@ -75,7 +71,6 @@ impl Config {
}
/// Updates the config from a configuration content.
fn update_from_config(&mut self, yaml: &serde_yaml::value::Value) -> Result<()> {
- self.colors.update_from_config(&yaml["colors"]);
self.binds.update_normal(&yaml["keys"]);
self.binds.update_custom(&yaml["custom"]);
self.update_terminal(&yaml["terminal"]);
@@ -101,85 +96,85 @@ impl Config {
}
}
-fn read_yaml_value(yaml: &serde_yaml::value::Value, key: &str) -> Option<String> {
- yaml[key].as_str().map(|s| s.to_string())
-}
-
-/// Holds configurable colors for every kind of file.
-/// "Normal" files are displayed with a different color by extension.
-#[derive(Debug, Clone)]
-pub struct Colors {
- /// Color for `directory` files.
- pub directory: String,
- /// Color for `block` files.
- pub block: String,
- /// Color for `char` files.
- pub char: String,
- /// Color for `fifo` files.
- pub fifo: String,
- /// Color for `socket` files.
- pub socket: String,
- /// Color for `symlink` files.
- pub symlink: String,
- /// Color for broken `symlink` files.
- pub broken: String,
- /// Colors for normal files, depending of extension
- pub color_cache: ColorCache,
-}
-
-impl Colors {
- fn update_from_config(&mut self, yaml: &serde_yaml::value::Value) {
- update_attribute!(self.directory, yaml, "directory");
- update_attribute!(self.block, yaml, "block");
- update_attribute!(self.char, yaml, "char");
- update_attribute!(self.fifo, yaml, "fifo");
- update_attribute!(self.socket, yaml, "socket");
- update_attribute!(self.symlink, yaml, "symlink");
- update_attribute!(self.broken, yaml, "broken");
- }
+// fn read_yaml_value(yaml: &serde_yaml::value::Value, key: &str) -> Option<String> {
+// yaml[key].as_str().map(|s| s.to_string())
+// }
- fn new() -> Self {
- Self {
- directory: "red".to_owned(),
- block: "yellow".to_owned(),
- char: "green".to_owned(),
- fifo: "blue".to_owned(),
- socket: "cyan".to_owned(),
- symlink: "magenta".to_owned(),
- broken: "white".to_owned(),
- color_cache: ColorCache::default(),
- }
- }
-}
-
-impl Default for Colors {
- fn default() -> Self {
- Self::new()
- }
-}
-
-/// Convert a string color into a `tuikit::Color` instance.
-pub fn str_to_tuikit(color: &str) -> Color {
- match color {
- "white" => Color::WHITE,
- "red" => Color::RED,
- "green" => Color::GREEN,
- "blue" => Color::BLUE,
- "yellow" => Color::YELLOW,
- "cyan" => Color::CYAN,
- "magenta" => Color::MAGENTA,
- "black" => Color::BLACK,
- "light_white" => Color::LIGHT_WHITE,
- "light_red" => Color::LIGHT_RED,
- "light_green" => Color::LIGHT_GREEN,
- "light_blue" => Color::LIGHT_BLUE,
- "light_yellow" => Color::LIGHT_YELLOW,
- "light_cyan" => Color::LIGHT_CYAN,
- "light_magenta" => Color::LIGHT_MAGENTA,
- "light_black" => Color::LIGHT_BLACK,
- _ => Color::default(),
- }
-}
+// /// Holds configurable colors for every kind of file.
+// /// "Normal" files are displayed with a different color by extension.
+// #[derive(Debug, Clone)]
+// pub struct Colors {
+// /// Color for `directory` files.
+// pub directory: String,
+// /// Color for `block` files.
+// pub block: String,
+// /// Color for `char` files.
+// pub char: String,
+// /// Color for `fifo` files.
+// pub fifo: String,
+// /// Color for `socket` files.
+// pub socket: String,
+// /// Color for `symlink` files.
+// pub symlink: String,
+// /// Color for broken `symlink` files.
+// pub broken: String,
+// // /// Colors for normal files, depending of extension
+// // pub color_cache: ColorCache,
+// }
+//
+// impl Colors {
+// fn update_from_config(&mut self, yaml: &serde_yaml::value::Value) {
+// update_attribute!(self.directory, yaml, "directory");
+// update_attribute!(self.block, yaml, "block");
+// update_attribute!(self.char, yaml, "char");
+// update_attribute!(self.fifo, yaml, "fifo");
+// update_attribute!(self.socket, yaml, "socket");
+// update_attribute!(self.symlink, yaml, "symlink");
+// update_attribute!(self.broken, yaml, "broken");
+// }
+//
+// fn new() -> Self {
+// Self {
+// directory: "red".to_owned(),
+// block: "yellow".to_owned(),
+// char: "green".to_owned(),
+// fifo: "blue".to_owned(),
+// socket: "cyan".to_owned(),
+// symlink: "magenta".to_owned(),
+// broken: "white".to_owned(),
+// // color_cache: ColorCache::default(),
+// }
+// }
+// }
+//
+// impl Default for Colors {
+// fn default() -> Self {
+// Self::new()
+// }
+// }
+//
+// /// Convert a string color into a `tuikit::Color` instance.
+// pub fn str_to_tuikit(color: &str) -> Color {
+// match color {
+// "white" => Color::WHITE,
+// "red" => Color::RED,
+// "green" => Color::GREEN,
+// "blue" => Color::BLUE,
+// "yellow" => Color::YELLOW,
+// "cyan" => Color::CYAN,
+// "magenta" => Color::MAGENTA,
+// "black" => Color::BLACK,
+// "light_white" => Color::LIGHT_WHITE,
+// "light_red" => Color::LIGHT_RED,
+// "light_green" => Color::LIGHT_GREEN,
+// "light_blue" => Color::LIGHT_BLUE,
+// "light_yellow" => Color::LIGHT_YELLOW,
+// "light_cyan" => Color::LIGHT_CYAN,
+// "light_magenta" => Color::LIGHT_MAGENTA,
+// "light_black" => Color::LIGHT_BLACK,
+// _ => Color::default(),
+// }
+// }
/// Returns a config with values from :
///
diff --git a/src/event_dispatch.rs b/src/event_dispatch.rs
index 8dfbe95..c98a894 100644
--- a/src/event_dispatch.rs
+++ b/src/event_dispatch.rs
@@ -1,7 +1,6 @@
use anyhow::Result;
use tuikit::prelude::{Event, Key, MouseButton};
-use crate::config::Colors;
use crate::event_exec::{EventAction, LeaveMode};
use crate::keybindings::Bindings;
use crate::mode::{InputSimple, MarkAction, Mode, Navigate};
@@ -30,27 +29,27 @@ impl EventDispatcher {
&self,
status: &mut Status,
ev: Event,
- colors: &Colors,
+ // colors: &Colors,
current_height: usize,
) -> Result<()> {
match ev {
Event::Key(Key::WheelUp(_, col, _)) => {
status.select_pane(col)?;
- EventAction::move_up(status, colors)?;
+ EventAction::move_up(status)?;
}
Event::Key(Key::WheelDown(_, col, _)) => {
status.select_pane(col)?;
- EventAction::move_down(status, colors)?;
+ EventAction::move_down(status)?;
}
Event::Key(Key::SingleClick(MouseButton::Left, row, col)) => {
- status.click(row, col, current_height, colors)?;
+ status.click(row, col, current_height)?;
}
Event::Key(
Key::SingleClick(MouseButton::Right, row, col)
| Key::DoubleClick(MouseButton::Left, row, col),
) => {
- status.click(row, col, current_height, colors)?;
- LeaveMode::right_click(status, colors)?;
+ status.click(row, col, current_height)?;
+ LeaveMode::right_click(status)?;
}
// reserved keybind which can't be bound to anything.
// using `Key::User(())` conflicts with skim internal which
@@ -58,24 +57,24 @@ impl EventDispatcher {
Event::Key(Key::AltPageUp) => status.selected().refresh_if_needed()?,
Event::Resize { width, height } => status.resize(width, height)?,
- Event::Key(Key::Char(c)) => self.char(status, c, colors)?,
- Event::Key(key) => self.key_matcher(status, key, colors)?,
+ Event::Key(Key::Char(c)) => self.char(status, c)?,
+ Event::Key(key) => self.key_matcher(status, key)?,
_ => (),
};
Ok(())
}
- fn key_matcher(&self, status: &mut Status, key: Key, colors: &Colors) -> Result<()> {
+ fn key_matcher(&self, status: &mut Status, key: Key) -> Result<()> {
match self.binds.get(&key) {
- Some(action) => action.matcher(status, colors),
+ Some(action) => action.matcher(status),
None => Ok(()),
}
}
- fn char(&self, status: &mut Status, c: char, colors: &Colors) -> Result<()> {
+ fn char(&self, status: &mut Status, c: char) -> Result<()> {
let tab = status.selected();
match tab.mode {
- Mode::InputSimple(InputSimple::Sort) => tab.sort(c, colors),
+ Mode::InputSimple(InputSimple::Sort) => tab.sort(c),
Mode::InputSimple(InputSimple::RegexMatch) => {
tab.input.insert(c);
status.select_from_regex()?;
@@ -87,10 +86,10 @@ impl EventDispatcher {
}
Mode::InputCompleted(_) => tab.text_insert_and_complete(c),
Mode::Normal | Mode::Tree => match self.binds.get(&Key::Char(c)) {
- Some(action) => action.matcher(status, colors),
+ Some(action) => action.matcher(status),
None => Ok(()),
},
- Mode::NeedConfirmation(confirmed_action) => status.confirm(c, confirmed_action, colors),
+ Mode::NeedConfirmation(confirmed_action) => status.confirm(c, confirmed_action),
Mode::Navigate(Navigate::Trash) if c == 'x' => status.trash.remove(),
Mode::Navigate(Navigate::EncryptedDrive) if c == 'm' => status.mount_encrypted_drive(),
Mode::Navigate(Navigate::EncryptedDrive) if c == 'g' => status.go_to_encrypted_drive(),
@@ -108,8 +107,8 @@ impl EventDispatcher {
Mode::Navigate(Navigate::Jump) if c == 'u' => status.clear_flags_and_reset_view(),
Mode::Navigate(Navigate::Jump) if c == 'x' => status.delete_single_flagged(),
Mode::Navigate(Navigate::Jump) if c == 'X' => status.trash_single_flagged(),
- Mode::Navigate(Navigate::Marks(MarkAction::Jump)) => status.marks_jump_char(c, colors),
- Mode::Navigate(Navigate::Marks(MarkAction::New)) => status.marks_new(c, colors),
+ Mode::Navigate(Navigate::Marks(MarkAction::Jump)) => status.marks_jump_char(c),
+ Mode::Navigate(Navigate::Marks(MarkAction::New)) => status.marks_new(c),
Mode::Preview | Mode::Navigate(_) => {
if tab.reset_mode() {
tab.refresh_view()?;
diff --git a/src/event_exec.rs b/src/event_exec.rs
index 6be910b..07eaa89 100644
--- a/src/event_exec.rs
+++ b/src/event_exec.rs
@@ -10,7 +10,6 @@ use sysinfo::SystemExt;
use crate::action_map::ActionMap;
use crate::completion::InputCompleted;
-use crate::config::Colors;
use crate::constant_strings_paths::{
CONFIG_PATH, DEFAULT_DRAGNDROP, DIFF, GIO, MEDIAINFO, NITROGEN, SSHFS_EXECUTABLE,
};
@@ -223,8 +222,8 @@ impl EventAction {
/// 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 preview(status: &mut Status, colors: &Colors) -> Result<()> {
- status.make_preview(colors)
+ pub fn preview(status: &mut Status) -> Result<()> {
+ status.make_preview()
}
/// Enter the delete mode.
@@ -297,13 +296,13 @@ impl EventAction {
Ok(())
}
/// Toggle the display of hidden files.
- pub fn toggle_hidden(status: &mut Status, colors: &Colors) -> Result<()> {
+ pub fn toggle_hidden(status: &mut Status) -> Result<()> {
let tab = status.selected();
tab.show_hidden = !tab.show_hidden;
tab.path_content.reset_files(&tab.filter, tab.show_hidden)?;
tab.window.reset(tab.path_content.content.len());
if let Mode::Tree = tab.mode {
- tab.make_tree(colors)?
+ tab.make_tree()?
}
Ok(())
}
@@ -428,31 +427,31 @@ impl EventAction {
}
/// Move back in history to the last visited directory.
- pub fn back(tab: &mut Tab, colors: &Colors) -> Result<()> {
- tab.back(colors)
+ pub fn back(tab: &mut Tab) -> Result<()> {
+ tab.back()
}
/// Move to $HOME aka ~.
- pub fn home(status: &mut Status, colors: &Colors) -> Result<()> {
+ pub fn home(status: &mut Status) -> Result<()> {
let tab = status.selected();
let home_cow = shellexpand::tilde("~");
let home: &str = home_cow.borrow();
let path = std::fs::canonicalize(home)?;
tab.set_pathcontent(&path)?;
- status.update_second_pane_for_preview(colors)
+ status.update_second_pane_for_preview()
}
- pub fn go_root(status: &mut Status, colors: &Colors) -> Result<()> {
+ pub fn go_root(status: &mut Status) -> Result<()> {
let tab = status.selected();
let root_path = std::path::PathBuf::from("/");
tab.set_pathcontent(&root_path)?;
- status.update_second_pane_for_preview(colors)
+ status.update_second_pane_for_preview()
}
- pub fn go_start(status: &mut Status, colors: &Colors) -> Result<()> {
+ pub fn go_start(status: &mut Status) -> Result<()> {
let start_folder = status.start_folder.clone();
status.selected().set_pathcontent(&start_folder)?;
- status.update_second_pane_for_preview(colors)
+ status.update_second_pane_for_preview()
}
/// Executes a `dragon-drop` command on the selected file.
@@ -474,7 +473,7 @@ impl EventAction {
Ok(())
}
- pub fn search_next(status: &mut Status, colors: &Colors) -> Result<()> {
+ pub fn search_next(status: &mut Status) -> Result<()> {
let tab = status.selected();
match tab.mode {
Mode::Tree => (),
@@ -484,7 +483,7 @@ impl EventAction {
};
let next_index = (tab.path_content.index + 1) % tab.path_content.content.len();
tab.search_from(&searched, next_index);
- status.update_second_pane_for_preview(colors)?;
+ status.update_second_pane_for_preview()?;
}
}
Ok(())
@@ -492,7 +491,7 @@ impl EventAction {
/// Move up one row in modes allowing movement.
/// Does nothing if the selected item is already the first in list.
- pub fn move_up(status: &mut Status, colors: &Colors) -> Result<()> {
+ pub fn move_up(status: &mut Status) -> Result<()> {
let tab = status.selected();
match tab.mode {
Mode::Normal | Mode::Preview => tab.up_one_row(),
@@ -507,15 +506,15 @@ impl EventAction {
Mode::Navigate(Navigate::CliInfo) => status.cli_info.prev(),
Mode::Navigate(Navigate::EncryptedDrive) => status.encrypted_devices.prev(),
Mode::InputCompleted(_) => tab.completion.prev(),
- Mode::Tree => tab.tree_select_prev(colors)?,
+ Mode::Tree => tab.tree_select_prev()?,
_ => (),
};
- status.update_second_pane_for_preview(colors)
+ status.update_second_pane_for_preview()
}
/// Move down one row in modes allowing movements.
/// Does nothing if the user is already at the bottom.
- pub fn move_down(status: &mut Status, colors: &Colors) -> Result<()> {
+ pub fn move_down(status: &mut Status) -> Result<()> {
match status.selected().mode {
Mode::Normal | Mode::Preview => status.selected().down_one_row(),
Mode::Navigate(Navigate::Jump) => status.flagged.next(),
@@ -529,37 +528,37 @@ impl EventAction {
Mode::Navigate(Navigate::CliInfo) => status.cli_info.next(),
Mode::Navigate(Navigate::EncryptedDrive) => status.encrypted_devices.next(),
Mode::InputCompleted(_) => status.selected().completion.next(),
- Mode::Tree => status.selected().select_next(colors)?,
+ Mode::Tree => status.selected().select_next()?,
_ => (),
};
- status.update_second_pane_for_preview(colors)
+ status.update_second_pane_for_preview()
}
/// Move to parent in normal mode,
/// move left one char in mode requiring text input.
- pub fn move_left(status: &mut Status, colors: &Colors) -> Result<()> {
+ pub fn move_left(status: &mut Status) -> Result<()> {
let tab = status.selected();
match tab.mode {
- Mode::Normal => tab.move_to_parent(colors)?,
- Mode::Tree => tab.tree_select_parent(colors)?,
+ Mode::Normal => tab.move_to_parent()?,
+ Mode::Tree => tab.tree_select_parent()?,
Mode::InputSimple(_) | Mode::InputCompleted(_) => {
tab.input.cursor_left();
}
_ => (),
}
- status.update_second_pane_for_preview(colors)
+ status.update_second_pane_for_preview()
}
/// 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 move_right(status: &mut Status, colors: &Colors) -> Result<()> {
+ pub fn move_right(status: &mut Status) -> Result<()> {
let tab: &mut Tab = status.selected();
match tab.mode {
Mode::Normal => LeaveMode::open_file(status),
Mode::Tree => {
- tab.select_first_child(colors)?;
- status.update_second_pane_for_preview(colors)
+ tab.select_first_child()?;
+ status.update_second_pane_for_preview()
}
Mode::InputSimple(_) | Mode::InputCompleted(_) => {
tab.input.cursor_right();
@@ -593,39 +592,39 @@ impl EventAction {
}
/// Move to leftmost char in mode allowing edition.
- pub fn key_home(status: &mut Status, colors: &Colors) -> Result<()> {
+ pub fn key_home(status: &mut Status) -> Result<()> {
let tab = status.selected();
match tab.mode {
Mode::Normal | Mode::Preview => tab.go_top(),
- Mode::Tree => tab.tree_go_to_root(colors)?,
+ Mode::Tree => tab.tree_go_to_root()?,
_ => tab.input.cursor_start(),
};
- status.update_second_pane_for_preview(colors)
+ status.update_second_pane_for_preview()
}
/// Move to the bottom in any mode.
- pub fn end(status: &mut Status, colors: &Colors) -> Result<()> {
+ pub fn end(status: &mut Status) -> Result<()> {
let tab = status.selected();
match tab.mode {
Mode::Normal | Mode::Preview => tab.go_bottom(),
- Mode::Tree => tab.tree_go_to_bottom_leaf(colors)?,
+ Mode::Tree => tab.tree_go_to_bottom_leaf()?,
_ => tab.input.cursor_end(),
};
- status.update_second_pane_for_preview(colors)
+ status.update_second_pane_for_preview()
}
/// Move up 10 lines in normal mode and preview.
- pub fn page_up(status: &mut Status, colors: &Colors) -> Result<()> {
+ pub fn page_up(status: &mut Status) -> Result<()> {
let tab = status.selected();
match tab.mode {
Mode::Normal => {
tab.page_up();
- status.update_second_pane_for_preview(colors)?;
+ status.update_second_pane_for_preview()?;
}
Mode::Preview => tab.page_up(),
Mode::Tree => {
- tab.tree_page_up(colors)?;
- status.update_second_pane_for_preview(colors)?;
+ tab.tree_page_up()?;
+ status.update_second_pane_for_preview()?;
}
_ => (),
};
@@ -633,17 +632,17 @@ impl EventAction {
}
/// Move down 10 lines in normal & preview mode.
- pub fn page_down(status: &mut Status, colors: &Col