minor tree_view refactoring
@@ -8,7 +8,7 @@ use flat_tree::{TreeLine, Tree, LineType};
pub trait TreeView {
fn tree_height(&self) -> u16;
fn write_tree(&mut self, tree: &Tree) -> io::Result<()>;
- fn write_line(&mut self, line: &TreeLine, y: u16) -> io::Result<()>;
+ fn write_line(&mut self, line: &TreeLine) -> io::Result<()>;
}
impl TreeView for App {
@@ -17,27 +17,26 @@ impl TreeView for App {
}
fn write_tree(&mut self, tree: &Tree) -> io::Result<()> {
for y in 1..self.h-2 {
- if y-1 < (tree.lines.len() as u16) {
- self.write_line(&tree.lines[(y-1) as usize], y)?;
- } else {
write!(
self.stdout,
"{}{}",
termion::cursor::Goto(1, y),
termion::clear::CurrentLine,
)?;
+ if y >= tree.lines.len() as u16 {
+ continue;
}
- }
- Ok(())
- }
- fn write_line(&mut self, line: &TreeLine, y: u16) -> io::Result<()> {
+ let line = &tree.lines[(y-1) as usize];
write!(
self.stdout,
- "{}{}{}",
- termion::cursor::Goto(1, y),
- termion::clear::CurrentLine,
+ "{}",
" ".repeat(line.depth as usize),
)?;
+ self.write_line(line)?;
+ }
+ Ok(())
+ }
+ fn write_line(&mut self, line: &TreeLine) -> io::Result<()> {
match line.content {
LineType::Dir => {
write!(
