mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-26 13:56:27 +00:00
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).
This commit is contained in:
parent
5d0bd37168
commit
ec0539d314
@ -113,7 +113,7 @@ impl Details {
|
|||||||
struct Row {
|
struct Row {
|
||||||
|
|
||||||
/// Vector of cells to display.
|
/// Vector of cells to display.
|
||||||
cells: Vec<Cell>,
|
cells: Option<Vec<Cell>>,
|
||||||
|
|
||||||
/// This file's name, in coloured output. The name is treated separately
|
/// This file's name, in coloured output. The name is treated separately
|
||||||
/// from the other cells, as it never requires padding.
|
/// from the other cells, as it never requires padding.
|
||||||
@ -135,6 +135,15 @@ struct Row {
|
|||||||
children: bool,
|
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
|
/// A **Table** object gets built up by the view as it lists files and
|
||||||
/// directories.
|
/// directories.
|
||||||
@ -192,7 +201,7 @@ impl<U> Table<U> where U: Users {
|
|||||||
pub fn add_header(&mut self) {
|
pub fn add_header(&mut self) {
|
||||||
let row = Row {
|
let row = Row {
|
||||||
depth: 0,
|
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"),
|
name: Cell::paint(self.colours.header, "Name"),
|
||||||
last: false,
|
last: false,
|
||||||
attrs: Vec::new(),
|
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) {
|
pub fn add_file_with_cells(&mut self, cells: Vec<Cell>, file: &File, depth: usize, last: bool, links: bool) {
|
||||||
let row = Row {
|
let row = Row {
|
||||||
depth: depth,
|
depth: depth,
|
||||||
cells: cells,
|
cells: Some(cells),
|
||||||
name: Cell { text: filename(file, &self.colours, links), length: file.file_name_width() },
|
name: Cell { text: filename(file, &self.colours, links), length: file.file_name_width() },
|
||||||
last: last,
|
last: last,
|
||||||
attrs: file.xattrs.clone(),
|
attrs: file.xattrs.clone(),
|
||||||
@ -398,20 +407,25 @@ impl<U> Table<U> where U: Users {
|
|||||||
// each column, then formatting each cell in that column to be the
|
// each column, then formatting each cell in that column to be the
|
||||||
// width of that one.
|
// width of that one.
|
||||||
let column_widths: Vec<usize> = (0 .. self.columns.len())
|
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();
|
.collect();
|
||||||
|
|
||||||
for row in self.rows.iter() {
|
for row in self.rows.iter() {
|
||||||
let mut cell = Cell::empty();
|
let mut cell = Cell::empty();
|
||||||
|
|
||||||
|
if let Some(ref cells) = row.cells {
|
||||||
for (n, width) in column_widths.iter().enumerate() {
|
for (n, width) in column_widths.iter().enumerate() {
|
||||||
match self.columns[n].alignment() {
|
match self.columns[n].alignment() {
|
||||||
Alignment::Left => { cell.append(&row.cells[n]); cell.add_spaces(width - row.cells[n].length); }
|
Alignment::Left => { cell.append(&cells[n]); cell.add_spaces(width - cells[n].length); }
|
||||||
Alignment::Right => { cell.add_spaces(width - row.cells[n].length); cell.append(&row.cells[n]); }
|
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();
|
let mut filename = String::new();
|
||||||
let mut filename_length = 0;
|
let mut filename_length = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user