From cd9331483e518f76f2d5aca3ae708f5e49ade0c5 Mon Sep 17 00:00:00 2001 From: Azad <49314270+Akmadan23@users.noreply.github.com> Date: Mon, 11 Mar 2024 02:16:17 +0100 Subject: feat: add `case_sensitive_ext` option for mimetype, theme and icons (#497) * feat: add `case_sensitive_ext` option for mimetype, theme and icons * Clone `CONFIG_T` instead of initializing it twice * Reimplement without `CONFIG_T` as static ref * Clippy & fmt --- src/commands/change_directory.rs | 9 ++++- src/commands/delete_files.rs | 3 +- src/commands/new_directory.rs | 3 +- src/commands/open_file.rs | 17 ++++++--- src/commands/reload.rs | 20 ++++++++-- src/commands/rename_file.rs | 3 +- src/commands/tab_ops.rs | 8 ++-- src/commands/touch_file.rs | 3 +- src/config/clean/app/config.rs | 2 + src/config/clean/app/display/sort_type.rs | 4 +- src/config/raw/app/config.rs | 2 + src/event/process_event.rs | 5 ++- src/fs/dirlist.rs | 5 ++- src/fs/entry.rs | 62 +++++++++++++++++++------------ src/history.rs | 35 ++++++++++++----- src/preview/preview_dir.rs | 3 +- src/run.rs | 1 + src/tab/tab_struct.rs | 4 +- src/util/style.rs | 4 +- 19 files changed, 133 insertions(+), 60 deletions(-) (limited to 'src') diff --git a/src/commands/change_directory.rs b/src/commands/change_directory.rs index 2e5196e..220ca59 100644 --- a/src/commands/change_directory.rs +++ b/src/commands/change_directory.rs @@ -28,6 +28,7 @@ pub fn change_directory(context: &mut AppContext, mut path: &path::Path) -> AppR }; cd(new_cwd.as_path(), context)?; + let config = context.config_ref().clone(); let options = context.config_ref().display_options_ref().clone(); let ui_context = context.ui_context_ref().clone(); let tab_options = context @@ -39,7 +40,13 @@ pub fn change_directory(context: &mut AppContext, mut path: &path::Path) -> AppR .tab_context_mut() .curr_tab_mut() .history_mut() - .populate_to_root(new_cwd.as_path(), &ui_context, &options, &tab_options)?; + .populate_to_root( + new_cwd.as_path(), + &config, + &ui_context, + &options, + &tab_options, + )?; Ok(()) } diff --git a/src/commands/delete_files.rs b/src/commands/delete_files.rs index 7d7fa33..755edb8 100644 --- a/src/commands/delete_files.rs +++ b/src/commands/delete_files.rs @@ -93,12 +93,13 @@ pub fn delete_selected_files( } let curr_tab = context.tab_context_ref().curr_tab_ref(); + let config = context.config_ref().clone(); let options = context.config_ref().display_options_ref().clone(); let curr_path = curr_tab.cwd().to_path_buf(); for (_, tab) in context.tab_context_mut().iter_mut() { let tab_options = tab.option_ref().clone(); tab.history_mut() - .reload(&curr_path, &options, &tab_options)?; + .reload(&curr_path, &config, &options, &tab_options)?; } Ok(()) } diff --git a/src/commands/new_directory.rs b/src/commands/new_directory.rs index 32b248e..d4bd68d 100644 --- a/src/commands/new_directory.rs +++ b/src/commands/new_directory.rs @@ -7,12 +7,13 @@ use crate::history::DirectoryHistory; pub fn new_directory(context: &mut AppContext, p: &path::Path) -> AppResult { std::fs::create_dir_all(p)?; + let config = context.config_ref().clone(); let options = context.config_ref().display_options_ref().clone(); let curr_path = context.tab_context_ref().curr_tab_ref().cwd().to_path_buf(); for (_, tab) in context.tab_context_mut().iter_mut() { let tab_options = tab.option_ref().clone(); tab.history_mut() - .reload(&curr_path, &options, &tab_options)?; + .reload(&curr_path, &config, &options, &tab_options)?; } if context.config_ref().focus_on_create { diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs index d206f35..8c6171e 100644 --- a/src/commands/open_file.rs +++ b/src/commands/open_file.rs @@ -2,6 +2,7 @@ use std::io; use std::path; use crate::commands::{quit, reload}; +use crate::config::clean::app::AppConfig; use crate::config::clean::mimetype::ProgramEntry; use crate::context::AppContext; use crate::error::{AppError, AppErrorKind, AppResult}; @@ -15,13 +16,19 @@ use super::change_directory; use crate::MIMETYPE_T; -fn _get_options<'a>(path: &path::Path) -> Vec<&'a ProgramEntry> { +fn _get_options<'a>(path: &path::Path, config: &AppConfig) -> Vec<&'a ProgramEntry> { let mut options: Vec<&ProgramEntry> = Vec::new(); if let Some(entries) = path .extension() .and_then(|ext| ext.to_str()) - .and_then(|file_ext| MIMETYPE_T.app_list_for_ext(file_ext)) + .and_then(|ext| { + if config.case_sensitive_ext { + MIMETYPE_T.app_list_for_ext(ext) + } else { + MIMETYPE_T.app_list_for_ext(&ext.to_lowercase()) + } + }) { options.extend(entries); return options; @@ -172,7 +179,7 @@ pub fn open(context: &mut AppContext, backend: &mut AppBackend) -> AppResult { paths.iter().map(|e| e.file_name()).collect(), ) }; - let options = _get_options(path); + let options = _get_options(path, context.config_ref()); let option = options.iter().find(|option| option.program_exists()); let config = context.config_ref(); @@ -207,7 +214,7 @@ pub fn open_with_index( )); } let files: Vec<&str> = paths.iter().map(|e| e.file_name()).collect(); - let options = _get_options(paths[0].file_path()); + let options = _get_options(paths[0].file_path(), context.config_ref()); if index >= options.len() { return Err(AppError::new( @@ -240,7 +247,7 @@ pub fn open_with_interactive(context: &mut AppContext, backend: &mut AppBackend) ); } let files: Vec<&str> = paths.iter().map(|e| e.file_name()).collect(); - let options = _get_options(paths[0].file_path()); + let options = _get_options(paths[0].file_path(), context.config_ref()); _open_with_helper(context, backend, options, &files)?; Ok(()) diff --git a/src/commands/reload.rs b/src/commands/reload.rs index 7b9a0e3..bee7754 100644 --- a/src/commands/reload.rs +++ b/src/commands/reload.rs @@ -26,6 +26,7 @@ pub fn soft_reload(context: &mut AppContext, id: &Uuid) -> std::io::Result<()> { } if !paths.is_empty() { + let config = context.config_ref().clone(); let options = context.config_ref().display_options_ref().clone(); let tab_options = context .tab_context_ref() @@ -38,8 +39,13 @@ pub fn soft_reload(context: &mut AppContext, id: &Uuid) -> std::io::Result<()> { .map(|t| t.history_mut()) { for path in paths { - let new_dirlist = - create_dirlist_with_history(history, path.as_path(), &options, &tab_options)?; + let new_dirlist = create_dirlist_with_history( + history, + path.as_path(), + &config, + &options, + &tab_options, + )?; history.insert(path, new_dirlist); } } @@ -67,6 +73,7 @@ pub fn reload(context: &mut AppContext, id: &Uuid) -> std::io::Result<()> { } if !paths.is_empty() { + let config = context.config_ref().clone(); let options = context.config_ref().display_options_ref().clone(); let tab_options = context .tab_context_ref() @@ -79,8 +86,13 @@ pub fn reload(context: &mut AppContext, id: &Uuid) -> std::io::Result<()> { .map(|t| t.history_mut()) { for path in paths { - let new_dirlist = - create_dirlist_with_history(history, path.as_path(), &options, &tab_options)?; + let new_dirlist = create_dirlist_with_history( + history, + path.as_path(), + &config, + &options, + &tab_options, + )?; history.insert(path, new_dirlist); } } diff --git a/src/commands/rename_file.rs b/src/commands/rename_file.rs index 57e1621..45ad9fe 100644 --- a/src/commands/rename_file.rs +++ b/src/commands/rename_file.rs @@ -27,6 +27,7 @@ pub fn _rename_file( .map(|lst| lst.file_path().to_path_buf()); if let Some(path) = path { + let config = context.config_ref().clone(); let options = context.config_ref().display_options_ref().clone(); let tab_options = context .tab_context_ref() @@ -35,7 +36,7 @@ pub fn _rename_file( .clone(); let history = context.tab_context_mut().curr_tab_mut().history_mut(); let new_dirlist = - create_dirlist_with_history(history, path.as_path(), &options, &tab_options)?; + create_dirlist_with_history(history, path.as_path(), &config, &options, &tab_options)?; history.insert(path, new_dirlist); } Ok(()) diff --git a/src/commands/tab_ops.rs b/src/commands/tab_ops.rs index 078362f..cbba359 100644 --- a/src/commands/tab_ops.rs +++ b/src/commands/tab_ops.rs @@ -35,6 +35,7 @@ fn _tab_switch(new_index: usize, context: &mut AppContext) -> std::io::Result<() None => None, }; + let config = context.config_ref().clone(); let options = context.config_ref().display_options_ref().clone(); let tab_options = context .tab_context_ref() @@ -44,7 +45,7 @@ fn _tab_switch(new_index: usize, context: &mut AppContext) -> std::io::Result<() let history = context.tab_context_mut().curr_tab_mut().history_mut(); if history - .create_or_soft_update(cwd.as_path(), &options, &tab_options) + .create_or_soft_update(cwd.as_path(), &config, &options, &tab_options) .is_err() { history.remove(cwd.as_path()); @@ -52,7 +53,7 @@ fn _tab_switch(new_index: usize, context: &mut AppContext) -> std::io::Result<() if let Some(cwd_parent) = cwd.parent() { if history - .create_or_soft_update(cwd_parent, &options, &tab_options) + .create_or_soft_update(cwd_parent, &config, &options, &tab_options) .is_err() { history.remove(cwd_parent); @@ -61,7 +62,7 @@ fn _tab_switch(new_index: usize, context: &mut AppContext) -> std::io::Result<() if let Some(file_path) = entry_path { if history - .create_or_soft_update(file_path.as_path(), &options, &tab_options) + .create_or_soft_update(file_path.as_path(), &config, &options, &tab_options) .is_err() { history.remove(file_path.as_path()); @@ -141,6 +142,7 @@ pub fn new_tab(context: &mut AppContext, mode: &NewTabMode) -> AppResult { let id = Uuid::new_v4(); let tab = JoshutoTab::new( new_tab_path, + context.config_ref(), context.ui_context_ref(), context.config_ref().display_options_ref(), )?; diff --git a/src/commands/touch_file.rs b/src/commands/touch_file.rs index f36beff..41ba1c3 100644 --- a/src/commands/touch_file.rs +++ b/src/commands/touch_file.rs @@ -48,6 +48,7 @@ pub fn touch_file(context: &mut AppContext, arg: &str) -> AppResult { .map(|lst| lst.file_path().to_path_buf()); if let Some(path) = path { + let config = context.config_ref().clone(); let options = context.config_ref().display_options_ref().clone(); let tab_options = context .tab_context_ref() @@ -56,7 +57,7 @@ pub fn touch_file(context: &mut AppContext, arg: &str) -> AppResult { .clone(); let history = context.tab_context_mut().curr_tab_mut().history_mut(); let new_dirlist = - create_dirlist_with_history(history, path.as_path(), &options, &tab_options)?; + create_dirlist_with_history(history, path.as_path(), &config, &options, &tab_options)?; history.insert(path, new_dirlist); } diff --git a/src/config/clean/app/config.rs b/src/config/clean/app/config.rs index ee3a24b..11272a0 100644 --- a/src/config/clean/app/config.rs +++ b/src/config/clean/app/config.rs @@ -18,6 +18,7 @@ pub struct AppConfig { pub use_trash: bool, pub xdg_open: bool, pub xdg_open_fork: bool, + pub case_sensitive_ext: bool, pub watch_files: bool, pub custom_commands: Vec, pub focus_on_create: bool, @@ -84,6 +85,7 @@ impl From for AppConfig { use_trash: raw.use_trash, xdg_open: raw.xdg_open, xdg_open_fork: raw.xdg_open_fork, + case_sensitive_ext: raw.case_sensitive_ext, watch_files: raw.watch_files, cmd_aliases: raw.cmd_aliases, focus_on_create: raw.focus_on_create, diff --git a/src/config/clean/app/display/sort_type.rs b/src/config/clean/app/display/sort_type.rs index 3041951..6741e04 100644 --- a/src/config/clean/app/display/sort_type.rs +++ b/src/config/clean/app/display/sort_type.rs @@ -123,8 +123,8 @@ fn size_sort(file1: &JoshutoDirEntry, file2: &JoshutoDirEntry) -> cmp::Ordering } fn ext_sort(file1: &JoshutoDirEntry, file2: &JoshutoDirEntry) -> cmp::Ordering { - let f1_ext = file1.get_ext(); - let f2_ext = file2.get_ext(); + let f1_ext = file1.ext().unwrap_or_default(); + let f2_ext = file2.ext().unwrap_or_default(); alphanumeric_sort::compare_str(f1_ext, f2_ext) } diff --git a/src/config/raw/app/config.rs b/src/config/raw/app/config.rs index 4ded404..8c8b0ab 100644 --- a/src/config/raw/app/config.rs +++ b/src/config/raw/app/config.rs @@ -29,6 +29,8 @@ pub struct AppConfigRaw { #[serde(default)] pub xdg_open: bool, #[serde(default)] + pub case_sensitive_ext: bool, + #[serde(default)] pub xdg_open_fork: bool, #[serde(default = "default_true")] pub watch_files: bool, diff --git a/src/event/process_event.rs b/src/event/process_event.rs index 0848dc8..91b8930 100644 --- a/src/event/process_event.rs +++ b/src/event/process_event.rs @@ -94,20 +94,21 @@ pub fn process_worker_progress(context: &mut AppContext, res: FileOperationProgr pub fn process_finished_worker(context: &mut AppContext, res: AppResult) { let worker_context = context.worker_context_mut(); let observer = worker_context.remove_worker().unwrap(); + let config = context.config_ref().clone(); let options = context.config_ref().display_options_ref().clone(); for (_, tab) in context.tab_context_mut().iter_mut() { let tab_options = tab.option_ref().clone(); if observer.dest_path().exists() { let _ = tab .history_mut() - .reload(observer.dest_path(), &options, &tab_options); + .reload(observer.dest_path(), &config, &options, &tab_options); } else { tab.history_mut().remove(observer.dest_path()); } if observer.src_path().exists() { let _ = tab .history_mut() - .reload(observer.src_path(), &options, &tab_options); + .reload(observer.src_path(), &config, &options, &tab_options); } else { tab.history_mut().remove(observer.src_path()); } diff --git a/src/fs/dirlist.rs b/src/fs/dirlist.rs index 30738f3..97affac 100644 --- a/src/fs/dirlist.rs +++ b/src/fs/dirlist.rs @@ -3,6 +3,7 @@ use std::{io, path}; use crate::config::clean::app::display::tab::TabDisplayOption; use crate::config::clean::app::display::DisplayOption; +use crate::config::clean::app::AppConfig; use crate::context::UiContext; use crate::fs::{JoshutoDirEntry, JoshutoMetadata}; use crate::history::read_directory; @@ -43,11 +44,13 @@ impl JoshutoDirList { pub fn from_path( path: path::PathBuf, + config: &AppConfig, options: &DisplayOption, tab_options: &TabDisplayOption, ) -> io::Result { let filter_func = options.filter_func(); - let mut contents = read_directory(path.as_path(), filter_func, options, tab_options)?; + let mut contents = + read_directory(path.as_path(), filter_func, config, options, tab_options)?; contents.sort_by(|f1, f2| tab_options.sort_options_ref().compare(f1, f2)); diff --git a/src/fs/entry.rs b/src/fs/entry.rs index 30a667b..d0940c3 100644 --- a/src/fs/entry.rs +++ b/src/fs/entry.rs @@ -1,7 +1,7 @@ use std::{fs, io, path}; use crate::{ - config::clean::app::display::DisplayOption, + config::clean::app::{display::DisplayOption, AppConfig}, fs::{FileType, JoshutoMetadata}, }; @@ -11,6 +11,7 @@ use crate::ICONS_T; #[derive(Clone, Debug)] pub struct JoshutoDirEntry { name: String, + ext: Option, label: String, path: path::PathBuf, pub metadata: JoshutoMetadata, @@ -25,6 +26,7 @@ impl JoshutoDirEntry { pub fn from( direntry: &walkdir::DirEntry, base: &path::Path, + config: &AppConfig, options: &DisplayOption, ) -> io::Result { let path = direntry.path().to_path_buf(); @@ -36,6 +38,18 @@ impl JoshutoDirEntry { .to_string_lossy() .to_string(); + let ext = direntry + .path() + .extension() + .and_then(|s| s.to_str()) + .map(|s| { + if config.case_sensitive_ext { + s.to_string() + } else { + s.to_lowercase() + } + }); + let mut metadata = JoshutoMetadata::from(&path)?; if options.automatically_count_files() && metadata.file_type().is_dir() { @@ -46,7 +60,7 @@ impl JoshutoDirEntry { #[cfg(feature = "devicons")] let label = if options.show_icons() { - create_icon_label(name.as_str(), &metadata) + create_icon_label(name.as_str(), &ext, config, &metadata) } else { name.clone() }; @@ -56,6 +70,7 @@ impl JoshutoDirEntry { Ok(Self { name, + ext, label, path, metadata, @@ -69,6 +84,10 @@ impl JoshutoDirEntry { self.name.as_str() } + pub fn ext(&self) -> Option<&str> { + self.ext.as_deref() + } + pub fn label(&self) -> &str { self.label.as_str() } @@ -100,14 +119,6 @@ impl JoshutoDirEntry { pub fn set_visual_mode_selected(&mut self, visual_mode_selected: bool) { self.visual_mode_selected = visual_mode_selected; } - - pub fn get_ext(&self) -> &str { - let fname = self.file_name(); - match fname.rfind('.') { - Some(pos) => &fname[pos..], - None => "", - } - } } impl std::fmt::Display for JoshutoDirEntry { @@ -142,7 +153,12 @@ impl std::cmp::Ord for JoshutoDirEntry { } #[cfg(feature = "devicons")] -fn create_icon_label(name: &str, metadata: &JoshutoMetadata) -> String { +fn create_icon_label( + name: &str, + ext: &Option, + config: &AppConfig, + metadata: &JoshutoMetadata, +) -> String { let label = { let icon = match metadata.file_type() { FileType::Directory => ICONS_T @@ -150,18 +166,18 @@ fn create_icon_label(name: &str, metadata: &JoshutoMetadata) -> String { .get(name) .cloned() .unwrap_or(ICONS_T.default_dir.clone()), - _ => ICONS_T - .file_exact - .get(name) - .cloned() - .unwrap_or(match name.rsplit_once('.') { - Some((_, ext)) => ICONS_T - .ext - .get(ext) - .unwrap_or(&ICONS_T.default_file) - .to_string(), - None => ICONS_T.default_file.clone(), - }), + _ => ICONS_T.file_exact.get(name).cloned().unwrap_or(match ext { + Some(ext) => { + let icon = if config.case_sensitive_ext { + ICONS_T.ext.get(ext) + } else { + ICONS_T.ext.get(&ext.to_lowercase()) + }; + + icon.unwrap_or(&ICONS_T.default_file).to_string() + } + None => ICONS_T.default_file.clone(), + }), }; format!("{} {}", icon, name) }; diff --git a/src/history.rs b/src/history.rs index c1fd782..0035d88 100644 --- a/src/history.rs +++ b/src/history.rs @@ -7,6 +7,7 @@ use walkdir::WalkDir; use crate::config::clean::app::display::dirlist::DirListDisplayOptions; use crate::config::clean::app::display::tab::TabDisplayOption; use crate::config::clean::app::display::DisplayOption; +use crate::config::clean::app::AppConfig; use crate::context::UiContext; use crate::fs::{JoshutoDirEntry, JoshutoDirList, JoshutoMetadata}; @@ -14,6 +15,7 @@ pub trait DirectoryHistory { fn populate_to_root( &mut self, path: &Path, + config: &AppConfig, ui_context: &UiContext, options: &DisplayOption, tab_options: &TabDisplayOption, @@ -21,18 +23,21 @@ pub trait DirectoryHistory { fn create_or_soft_update( &mut self, path: &Path, + config: &AppConfig, options: &DisplayOption, tab_options: &TabDisplayOption, ) -> io::Result<()>; fn create_or_reload( &mut self, path: &Path, + config: &AppConfig, options: &DisplayOption, tab_options: &TabDisplayOption, ) -> io::Result<()>; fn reload( &mut self, path: &Path, + config: &AppConfig, options: &DisplayOption, tab_options: &TabDisplayOption, ) -> io::Result<()>; @@ -47,6 +52,7 @@ impl DirectoryHistory for JoshutoHistory { fn populate_to_root( &mut self, path: &Path, + config: &AppConfig, ui_context: &UiContext, options: &DisplayOption, tab_options: &TabDisplayOption, @@ -57,7 +63,7 @@ impl DirectoryHistory for JoshutoHistory { for curr in path.ancestors() { if self.contains_key(curr) { let mut new_dirlist = - create_dirlist_with_history(self, curr, options, tab_options)?; + create_dirlist_with_history(self, curr, config, options, tab_options)?; if let Some(ancestor) = prev.as_ref() { if let Some(i) = get_index_of_value(&new_dirlist.contents, ancestor) { new_dirlist.set_index(Some(i), ui_context, options); @@ -65,8 +71,12 @@ impl DirectoryHistory for JoshutoHistory { } dirlists.push(new_dirlist); } else { - let mut new_dirlist = - JoshutoDirList::from_path(curr.to_path_buf().clone(), options, tab_options)?; + let mut new_dirlist = JoshutoDirList::from_path( + curr.to_path_buf().clone(), + config, + options, + tab_options, + )?; if let Some(ancestor) = prev.as_ref() { if let Some(i) = get_index_of_value(&new_dirlist.contents, ancestor) { new_dirlist.set_index(Some(i), ui_context, options); @@ -85,6 +95,7 @@ impl DirectoryHistory for JoshutoHistory { fn create_or_soft_update( &mut self, path: &Path, + config: &AppConfig, options: &DisplayOption, tab_options: &TabDisplayOption, ) -> io::Result<()> { @@ -95,9 +106,9 @@ impl DirectoryHistory for JoshutoHistory { }; if need_update { let dirlist = if contains_key { - create_dirlist_with_history(self, path, options, tab_options)? + create_dirlist_with_history(self, path, config, options, tab_options)? } else { - JoshutoDirList::from_path(path.to_path_buf(), options, tab_options)? + JoshutoDirList::from_path(path.to_path_buf(), config, options, tab_options)? }; self.insert(path.to_path_buf(), dirlist); } @@ -107,13 +118,14 @@ impl DirectoryHistory for JoshutoHistory { fn create_or_reload( &mut self, path: &Path, + config: &AppConfig, options: &DisplayOption, tab_options: &TabDisplayOption, ) -> io::Result<()> { let dirlist = if self.contains_key(path) { - create_dirlist_with_history(self, path, options, tab_options)? + create_dirlist_with_history(self, path, config, options, tab_options)? } else { - JoshutoDirList::from_path(path.to_path_buf(), options, tab_options)? + JoshutoDirList::from_path(path.to_path_buf(), config, options, tab_options)? }; self.insert(path.to_path_buf(), dirlist); Ok(()) @@ -122,10 +134,11 @@ impl DirectoryHistory for JoshutoHistory { fn reload( &mut self, path: &Path, + config: &AppConfig, options: &DisplayOption, tab_options: &TabDisplayOption, ) -> io::Result<()> { - let dirlist = create_dirlist_with_history(self, path, options, tab_options)?; + let dirlist = create_dirlist_with_history(self, path, config, options, tab_options)?; self.insert(path.to_path_buf(), dirlist); Ok(()) } @@ -154,11 +167,12 @@ fn get_index_of_value(arr: &[JoshutoDirEntry], val: &Path) -> Option { pub fn create_dirlist_with_history( history: &JoshutoHistory, path: &Path, + config: &AppConfig, options: &DisplayOption, tab_options: &TabDisplayOption, ) -> io::Result { let filter_func = options.filter_func(); - let mut contents = read_directory(path, filter_func, options, tab_options)?; + let mut contents = read_directory(path, filter_func, config, options, tab_options)?; // re-use directory size information on reload for entry in contents.iter_mut() { @@ -245,6 +259,7 @@ pub fn create_dirlist_with_history( pub fn read_directory( path: &Path, filter_func: F, + config: &AppConfig, options: &DisplayOption, tab_options: &TabDisplayOption, ) -> io::Result> @@ -273,7 +288,7 @@ where true } }) - .filter_map(|res| JoshutoDirEntry::from(&res.ok()?, path, options).ok()) + .filter_map(|res| JoshutoDirEntry::from(&res.ok()?, path, config, options).ok()) .collect(); Ok(results) diff --git a/src/preview/preview_dir.rs b/src/preview/preview_dir.rs index 77090a3..98f6b95 100644 --- a/src/preview/preview_dir.rs +++ b/src/preview/preview_dir.rs @@ -22,6 +22,7 @@ pub struct Background {} impl Background { pub fn load_preview(context: &mut AppContext, p: path::PathBuf) -> thread::JoinHandle<()> { let event_tx = context.events.event_tx.clone(); + let config = context.config_ref().clone(); let options = context.config_ref().display_options_ref().clone(); let tab_options = context .tab_context_ref() @@ -39,7 +40,7 @@ impl Background { thread::spawn(move || { let path_clone = p.clone(); - let dir_res = JoshutoDirList::from_path(p, &options, &tab_options); + let dir_res = JoshutoDirList::from_path(p, &config, &options, &tab_options); let res = AppEvent::PreviewDir { id: tab_id, path: path_clone, diff --git a/src/run.rs b/src/run.rs index 958fe80..a427bf0 100644 --- a/src/run.rs +++ b/src/run.rs @@ -34,6 +34,7 @@ pub fn run_loop( // Initialize an initial tab let tab = JoshutoTab::new( curr_path, + context.config_ref(), context.ui_context_ref(), context.config_ref().display_options_ref(), )?; diff --git a/src/tab/tab_struct.rs b/src/tab/tab_struct.rs index 932407f..66733bf 100644 --- a/src/tab/tab_struct.rs +++ b/src/tab/tab_struct.rs @@ -3,6 +3,7 @@ use std::path; use crate::config::clean::app::display::tab::TabDisplayOption; use crate::config::clean::app::display::DisplayOption; +use crate::config::clean::app::AppConfig; use crate::context::UiContext; use crate::fs::JoshutoDirList; use crate::history::{DirectoryHistory, JoshutoHistory}; @@ -23,13 +24,14 @@ pub struct JoshutoTab { impl JoshutoTab { pub fn new( cwd: path::PathBuf, + config: &AppConfig, ui_context: &UiContext, options: &DisplayOption, ) -> std::io::Result { let mut history = JoshutoHistory::new(); let tab_options = options.default_tab_display_option.clone(); - history.populate_to_root(cwd.as_path(), ui_context, options, &tab_options)?; + history.populate_to_root(cwd.as_path(), config, ui_context, options, &tab_options)?; let new_tab = Self { _cwd: cwd, _previous_dir: None, diff --git a/src/util/style.rs b/src/util/style.rs index 0373c0c..de5a622 100644 --- a/src/util/style.rs +++ b/src/util/style.rs @@ -122,9 +122,7 @@ fn file_style(entry: &JoshutoDirEntry) -> Style { .add_modifier(THEME_T.executable.modifier) } else { entry - .file_path() - .extension() - .and_then(|s| s.to_str()) + .ext() .and_then(|s| THEME_T.ext.get(s)) .map(|theme| { Style::default() -- cgit v1.2.3