diff options
author | rabite <rabite@posteo.de> | 2019-02-07 00:57:51 +0100 |
---|---|---|
committer | rabite <rabite@posteo.de> | 2019-02-07 00:57:51 +0100 |
commit | 2496d4b6e0809b9072c2a8e29416fd5e771ae7b2 (patch) | |
tree | 79c0e0709bd64223689d83d51ffb8d458195d08f /src/files.rs | |
parent | 4e9b0842f3a9166ac81da0fad1b884f09a0451a2 (diff) |
select by mtime and reverse sorting
Diffstat (limited to 'src/files.rs')
-rw-r--r-- | src/files.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/files.rs b/src/files.rs index c9f3754..e38af15 100644 --- a/src/files.rs +++ b/src/files.rs @@ -14,12 +14,13 @@ lazy_static! { static ref COLORS: LsColors = LsColors::from_env().unwrap(); } -#[derive(PartialEq)] +#[derive(PartialEq, Clone)] pub struct Files { pub directory: File, pub files: Vec<File>, pub sort: SortBy, pub dirs_first: bool, + pub reverse: bool, } impl Index<usize> for Files { @@ -79,6 +80,7 @@ impl Files { files: files, sort: SortBy::Name, dirs_first: true, + reverse: false, }; files.sort(); @@ -115,12 +117,23 @@ impl Files { if self.dirs_first { self.files.sort_by(|a, b| { - if a.is_dir() && !b.is_dir() && a.name.starts_with(".") { + if a.is_dir() && !b.is_dir() { Ordering::Less } else { Ordering::Equal } }); + self.files.sort_by(|a, b| { + if a.name.starts_with(".") && !b.name.starts_with(".") { + Ordering::Less + } else { + Ordering::Equal + } + }); + } + + if self.reverse { + self.files.reverse(); } } @@ -132,6 +145,9 @@ impl Files { }; } + pub fn reverse_sort(&mut self) { + self.reverse = !self.reverse + } pub fn len(&self) -> usize { self.files.len() } |