summaryrefslogtreecommitdiffstats
path: root/src/output
diff options
context:
space:
mode:
authorBen S <ogham@bsago.me>2015-08-25 11:45:27 +0100
committerBen S <ogham@bsago.me>2015-08-25 11:45:27 +0100
commitec0539d314683f8340353fb271e792f9b5b19cc7 (patch)
tree1d8bedf9bd15d17d52f9a4804acbb7b6bb13497c /src/output
parent5d0bd371687610a627656a9002520564d9943c47 (diff)
Make the cells optional for display Rows.
This will be used to not provide any information for the rows that will have no data (attributes, errors).
Diffstat (limited to 'src/output')
-rw-r--r--src/output/details.rs34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/output/details.rs b/src/output/details.rs
index 2a8850d..3c0343f 100644
--- a/src/output/details.rs
+++ b/src/output/details.rs
@@ -113,7 +113,7 @@ impl Details {
struct Row {
/// Vector of cells to display.
- cells: Vec<Cell>,
+ cells: Option<Vec<Cell>>,
/// This file's name, in coloured output. The name is treated separately
/// from the other cells, as it never requires padding.
@@ -135,6 +135,15 @@ struct Row {
children: bool,
}
+impl Row {
+ fn column_width(&self, index: usize) -> usize {
+ match self.cells {
+ Some(ref cells) => cells[index].length,
+ None => 0,
+ }
+ }
+}
+
/// A **Table** object gets built up by the view as it lists files and
/// directories.
@@ -192,7 +201,7 @@ impl<U> Table<U> where U: Users {
pub fn add_header(&mut self) {
let row = Row {
depth: 0,
- cells: self.columns.iter().map(|c| Cell::paint(self.colours.header, c.header())).collect(),
+ cells: Some(self.columns.iter().map(|c| Cell::paint(self.colours.header, c.header())).collect()),
name: Cell::paint(self.colours.header, "Name"),
last: false,
attrs: Vec::new(),
@@ -211,7 +220,7 @@ impl<U> Table<U> where U: Users {
pub fn add_file_with_cells(&mut self, cells: Vec<Cell>, file: &File, depth: usize, last: bool, links: bool) {
let row = Row {
depth: depth,
- cells: cells,
+ cells: Some(cells),
name: Cell { text: filename(file, &self.colours, links), length: file.file_name_width() },
last: last,
attrs: file.xattrs.clone(),
@@ -398,19 +407,24 @@ impl<U> Table<U> where U: Users {
// each column, then formatting each cell in that column to be the
// width of that one.
let column_widths: Vec<usize> = (0 .. self.columns.len())
- .map(|n| self.rows.iter().map(|row| row.cells[n].length).max().unwrap_or(0))
+ .map(|n| self.rows.iter().map(|row| row.column_width(n)).max().unwrap_or(0))
.collect();
for row in self.rows.iter() {
let mut cell = Cell::empty();
- for (n, width) in column_widths.iter().enumerate() {
- match self.columns[n].alignment() {
- Alignment::Left => { cell.append(&row.cells[n]); cell.add_spaces(width - row.cells[n].length); }
- Alignment::Right => { cell.add_spaces(width - row.cells[n].length); cell.append(&row.cells[n]); }
- }
+ if let Some(ref cells) = row.cells {
+ for (n, width) in column_widths.iter().enumerate() {
+ match self.columns[n].alignment() {
+ Alignment::Left => { cell.append(&cells[n]); cell.add_spaces(width - cells[n].length); }
+ Alignment::Right => { cell.add_spaces(width - cells[n].length); cell.append(&cells[n]); }
+ }
- cell.add_spaces(1);
+ cell.add_spaces(1);
+ }
+ }
+ else {
+ cell.add_spaces(column_widths.len())
}
let mut filename = String::new();