mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-23 12:32:00 +00:00
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.
This commit is contained in:
parent
ca65c981f1
commit
590fb9cd60
24
src/file.rs
24
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())
|
||||
}
|
||||
|
||||
f::Time(time_in_seconds)
|
||||
pub fn created_time(&self) -> f::Time {
|
||||
f::Time(self.metadata.ctime())
|
||||
}
|
||||
|
||||
pub fn accessed_time(&self) -> f::Time {
|
||||
f::Time(self.metadata.mtime())
|
||||
}
|
||||
|
||||
/// This file's 'type'.
|
||||
|
@ -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",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -486,10 +486,14 @@ 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::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()),
|
||||
|
Loading…
Reference in New Issue
Block a user