Skip to content

Commit

Permalink
Add support for suppressing table columns
Browse files Browse the repository at this point in the history
  • Loading branch information
0rvar committed Aug 29, 2019
1 parent 89c861f commit 925f517
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**.
Expand Down
7 changes: 7 additions & 0 deletions src/options/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -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,
]);
2 changes: 1 addition & 1 deletion src/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
16 changes: 12 additions & 4 deletions src/options/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
}

Expand All @@ -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 })
}
}

Expand Down Expand Up @@ -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));
}
Expand Down
23 changes: 17 additions & 6 deletions src/output/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 925f517

Please sign in to comment.