Skip to content

Commit

Permalink
Continuous lines for entry items
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed Jun 4, 2019
1 parent 2338e75 commit 0121a64
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/interactive/widgets/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
traverse::{Tree, TreeIndex},
};
use itertools::Itertools;
use std::iter::repeat;
use std::path::Path;
use tui::{
buffer::Buffer,
Expand Down Expand Up @@ -32,6 +33,16 @@ impl ListState {
}
}

fn fill_background_to_right(mut s: String, entire_width: u16) -> String {
match (s.len(), entire_width as usize) {
(x, y) if x >= y => s,
(x, y) => {
s.extend(repeat(' ').take(y - x));
s
}
}
}

pub struct Entries<'a, 'b> {
pub tree: &'a Tree,
pub root: TreeIndex,
Expand Down Expand Up @@ -96,15 +107,18 @@ impl<'a, 'b> Widget for Entries<'a, 'b> {
},
};
Text::Styled(
format!(
"{} | {:>5.02}% | {}{}",
display.byte_format.display(w.size),
(w.size as f64 / total as f64) * 100.0,
match path_of(*node_idx) {
ref p if p.is_dir() && !is_top(*root) => "/",
_ => " ",
},
w.name.to_string_lossy(),
fill_background_to_right(
format!(
"{} | {:>5.02}% | {}{}",
display.byte_format.display(w.size),
(w.size as f64 / total as f64) * 100.0,
match path_of(*node_idx) {
ref p if p.is_dir() && !is_top(*root) => "/",
_ => " ",
},
w.name.to_string_lossy(),
),
area.width,
)
.into(),
style,
Expand Down

0 comments on commit 0121a64

Please sign in to comment.