diff options
author | Ben S <ogham@bsago.me> | 2015-11-15 16:12:16 +0000 |
---|---|---|
committer | Ben S <ogham@bsago.me> | 2015-11-15 16:12:16 +0000 |
commit | 590fb9cd601194ae579e12d06b09a883dbbe9379 (patch) | |
tree | 22167c3368c26eefdb9fad76cfd40700c5a1b666 /src | |
parent | ca65c981f1eee50344e0df2f2406bce01ed24136 (diff) |
Move time type picking to details module
Technically speaking, picking which timestamp to show for a file is a function of an output module, rather than the file itself. This also means that the `output::column` and `file` modules are now completely separate.
Diffstat (limited to 'src')
-rw-r--r-- | src/file.rs | 24 | ||||
-rw-r--r-- | src/output/column.rs | 18 | ||||
-rw-r--r-- | src/output/details.rs | 22 |
3 files changed, 34 insertions, 30 deletions
diff --git a/src/file.rs b/src/file.rs index a053521..e851405 100644 --- a/src/file.rs +++ b/src/file.rs @@ -10,14 +10,13 @@ use std::path::{Component, Path, PathBuf}; use unicode_width::UnicodeWidthStr; use dir::Dir; -use output::column::TimeType; use self::fields as f; -// Constant table copied from https://doc.rust-lang.org/src/std/sys/unix/ext/fs.rs.html#11-259 -// which is currently unstable and lacks vision for stabilization, -// see https://github.com/rust-lang/rust/issues/27712 +/// Constant table copied from https://doc.rust-lang.org/src/std/sys/unix/ext/fs.rs.html#11-259 +/// which is currently unstable and lacks vision for stabilization, +/// see https://github.com/rust-lang/rust/issues/27712 #[allow(dead_code)] mod modes { use std::os::unix::raw; @@ -281,15 +280,16 @@ impl<'dir> File<'dir> { } } - /// One of this file's timestamps, as a number in seconds. - pub fn timestamp(&self, time_type: TimeType) -> f::Time { - let time_in_seconds = match time_type { - TimeType::FileAccessed => self.metadata.atime(), - TimeType::FileModified => self.metadata.mtime(), - TimeType::FileCreated => self.metadata.ctime(), - }; + pub fn modified_time(&self) -> f::Time { + f::Time(self.metadata.mtime()) + } + + pub fn created_time(&self) -> f::Time { + f::Time(self.metadata.ctime()) + } - f::Time(time_in_seconds) + pub fn accessed_time(&self) -> f::Time { + f::Time(self.metadata.mtime()) } /// This file's 'type'. diff --git a/src/output/column.rs b/src/output/column.rs index c0a87d5..c2b8568 100644 --- a/src/output/column.rs +++ b/src/output/column.rs @@ -99,15 +99,15 @@ impl Columns { } if self.time_types.modified { - columns.push(Column::Timestamp(TimeType::FileModified)); + columns.push(Column::Timestamp(TimeType::Modified)); } if self.time_types.created { - columns.push(Column::Timestamp(TimeType::FileCreated)); + columns.push(Column::Timestamp(TimeType::Created)); } if self.time_types.accessed { - columns.push(Column::Timestamp(TimeType::FileAccessed)); + columns.push(Column::Timestamp(TimeType::Accessed)); } if cfg!(feature="git") { @@ -152,13 +152,13 @@ impl Default for SizeFormat { pub enum TimeType { /// The file’s accessed time (`st_atime`). - FileAccessed, + Accessed, /// The file’s modified time (`st_mtime`). - FileModified, + Modified, /// The file’s creation time (`st_ctime`). - FileCreated, + Created, } impl TimeType { @@ -166,9 +166,9 @@ impl TimeType { /// Returns the text to use for a column’s heading in the columns output. pub fn header(&self) -> &'static str { match *self { - TimeType::FileAccessed => "Date Accessed", - TimeType::FileModified => "Date Modified", - TimeType::FileCreated => "Date Created", + TimeType::Accessed => "Date Accessed", + TimeType::Modified => "Date Modified", + TimeType::Created => "Date Created", } } } diff --git a/src/output/details.rs b/src/output/details.rs index 95886ad..7e9775f 100644 --- a/src/output/details.rs +++ b/src/output/details.rs @@ -486,16 +486,20 @@ impl<U> Table<U> where U: Users { } fn display(&mut self, file: &File, column: &Column, xattrs: bool) -> Cell { + use output::column::TimeType::*; + match *column { - Column::Permissions => self.render_permissions(file.permissions(), xattrs), - Column::FileSize(fmt) => self.render_size(file.size(), fmt), - Column::Timestamp(t) => self.render_time(file.timestamp(t)), - Column::HardLinks => self.render_links(file.links()), - Column::Inode => self.render_inode(file.inode()), - Column::Blocks => self.render_blocks(file.blocks()), - Column::User => self.render_user(file.user()), - Column::Group => self.render_group(file.group()), - Column::GitStatus => self.render_git_status(file.git_status()), + Column::Permissions => self.render_permissions(file.permissions(), xattrs), + Column::FileSize(fmt) => self.render_size(file.size(), fmt), + Column::Timestamp(Modified) => self.render_time(file.modified_time()), + Column::Timestamp(Created) => self.render_time(file.created_time()), + Column::Timestamp(Accessed) => self.render_time(file.accessed_time()), + Column::HardLinks => self.render_links(file.links()), + Column::Inode => self.render_inode(file.inode()), + Column::Blocks => self.render_blocks(file.blocks()), + Column::User => self.render_user(file.user()), + Column::Group => self.render_group(file.group()), + Column::GitStatus => self.render_git_status(file.git_status()), } } |