Skip to content

Commit

Permalink
pretty colors in interactive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed Jun 4, 2019
1 parent 017be14 commit b7de02e
Showing 1 changed file with 64 additions and 26 deletions.
90 changes: 64 additions & 26 deletions src/interactive/widgets/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,36 +68,74 @@ impl<'a, 'b> Widget for Entries<'a, 'b> {
List {
block: Some(block),
items: entries.iter().skip(offset).map(|(node_idx, w)| {
let style = match selected {
Some(idx) if *idx == *node_idx => Style {
fg: Color::Black,
bg: Color::White,
..Default::default()
},
_ => Style {
fg: Color::White,
bg: Color::Reset,
..Default::default()
},
let (is_selected, style) = match selected {
Some(idx) if *idx == *node_idx => (
true,
Style {
fg: Color::Black,
bg: Color::White,
..Default::default()
},
),
_ => (
false,
Style {
fg: Color::White,
bg: Color::Reset,
..Default::default()
},
),
};
let segments = vec![Text::Styled(
fill_background_to_right(
let path = path_of(*node_idx);
let segments = vec![
Text::Styled(
format!(
"{:>byte_column_width$} | {:>5.02}% | {}{}",
"{:>byte_column_width$}",
display.byte_format.display(w.size).to_string(), // we would have to impl alignment/padding ourselves otherwise...
(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(),
byte_column_width = display.byte_format.width()
),
area.width,
)
.into(),
style,
)];
)
.into(),
Style {
fg: if is_selected {
Color::DarkGray
} else {
Color::Green
},
..style
},
),
Text::Styled(
format!(" | {:>5.02}% | ", (w.size as f64 / total as f64) * 100.0,).into(),
style,
),
Text::Styled(
fill_background_to_right(
format!(
"{prefix}{}",
w.name.to_string_lossy(),
prefix = if path.is_dir() && !is_top(*root) {
"/"
} else {
" "
}
),
area.width,
)
.into(),
Style {
fg: if path.is_dir() {
style.fg
} else {
if is_selected {
style.fg
} else {
Color::DarkGray
}
},
..style
},
),
];
segments
}),
}
Expand Down

0 comments on commit b7de02e

Please sign in to comment.