mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-27 06:06:28 +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 unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
use dir::Dir;
|
use dir::Dir;
|
||||||
use output::column::TimeType;
|
|
||||||
|
|
||||||
use self::fields as f;
|
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)]
|
#[allow(dead_code)]
|
||||||
mod modes {
|
mod modes {
|
||||||
use std::os::unix::raw;
|
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 modified_time(&self) -> f::Time {
|
||||||
pub fn timestamp(&self, time_type: TimeType) -> f::Time {
|
f::Time(self.metadata.mtime())
|
||||||
let time_in_seconds = match time_type {
|
}
|
||||||
TimeType::FileAccessed => self.metadata.atime(),
|
|
||||||
TimeType::FileModified => self.metadata.mtime(),
|
|
||||||
TimeType::FileCreated => self.metadata.ctime(),
|
|
||||||
};
|
|
||||||
|
|
||||||
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'.
|
/// This file's 'type'.
|
||||||
|
@ -99,15 +99,15 @@ impl Columns {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if self.time_types.modified {
|
if self.time_types.modified {
|
||||||
columns.push(Column::Timestamp(TimeType::FileModified));
|
columns.push(Column::Timestamp(TimeType::Modified));
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.time_types.created {
|
if self.time_types.created {
|
||||||
columns.push(Column::Timestamp(TimeType::FileCreated));
|
columns.push(Column::Timestamp(TimeType::Created));
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.time_types.accessed {
|
if self.time_types.accessed {
|
||||||
columns.push(Column::Timestamp(TimeType::FileAccessed));
|
columns.push(Column::Timestamp(TimeType::Accessed));
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg!(feature="git") {
|
if cfg!(feature="git") {
|
||||||
@ -152,13 +152,13 @@ impl Default for SizeFormat {
|
|||||||
pub enum TimeType {
|
pub enum TimeType {
|
||||||
|
|
||||||
/// The file’s accessed time (`st_atime`).
|
/// The file’s accessed time (`st_atime`).
|
||||||
FileAccessed,
|
Accessed,
|
||||||
|
|
||||||
/// The file’s modified time (`st_mtime`).
|
/// The file’s modified time (`st_mtime`).
|
||||||
FileModified,
|
Modified,
|
||||||
|
|
||||||
/// The file’s creation time (`st_ctime`).
|
/// The file’s creation time (`st_ctime`).
|
||||||
FileCreated,
|
Created,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TimeType {
|
impl TimeType {
|
||||||
@ -166,9 +166,9 @@ impl TimeType {
|
|||||||
/// Returns the text to use for a column’s heading in the columns output.
|
/// Returns the text to use for a column’s heading in the columns output.
|
||||||
pub fn header(&self) -> &'static str {
|
pub fn header(&self) -> &'static str {
|
||||||
match *self {
|
match *self {
|
||||||
TimeType::FileAccessed => "Date Accessed",
|
TimeType::Accessed => "Date Accessed",
|
||||||
TimeType::FileModified => "Date Modified",
|
TimeType::Modified => "Date Modified",
|
||||||
TimeType::FileCreated => "Date Created",
|
TimeType::Created => "Date Created",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -486,16 +486,20 @@ impl<U> Table<U> where U: Users {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn display(&mut self, file: &File, column: &Column, xattrs: bool) -> Cell {
|
fn display(&mut self, file: &File, column: &Column, xattrs: bool) -> Cell {
|
||||||
|
use output::column::TimeType::*;
|
||||||
|
|
||||||
match *column {
|
match *column {
|
||||||
Column::Permissions => self.render_permissions(file.permissions(), xattrs),
|
Column::Permissions => self.render_permissions(file.permissions(), xattrs),
|
||||||
Column::FileSize(fmt) => self.render_size(file.size(), fmt),
|
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::HardLinks => self.render_links(file.links()),
|
Column::Timestamp(Created) => self.render_time(file.created_time()),
|
||||||
Column::Inode => self.render_inode(file.inode()),
|
Column::Timestamp(Accessed) => self.render_time(file.accessed_time()),
|
||||||
Column::Blocks => self.render_blocks(file.blocks()),
|
Column::HardLinks => self.render_links(file.links()),
|
||||||
Column::User => self.render_user(file.user()),
|
Column::Inode => self.render_inode(file.inode()),
|
||||||
Column::Group => self.render_group(file.group()),
|
Column::Blocks => self.render_blocks(file.blocks()),
|
||||||
Column::GitStatus => self.render_git_status(file.git_status()),
|
Column::User => self.render_user(file.user()),
|
||||||
|
Column::Group => self.render_group(file.group()),
|
||||||
|
Column::GitStatus => self.render_git_status(file.git_status()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user