Rename some stuff

This commit is contained in:
Benjamin Sago 2017-07-03 23:25:56 +01:00
parent c0a2cf50af
commit 80d5c2ad6d
3 changed files with 11 additions and 7 deletions

View File

@ -153,14 +153,14 @@ impl<'a> Render<'a> {
// This is weird, but I can't find a way around it: // This is weird, but I can't find a way around it:
// https://internals.rust-lang.org/t/should-option-mut-t-implement-copy/3715/6 // https://internals.rust-lang.org/t/should-option-mut-t-implement-copy/3715/6
let mut table = Some(table); let mut table = Some(table);
self.add_files_to_table(&mut table, &mut rows, &self.files, TreeDepth(0)); self.add_files_to_table(&mut table, &mut rows, &self.files, TreeDepth::root());
for row in self.iterate_with_table(table.unwrap(), rows) { for row in self.iterate_with_table(table.unwrap(), rows) {
writeln!(w, "{}", row.strings())? writeln!(w, "{}", row.strings())?
} }
} }
else { else {
self.add_files_to_table(&mut None, &mut rows, &self.files, TreeDepth(0)); self.add_files_to_table(&mut None, &mut rows, &self.files, TreeDepth::root());
for row in self.iterate(rows) { for row in self.iterate(rows) {
writeln!(w, "{}", row.strings())? writeln!(w, "{}", row.strings())?
@ -278,7 +278,7 @@ impl<'a> Render<'a> {
pub fn render_header(&self, header: TableRow) -> Row { pub fn render_header(&self, header: TableRow) -> Row {
Row { Row {
tree: TreeParams::new(TreeDepth(0), false), tree: TreeParams::new(TreeDepth::root(), false),
cells: Some(header), cells: Some(header),
name: TextCell::paint_str(self.colours.header, "Name"), name: TextCell::paint_str(self.colours.header, "Name"),
} }
@ -351,7 +351,7 @@ impl<'a> Iterator for TableIter<'a> {
// If any tree characters have been printed, then add an extra // If any tree characters have been printed, then add an extra
// space, which makes the output look much better. // space, which makes the output look much better.
if !row.tree.is_zero() { if !row.tree.is_at_root() {
cell.add_spaces(1); cell.add_spaces(1);
} }
@ -400,7 +400,7 @@ impl<'a> Iterator for Iter<'a> {
// If any tree characters have been printed, then add an extra // If any tree characters have been printed, then add an extra
// space, which makes the output look much better. // space, which makes the output look much better.
if !row.tree.is_zero() { if !row.tree.is_at_root() {
cell.add_spaces(1); cell.add_spaces(1);
} }

View File

@ -120,7 +120,7 @@ impl<'a> Render<'a> {
let (ref mut table, ref mut rows) = tables[index]; let (ref mut table, ref mut rows) = tables[index];
table.add_widths(&row); table.add_widths(&row);
let details_row = drender.render_file(row, file_name.clone(), TreeParams::new(TreeDepth(0), false)); let details_row = drender.render_file(row, file_name.clone(), TreeParams::new(TreeDepth::root(), false));
rows.push(details_row); rows.push(details_row);
} }

View File

@ -142,12 +142,16 @@ impl TreeParams {
TreeParams { depth, last } TreeParams { depth, last }
} }
pub fn is_zero(&self) -> bool { pub fn is_at_root(&self) -> bool {
self.depth.0 == 0 self.depth.0 == 0
} }
} }
impl TreeDepth { impl TreeDepth {
pub fn root() -> TreeDepth {
TreeDepth(0)
}
pub fn deeper(self) -> TreeDepth { pub fn deeper(self) -> TreeDepth {
TreeDepth(self.0 + 1) TreeDepth(self.0 + 1)
} }