Skip to content

Commit

Permalink
Don't display '0' for total bytes while traversing
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed Jun 3, 2019
1 parent dcf3a26 commit 9720931
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/interactive/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub struct Traversal {
pub entries_traversed: u64,
/// Total amount of IO errors encountered when traversing the filesystem
pub io_errors: u64,
/// Total amount of bytes seen during the traversal
pub total_bytes: Option<u64>,
}

impl Traversal {
Expand Down Expand Up @@ -164,6 +166,7 @@ impl Traversal {
}
let root_size = t.recompute_root_size();
set_size_or_panic(&mut t.tree, t.root_index, root_size);
t.total_bytes = Some(root_size);

Ok(t)
}
Expand Down
31 changes: 17 additions & 14 deletions src/interactive/widgets.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{DisplayOptions, Traversal, Tree, TreeIndex};
use crate::{get_size_or_panic, ByteFormat};
use crate::ByteFormat;
use tui::layout::{Constraint, Direction, Layout};
use tui::style::{Color, Style};
use tui::{
Expand All @@ -20,7 +20,7 @@ pub struct MainWindow<'a> {
}

pub struct Footer {
pub total_bytes: u64,
pub total_bytes: Option<u64>,
pub entries_traversed: u64,
pub format: ByteFormat,
}
Expand All @@ -37,7 +37,10 @@ impl Widget for Footer {
area.y,
format!(
"Total disk usage: {} Entries: {}",
format!("{}", self.format.display(self.total_bytes)).trim(),
match self.total_bytes {
Some(b) => format!("{}", self.format.display(b)).trim().to_owned(),
None => "-".to_owned(),
},
self.entries_traversed
),
(area.width - margin) as usize,
Expand All @@ -57,6 +60,7 @@ impl<'a> Widget for MainWindow<'a> {
tree,
root_index,
entries_traversed,
total_bytes,
..
},
display,
Expand All @@ -74,7 +78,7 @@ impl<'a> Widget for MainWindow<'a> {
.draw(entries, buf);

Footer {
total_bytes: get_size_or_panic(&tree, *root_index),
total_bytes: *total_bytes,
entries_traversed: *entries_traversed,
format: display.byte_format,
}
Expand All @@ -92,17 +96,16 @@ impl<'a> Widget for Entries<'a> {
} = self;
List::new(
tree.neighbors_directed(*root, Direction::Outgoing)
.filter_map(|w| {
tree.node_weight(w).map(|w| {
Text::Raw(
format!(
"{} | ----- | {}",
display.byte_format.display(w.size),
w.name.to_string_lossy()
)
.into(),
.filter_map(|w| tree.node_weight(w))
.map(|w| {
Text::Raw(
format!(
"{} | ----- | {}",
display.byte_format.display(w.size),
w.name.to_string_lossy()
)
})
.into(),
)
}),
)
.block(Block::default().borders(Borders::ALL).title("Entries"))
Expand Down

0 comments on commit 9720931

Please sign in to comment.