diff options
author | Ben S <ogham@bsago.me> | 2015-08-26 12:00:31 +0100 |
---|---|---|
committer | Ben S <ogham@bsago.me> | 2015-08-26 12:00:31 +0100 |
commit | 5e1ff9cdcd1c6792b6dd3374ab6dc50e0bf5f669 (patch) | |
tree | bef1b3e576685235e1cdd3e6082164ca1c78362c | |
parent | 31dec1d1bab6821fef8591f755a37d779c3a2d01 (diff) |
Restore xattrs to their long view column
Had to thread the value in at display-time to get it to only query the attributes once!
This isn't the nicest way to do it, but this *is* a bit of an edge-case (it's the only thing where a column depends on something that gets calculated later)
-rw-r--r-- | src/output/details.rs | 41 | ||||
-rw-r--r-- | src/output/grid_details.rs | 10 |
2 files changed, 33 insertions, 18 deletions
diff --git a/src/output/details.rs b/src/output/details.rs index 5ca0846..3052448 100644 --- a/src/output/details.rs +++ b/src/output/details.rs @@ -86,21 +86,28 @@ impl Details { /// is present. fn add_files_to_table<U: Users>(&self, table: &mut Table<U>, src: &[File], depth: usize) { for (index, file) in src.iter().enumerate() { - table.add_file(file, depth, index == src.len() - 1, true); - let mut xattrs = Vec::new(); let mut errors = Vec::new(); - if self.xattr { - match file.path.attributes() { - Ok(xs) => { + let has_xattrs = match file.path.attributes() { + Ok(xs) => { + let r = !xs.is_empty(); + if self.xattr { for xattr in xs { xattrs.push(xattr); } - }, - Err(e) => errors.push((e, None)), - } - } + } + r + }, + Err(e) => { + if self.xattr { + errors.push((e, None)); + } + true + }, + }; + + table.add_file(file, depth, index == src.len() - 1, true, has_xattrs); // There are two types of recursion that exa supports: a tree // view, which is dealt with here, and multiple listings, which is @@ -290,8 +297,8 @@ impl<U> Table<U> where U: Users { } /// Get the cells for the given file, and add the result to the table. - fn add_file(&mut self, file: &File, depth: usize, last: bool, links: bool) { - let cells = self.cells_for_file(file); + fn add_file(&mut self, file: &File, depth: usize, last: bool, links: bool, xattrs: bool) { + let cells = self.cells_for_file(file, xattrs); self.add_file_with_cells(cells, file, depth, last, links) } @@ -308,15 +315,15 @@ impl<U> Table<U> where U: Users { /// Use the list of columns to find which cells should be produced for /// this file, per-column. - pub fn cells_for_file(&mut self, file: &File) -> Vec<Cell> { + pub fn cells_for_file(&mut self, file: &File, xattrs: bool) -> Vec<Cell> { self.columns.clone().iter() - .map(|c| self.display(file, c)) + .map(|c| self.display(file, c, xattrs)) .collect() } - fn display(&mut self, file: &File, column: &Column) -> Cell { + fn display(&mut self, file: &File, column: &Column, xattrs: bool) -> Cell { match *column { - Column::Permissions => self.render_permissions(file.permissions()), + 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::HardLinks => self.render_links(file.links()), @@ -328,7 +335,7 @@ impl<U> Table<U> where U: Users { } } - fn render_permissions(&self, permissions: f::Permissions) -> Cell { + fn render_permissions(&self, permissions: f::Permissions, xattrs: bool) -> Cell { let c = self.colours.perms; let bit = |bit, chr: &'static str, style: Style| { if bit { style.paint(chr) } else { self.colours.punctuation.paint("-") } @@ -358,7 +365,7 @@ impl<U> Table<U> where U: Users { bit(permissions.other_execute, "x", c.other_execute), ]; - if permissions.attribute { + if xattrs { columns.push(c.attribute.paint("@")); } diff --git a/src/output/grid_details.rs b/src/output/grid_details.rs index 5a5804d..bca3c8b 100644 --- a/src/output/grid_details.rs +++ b/src/output/grid_details.rs @@ -5,6 +5,7 @@ use term_grid as grid; use column::{Column, Cell}; use dir::Dir; +use feature::xattr::FileAttributes; use file::File; use output::details::{Details, Table}; use output::grid::Grid; @@ -15,6 +16,13 @@ pub struct GridDetails { pub details: Details, } +fn file_has_xattrs(file: &File) -> bool { + match file.path.attributes() { + Ok(attrs) => !attrs.is_empty(), + Err(_) => false, + } +} + impl GridDetails { pub fn view(&self, dir: Option<&Dir>, files: &[File]) { let columns_for_dir = match self.details.columns { @@ -23,7 +31,7 @@ impl GridDetails { }; let mut first_table = Table::with_options(self.details.colours, columns_for_dir.clone()); - let cells: Vec<_> = files.iter().map(|file| first_table.cells_for_file(file)).collect(); + let cells: Vec<_> = files.iter().map(|file| first_table.cells_for_file(file, file_has_xattrs(file))).collect(); let mut last_working_table = self.make_grid(1, &*columns_for_dir, files, cells.clone()); |