diff options
author | Canop <cano.petrole@gmail.com> | 2020-12-14 13:35:12 +0100 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2020-12-14 13:35:12 +0100 |
commit | c067d1537d36e51d3012b5d8da584ac80fc6602b (patch) | |
tree | ce28a579f29469210f931746c0d2eb5bd147438b /src/display | |
parent | 72a1cb1d31de4257fe5cb71646c4c059753ae7f4 (diff) |
fit file count column width to what's necessary
Diffstat (limited to 'src/display')
-rw-r--r-- | src/display/displayable_tree.rs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/display/displayable_tree.rs b/src/display/displayable_tree.rs index cf576f6..9882042 100644 --- a/src/display/displayable_tree.rs +++ b/src/display/displayable_tree.rs @@ -97,14 +97,15 @@ impl<'s, 't> DisplayableTree<'s, 't> { &self, cw: &mut CropWriter<'w, W>, line: &TreeLine, + count_len: usize, selected: bool, ) -> Result<usize, termimad::Error> { Ok(if let Some(s) = line.sum { cond_bg!(count_style, self, selected, self.skin.count); - cw.queue_g_string(&count_style, format!("{:>8}", s.to_count()))?; + cw.queue_g_string(&count_style, format!("{:>width$}", s.to_count(), width=count_len))?; 1 } else { - 9 + count_len + 1 }) } @@ -398,6 +399,18 @@ impl<'s, 't> DisplayableTree<'s, 't> { let visible_cols = tree.visible_cols(); + // if necessary we compute the width of the count column + let count_len = if tree.options.show_counts { + tree.lines.iter() + .skip(1) // we don't show the counts of the root + .map(|l| l.sum.map_or(0, |s| s.to_count())) + .max() + .map(|c| format!("{}", c).len()) + .unwrap_or(0) + } else { + 0 + }; + // we compute the length of the dates, depending on the format let date_len = if tree.options.show_dates { let date_time: DateTime<Local> = Local::now(); @@ -474,7 +487,7 @@ impl<'s, 't> DisplayableTree<'s, 't> { } Col::Count => { - self.write_line_count(cw, line, selected)? + self.write_line_count(cw, line, count_len, selected)? } Col::Name => { |