Ver Fonte

Add support for suppressing table columns

Orvar Segerström há 6 anos atrás
pai
commit
925f5173c1
5 ficheiros alterados com 41 adições e 11 exclusões
  1. 4 0
      README.md
  2. 7 0
      src/options/flags.rs
  3. 1 1
      src/options/mod.rs
  4. 12 4
      src/options/view.rs
  5. 17 6
      src/output/table.rs

+ 4 - 0
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**.

+ 7 - 0
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,
 ]);

+ 1 - 1
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,
         }
     }

+ 12 - 4
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));
             }

+ 17 - 6
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<UsersCache> 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 {