summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config/joshuto.toml1
-rw-r--r--src/config/config.rs4
-rw-r--r--src/fs/dirlist.rs20
-rw-r--r--src/fs/entry.rs76
-rw-r--r--src/util/sort.rs2
5 files changed, 40 insertions, 63 deletions
diff --git a/config/joshuto.toml b/config/joshuto.toml
index de8c952..898ae0d 100644
--- a/config/joshuto.toml
+++ b/config/joshuto.toml
@@ -13,6 +13,7 @@ max_preview_size = 2097152 # 2MB
sort_method = "natural"
[sort_option]
+show_icons = true
show_hidden = false
case_sensitive = false
reverse = false
diff --git a/src/config/config.rs b/src/config/config.rs
index 9fa43f6..8b63c60 100644
--- a/src/config/config.rs
+++ b/src/config/config.rs
@@ -21,6 +21,8 @@ const fn default_column_ratio() -> (usize, usize, usize) {
#[derive(Clone, Debug, Deserialize)]
struct SortRawOption {
#[serde(default)]
+ show_icons: bool,
+ #[serde(default)]
show_hidden: bool,
#[serde(default = "default_true")]
directories_first: bool,
@@ -33,6 +35,7 @@ struct SortRawOption {
impl SortRawOption {
pub fn into_sort_option(self, sort_method: sort::SortType) -> sort::SortOption {
sort::SortOption {
+ show_icons: self.show_icons,
show_hidden: self.show_hidden,
directories_first: self.directories_first,
case_sensitive: self.case_sensitive,
@@ -45,6 +48,7 @@ impl SortRawOption {
impl std::default::Default for SortRawOption {
fn default() -> Self {
Self {
+ show_icons: bool::default(),
show_hidden: bool::default(),
directories_first: default_true(),
case_sensitive: bool::default(),
diff --git a/src/fs/dirlist.rs b/src/fs/dirlist.rs
index c7557d4..df40c9d 100644
--- a/src/fs/dirlist.rs
+++ b/src/fs/dirlist.rs
@@ -16,7 +16,7 @@ pub struct JoshutoDirList {
impl JoshutoDirList {
pub fn new(path: path::PathBuf, sort_option: &SortOption) -> std::io::Result<Self> {
let filter_func = sort_option.filter_func();
- let mut contents = read_dir_list(path.as_path(), filter_func)?;
+ let mut contents = read_dir_list(path.as_path(), filter_func, sort_option.show_icons)?;
contents.sort_by(|f1, f2| sort_option.compare(f1, f2));
let index = if contents.is_empty() { None } else { Some(0) };
@@ -65,7 +65,7 @@ impl JoshutoDirList {
pub fn reload_contents(&mut self, sort_option: &SortOption) -> std::io::Result<()> {
let filter_func = sort_option.filter_func();
- let mut contents = read_dir_list(&self.path, filter_func)?;
+ let mut contents = read_dir_list(&self.path, filter_func, sort_option.show_icons)?;
contents.sort_by(|f1, f2| sort_option.compare(f1, f2));
let contents_len = contents.len();
@@ -140,27 +140,17 @@ impl JoshutoDirList {
}
}
-fn read_dir_list<F>(path: &path::Path, filter_func: F) -> std::io::Result<Vec<JoshutoDirEntry>>
-where
- F: Fn(&Result<fs::DirEntry, std::io::Error>) -> bool,
-{
- let results: Vec<JoshutoDirEntry> = fs::read_dir(path)?
- .filter(filter_func)
- .filter_map(|res| JoshutoDirEntry::from(&res.ok()?).ok())
- .collect();
- Ok(results)
-}
-
-fn read_dir_list_icons<F>(
+fn read_dir_list<F>(
path: &path::Path,
filter_func: F,
+ show_icons: bool,
) -> std::io::Result<Vec<JoshutoDirEntry>>
where
F: Fn(&Result<fs::DirEntry, std::io::Error>) -> bool,
{
let results: Vec<JoshutoDirEntry> = fs::read_dir(path)?
.filter(filter_func)
- .filter_map(|res| JoshutoDirEntry::from(&res.ok()?).ok())
+ .filter_map(|res| JoshutoDirEntry::from(&res.ok()?, show_icons).ok())
.collect();
Ok(results)
}
diff --git a/src/fs/entry.rs b/src/fs/entry.rs
index 1dfff8c..c6124b7 100644
--- a/src/fs/entry.rs
+++ b/src/fs/entry.rs
@@ -18,30 +18,7 @@ pub struct JoshutoDirEntry {
}
impl JoshutoDirEntry {
- // pub fn from(direntry: &fs::DirEntry) -> std::io::Result<Self> {
- // let name = match direntry.file_name().into_string() {
- // Ok(s) => s,
- // Err(_) => {
- // return Err(std::io::Error::new(
- // std::io::ErrorKind::Other,
- // "Failed converting OsString to String",
- // ));
- // }
- // };
-
- // let path = direntry.path();
- // let metadata = JoshutoMetadata::from(&path)?;
-
- // Ok(Self {
- // name,
- // path,
- // metadata,
- // selected: false,
- // marked: false,
- // })
- // }
-
- pub fn from(direntry: &fs::DirEntry) -> std::io::Result<Self> {
+ pub fn from(direntry: &fs::DirEntry, show_icons: bool) -> std::io::Result<Self> {
let path = direntry.path();
let metadata = JoshutoMetadata::from(&path)?;
@@ -55,32 +32,35 @@ impl JoshutoDirEntry {
}
};
- let icon = match metadata.file_type {
- FileType::Directory => DIR_NODE_EXACT_MATCHES
- .get(name.as_str())
- .cloned()
- .unwrap_or(DEFAULT_DIR),
- _ => FILE_NODE_EXACT_MATCHES
- .get(name.as_str())
- .cloned()
- .unwrap_or(match path.extension() {
- Some(s) => FILE_NODE_EXTENSIONS
- .get(match s.to_str() {
- Some(s) => s,
- None => {
- return Err(std::io::Error::new(
- std::io::ErrorKind::Other,
- "Failed converting OsStr to str",
- ))
- }
- })
- .unwrap_or(&DEFAULT_FILE),
- None => DEFAULT_FILE,
- }),
+ let name = if show_icons {
+ let icon = match metadata.file_type {
+ FileType::Directory => DIR_NODE_EXACT_MATCHES
+ .get(name.as_str())
+ .cloned()
+ .unwrap_or(DEFAULT_DIR),
+ _ => FILE_NODE_EXACT_MATCHES
+ .get(name.as_str())
+ .cloned()
+ .unwrap_or(match path.extension() {
+ Some(s) => FILE_NODE_EXTENSIONS
+ .get(match s.to_str() {
+ Some(s) => s,
+ None => {
+ return Err(std::io::Error::new(
+ std::io::ErrorKind::Other,
+ "Failed converting OsStr to str",
+ ))
+ }
+ })
+ .unwrap_or(&DEFAULT_FILE),
+ None => DEFAULT_FILE,
+ }),
+ };
+ format!(" {} {}", icon, name)
+ } else {
+ name
};
- let name = format!("{} {}", icon, name);
-
Ok(Self {
name,
path,
diff --git a/src/util/sort.rs b/src/util/sort.rs
index cd0b84a..d58c946 100644
--- a/src/util/sort.rs
+++ b/src/util/sort.rs
@@ -36,6 +36,7 @@ impl SortType {
#[derive(Clone, Debug)]
pub struct SortOption {
+ pub show_icons: bool,
pub show_hidden: bool,
pub directories_first: bool,
pub case_sensitive: bool,
@@ -105,6 +106,7 @@ impl SortOption {
impl std::default::Default for SortOption {
fn default() -> Self {
SortOption {
+ show_icons: false,
show_hidden: false,
directories_first: true,
case_sensitive: false,