mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-23 04:22:06 +00:00
Extract method for table widths total
This commit is contained in:
parent
1b58f012e0
commit
fec4c45301
@ -61,7 +61,6 @@
|
|||||||
|
|
||||||
|
|
||||||
use std::io::{Write, Error as IOError, Result as IOResult};
|
use std::io::{Write, Error as IOError, Result as IOResult};
|
||||||
use std::ops::Add;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::vec::IntoIter as VecIntoIter;
|
use std::vec::IntoIter as VecIntoIter;
|
||||||
|
|
||||||
@ -320,7 +319,7 @@ impl<'a> Render<'a> {
|
|||||||
pub fn iterate_with_table(&'a self, table: Table<'a>, rows: Vec<Row>) -> TableIter<'a> {
|
pub fn iterate_with_table(&'a self, table: Table<'a>, rows: Vec<Row>) -> TableIter<'a> {
|
||||||
TableIter {
|
TableIter {
|
||||||
tree_trunk: TreeTrunk::default(),
|
tree_trunk: TreeTrunk::default(),
|
||||||
total_width: table.columns_count() + table.widths().iter().fold(0, Add::add),
|
total_width: table.widths().total(),
|
||||||
table: table,
|
table: table,
|
||||||
inner: rows.into_iter(),
|
inner: rows.into_iter(),
|
||||||
colours: self.colours,
|
colours: self.colours,
|
||||||
|
@ -90,12 +90,8 @@ impl<'a, 'f> Table<'a> {
|
|||||||
Table { columns, colours, env, widths }
|
Table { columns, colours, env, widths }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn columns_count(&self) -> usize {
|
pub fn widths(&self) -> &TableWidths {
|
||||||
self.columns.len()
|
&self.widths
|
||||||
}
|
|
||||||
|
|
||||||
pub fn widths(&self) -> &[usize] {
|
|
||||||
&*self.widths
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn header_row(&self) -> Row {
|
pub fn header_row(&self) -> Row {
|
||||||
@ -185,4 +181,8 @@ impl TableWidths {
|
|||||||
*old_width = max(*old_width, *cell.width);
|
*old_width = max(*old_width, *cell.width);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn total(&self) -> usize {
|
||||||
|
self.0.len() + self.0.iter().sum::<usize>()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user