Skip to content

Commit

Permalink
First Bar implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed Jun 4, 2019
1 parent 097bce8 commit 5551c01
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
20 changes: 18 additions & 2 deletions src/interactive/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl Default for SortMode {
#[derive(Clone, Copy)]
pub enum ByteVisualization {
Percentage,
Bars,
}

pub struct DisplayByteVisualization {
Expand All @@ -46,7 +47,7 @@ pub struct DisplayByteVisualization {

impl Default for ByteVisualization {
fn default() -> Self {
ByteVisualization::Percentage
ByteVisualization::Bars
}
}

Expand All @@ -70,7 +71,22 @@ impl fmt::Display for DisplayByteVisualization {
} = self;

match format {
Percentage => write!(f, "{:>width$.02}%", percentage * 100.0, width = length - 1),
Percentage => write!(
f,
" {:>width$.02}% ",
percentage * 100.0,
width = length - 1 - 2
),
Bars => {
let block_length = (*length as f64 * percentage).round() as usize;
for _ in 0..block_length {
f.write_str(tui::symbols::block::FULL)?
}
for _ in 0..length - block_length {
f.write_str(" ")?
}
Ok(())
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/interactive/widgets/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ impl<'a, 'b> Widget for Entries<'a, 'b> {
);
let percentage = Text::Styled(
format!(
" | {} | ",
display.byte_vis.display(w.size as f64 / total as f64, 6)
" |{}| ",
display.byte_vis.display(w.size as f64 / total as f64, 10)
)
.into(),
style,
Expand Down

0 comments on commit 5551c01

Please sign in to comment.