summaryrefslogtreecommitdiffstats
path: root/src/options.rs
diff options
context:
space:
mode:
authorBen S <ogham@bsago.me>2015-02-22 00:40:41 +0000
committerBen S <ogham@bsago.me>2015-02-22 00:40:46 +0000
commita4e17193d990340b163efceff8eb5e513199d704 (patch)
tree4c33612e05d3b635342327e918f5fd8b5a372175 /src/options.rs
parentd73b0a8ab5a1b8736ac3d59db5caa31a7bbc5152 (diff)
Add sort-by-date options
These were completely missing because I forgot about them... I added sorting functionality before I added date functionality, but it turns out I didn't even need the datetime library to do this! However, this implementation feels incomplete. If you sort by the accessed date, it still displays the modified date, so the dates still look out of order. If I were to change the date column for the user, though, then there would still be no header to signify that the column has changed. I'm not sure how to proceed with this, but this is still missing functionality, so in it goes.
Diffstat (limited to 'src/options.rs')
-rw-r--r--src/options.rs21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/options.rs b/src/options.rs
index f903617..f5166b0 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -126,6 +126,9 @@ impl FileFilter {
a.name.to_ascii_lowercase().cmp(&b.name.to_ascii_lowercase())
}
}),
+ SortField::ModifiedDate => files.sort_by(|a, b| a.stat.modified.cmp(&b.stat.modified)),
+ SortField::AccessedDate => files.sort_by(|a, b| a.stat.accessed.cmp(&b.stat.accessed)),
+ SortField::CreatedDate => files.sort_by(|a, b| a.stat.created.cmp(&b.stat.created)),
}
if self.reverse {
@@ -137,7 +140,8 @@ impl FileFilter {
/// User-supplied field to sort by.
#[derive(PartialEq, Debug, Copy)]
pub enum SortField {
- Unsorted, Name, Extension, Size, FileInode
+ Unsorted, Name, Extension, Size, FileInode,
+ ModifiedDate, AccessedDate, CreatedDate,
}
impl SortField {
@@ -145,12 +149,15 @@ impl SortField {
/// Find which field to use based on a user-supplied word.
fn from_word(word: String) -> Result<SortField, Misfire> {
match word.as_slice() {
- "name" => Ok(SortField::Name),
- "size" => Ok(SortField::Size),
- "ext" => Ok(SortField::Extension),
- "none" => Ok(SortField::Unsorted),
- "inode" => Ok(SortField::FileInode),
- field => Err(SortField::none(field))
+ "name" | "filename" => Ok(SortField::Name),
+ "size" | "filesize" => Ok(SortField::Size),
+ "ext" | "extension" => Ok(SortField::Extension),
+ "mod" | "modified" => Ok(SortField::ModifiedDate),
+ "acc" | "accessed" => Ok(SortField::AccessedDate),
+ "cr" | "created" => Ok(SortField::CreatedDate),
+ "none" => Ok(SortField::Unsorted),
+ "inode" => Ok(SortField::FileInode),
+ field => Err(SortField::none(field))
}
}