summaryrefslogtreecommitdiffstats
path: root/src/fs
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2020-05-12 22:33:10 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2020-05-12 22:33:10 -0400
commitddb0669bbf0b5bb9e039094e58e69a5a81f13494 (patch)
tree9031b08d8d42d59e32235c15d5ade56f12305929 /src/fs
parente99f25b7d1e6c55fbfc59c6654f00de68e7c96ea (diff)
add support for sorting via lexical and mtime
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/dirlist.rs7
-rw-r--r--src/fs/entry.rs48
2 files changed, 2 insertions, 53 deletions
diff --git a/src/fs/dirlist.rs b/src/fs/dirlist.rs
index 806377c..4bda62c 100644
--- a/src/fs/dirlist.rs
+++ b/src/fs/dirlist.rs
@@ -17,8 +17,7 @@ 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 compare_func = sort_option.compare_func();
- contents.sort_by(compare_func);
+ contents.sort_by(|f1, f2| sort_option.compare(f1, f2));
let index = if contents.is_empty() { None } else { Some(0) };
@@ -48,10 +47,8 @@ impl JoshutoDirList {
pub fn reload_contents(&mut self, sort_option: &SortOption) -> std::io::Result<()> {
let filter_func = sort_option.filter_func();
- let sort_func = sort_option.compare_func();
-
let mut contents = read_dir_list(&self.path, filter_func)?;
- contents.sort_by(sort_func);
+ contents.sort_by(|f1, f2| sort_option.compare(f1, f2));
let contents_len = contents.len();
let index: Option<usize> = if contents_len == 0 {
diff --git a/src/fs/entry.rs b/src/fs/entry.rs
index 80847b4..fbcccb7 100644
--- a/src/fs/entry.rs
+++ b/src/fs/entry.rs
@@ -66,54 +66,6 @@ impl JoshutoDirEntry {
self.selected = selected;
}
- pub fn get_fg_color(&self) -> Color {
- let metadata = &self.metadata;
- let filetype = &metadata.file_type;
-
- if self.is_selected() {
- THEME_T.selection.fg
- } else if filetype.is_dir() {
- THEME_T.directory.fg
- } else if filetype.is_symlink() {
- THEME_T.link.fg
- } else {
- match self.file_path().extension() {
- None => Color::White,
- Some(os_str) => match os_str.to_str() {
- None => Color::White,
- Some(s) => match THEME_T.ext.get(s) {
- None => Color::White,
- Some(t) => t.fg,
- },
- },
- }
- }
- }
-
- pub fn get_bg_color(&self) -> Color {
- let metadata = &self.metadata;
- let filetype = &metadata.file_type;
-
- if self.is_selected() {
- THEME_T.selection.bg
- } else if filetype.is_dir() {
- THEME_T.directory.bg
- } else if filetype.is_symlink() {
- THEME_T.link.bg
- } else {
- match self.file_path().extension() {
- None => Color::Reset,
- Some(os_str) => match os_str.to_str() {
- None => Color::Reset,
- Some(s) => match THEME_T.ext.get(s) {
- None => Color::Reset,
- Some(t) => t.bg,
- },
- },
- }
- }
- }
-
pub fn get_modifier(&self) -> Modifier {
let metadata = &self.metadata;
let filetype = &metadata.file_type;