From 925f5173c123e99b308624fa805cc309afacc1b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orvar=20Segerstr=C3=B6m?= Date: Thu, 29 Aug 2019 14:34:30 +0200 Subject: [PATCH] Add support for suppressing table columns --- README.md | 4 ++++ src/options/flags.rs | 7 +++++++ src/options/mod.rs | 2 +- src/options/view.rs | 16 ++++++++++++---- src/output/table.rs | 23 +++++++++++++++++------ 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 99723f6..714dec0 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,10 @@ These options are available when running with --long (`-l`): - **-@**, **--extended**: list each file's extended attributes and sizes - **--git**: list each file's Git status, if tracked or ignored - **--time-style**: how to format timestamps +- **--no-permissions**: suppress the permissions field +- **--no-filesize**: suppress the filesize field +- **--no-user**: suppress the user field +- **--no-time**: suppress the time field - Valid **--color** options are **always**, **automatic**, and **never**. - Valid sort fields are **accessed**, **changed**, **created**, **extension**, **Extension**, **inode**, **modified**, **name**, **Name**, **size**, **type**, and **none**. Fields starting with a capital letter sort uppercase before lowercase. The modified field has the aliases **date**, **time**, and **newest**, while its reverse has the aliases **age** and **oldest**. diff --git a/src/options/flags.rs b/src/options/flags.rs index a89c63e..63dab9e 100644 --- a/src/options/flags.rs +++ b/src/options/flags.rs @@ -53,6 +53,12 @@ pub static TIME_STYLE: Arg = Arg { short: None, long: "time-style", takes_ const TIMES: Values = &["modified", "changed", "accessed", "created"]; const TIME_STYLES: Values = &["default", "long-iso", "full-iso", "iso"]; +// suppressing columns +pub static NO_PERMISSIONS: Arg = Arg { short: None, long: "no-permissions", takes_value: TakesValue::Forbidden }; +pub static NO_FILESIZE: Arg = Arg { short: None, long: "no-filesize", takes_value: TakesValue::Forbidden }; +pub static NO_USER: Arg = Arg { short: None, long: "no-user", takes_value: TakesValue::Forbidden }; +pub static NO_TIME: Arg = Arg { short: None, long: "no-time", takes_value: TakesValue::Forbidden }; + // optional feature options pub static GIT: Arg = Arg { short: None, long: "git", takes_value: TakesValue::Forbidden }; pub static EXTENDED: Arg = Arg { short: Some(b'@'), long: "extended", takes_value: TakesValue::Forbidden }; @@ -69,6 +75,7 @@ pub static ALL_ARGS: Args = Args(&[ &BINARY, &BYTES, &GROUP, &HEADER, &ICONS, &INODE, &LINKS, &MODIFIED, &CHANGED, &BLOCKS, &TIME, &ACCESSED, &CREATED, &TIME_STYLE, + &NO_PERMISSIONS, &NO_FILESIZE, &NO_USER, &NO_TIME, &GIT, &EXTENDED, ]); diff --git a/src/options/mod.rs b/src/options/mod.rs index 6231ef4..20a688d 100644 --- a/src/options/mod.rs +++ b/src/options/mod.rs @@ -148,7 +148,7 @@ impl Options { pub fn should_scan_for_git(&self) -> bool { match self.view.mode { Mode::Details(details::Options { table: Some(ref table), .. }) | - Mode::GridDetails(grid_details::Options { details: details::Options { table: Some(ref table), .. }, .. }) => table.extra_columns.git, + Mode::GridDetails(grid_details::Options { details: details::Options { table: Some(ref table), .. }, .. }) => table.columns.git, _ => false, } } diff --git a/src/options/view.rs b/src/options/view.rs index 23e9a44..97a29ee 100644 --- a/src/options/view.rs +++ b/src/options/view.rs @@ -210,8 +210,8 @@ impl TableOptions { let env = Environment::load_all(); let time_format = TimeFormat::deduce(matches, vars)?; let size_format = SizeFormat::deduce(matches)?; - let extra_columns = Columns::deduce(matches)?; - Ok(TableOptions { env, time_format, size_format, extra_columns }) + let columns = Columns::deduce(matches)?; + Ok(TableOptions { env, time_format, size_format, columns }) } } @@ -226,7 +226,11 @@ impl Columns { let inode = matches.has(&flags::INODE)?; let links = matches.has(&flags::LINKS)?; - Ok(Columns { time_types, git, blocks, group, inode, links }) + let permissions = !matches.has(&flags::NO_PERMISSIONS)?; + let filesize = !matches.has(&flags::NO_FILESIZE)?; + let user = !matches.has(&flags::NO_USER)?; + + Ok(Columns { time_types, git, blocks, group, inode, links, permissions, filesize, user }) } } @@ -308,7 +312,11 @@ impl TimeTypes { let accessed = matches.has(&flags::ACCESSED)?; let created = matches.has(&flags::CREATED)?; - let time_types = if let Some(word) = possible_word { + let no_time = matches.has(&flags::NO_TIME)?; + + let time_types = if no_time { + TimeTypes { modified: false, changed: false, accessed: false, created: false } + } else if let Some(word) = possible_word { if modified { return Err(Misfire::Useless(&flags::MODIFIED, true, &flags::TIME)); } diff --git a/src/output/table.rs b/src/output/table.rs index b0b6b84..3e14e97 100644 --- a/src/output/table.rs +++ b/src/output/table.rs @@ -23,14 +23,14 @@ pub struct Options { pub env: Environment, pub size_format: SizeFormat, pub time_format: TimeFormat, - pub extra_columns: Columns, + pub columns: Columns, } // I had to make other types derive Debug, // and Mutex is not that! impl fmt::Debug for Options { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - write!(f, "Table({:#?})", self.extra_columns) + write!(f, "Table({:#?})", self.columns) } } @@ -47,6 +47,11 @@ pub struct Columns { pub blocks: bool, pub group: bool, pub git: bool, + + // Defaults to true: + pub permissions: bool, + pub filesize: bool, + pub user: bool, } impl Columns { @@ -57,19 +62,25 @@ impl Columns { columns.push(Column::Inode); } - columns.push(Column::Permissions); + if self.permissions { + columns.push(Column::Permissions); + } if self.links { columns.push(Column::HardLinks); } - columns.push(Column::FileSize); + if self.filesize { + columns.push(Column::FileSize); + } if self.blocks { columns.push(Column::Blocks); } - columns.push(Column::User); + if self.user { + columns.push(Column::User); + } if self.group { columns.push(Column::Group); @@ -294,7 +305,7 @@ pub struct Row { impl<'a, 'f> Table<'a> { pub fn new(options: &'a Options, git: Option<&'a GitCache>, colours: &'a Colours) -> Table<'a> { - let columns = options.extra_columns.collect(git.is_some()); + let columns = options.columns.collect(git.is_some()); let widths = TableWidths::zero(columns.len()); Table {