summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Thiel <sthiel@thoughtworks.com>2019-06-07 09:37:36 +0530
committerSebastian Thiel <sthiel@thoughtworks.com>2019-06-07 12:51:31 +0530
commit28d84fc18f3efc7cfd4aa1728656998e652e934b (patch)
treeb23ddb1f6ab5a72e6722de27c6560e2a5e73ad9d
parent6bd6556449daae40fdabedf64866b641785787f5 (diff)
First prettier version of mark pane
-rw-r--r--src/common.rs12
-rw-r--r--src/interactive/widgets/mark.rs31
2 files changed, 40 insertions, 3 deletions
diff --git a/src/common.rs b/src/common.rs
index 1440cc4..a9eabff 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -60,6 +60,18 @@ impl ByteFormat {
_ => 10,
}
}
+ pub fn total_width(&self) -> usize {
+ use ByteFormat::*;
+ const THE_SPACE_BETWEEN_UNIT_AND_NUMBER: usize = 1;
+
+ self.width()
+ + match self {
+ Binary | MiB | GiB => 3,
+ Metric | MB | GB => 2,
+ Bytes => 1,
+ }
+ + THE_SPACE_BETWEEN_UNIT_AND_NUMBER
+ }
pub fn display(self, bytes: u64) -> ByteFormatDisplay {
ByteFormatDisplay {
format: self,
diff --git a/src/interactive/widgets/mark.rs b/src/interactive/widgets/mark.rs
index 0fd8113..9c93a3d 100644
--- a/src/interactive/widgets/mark.rs
+++ b/src/interactive/widgets/mark.rs
@@ -5,6 +5,7 @@ use itertools::Itertools;
use std::collections::btree_map::Entry;
use std::{borrow::Borrow, collections::BTreeMap, path::PathBuf};
use termion::{event::Key, event::Key::*};
+use tui::style::Color;
use tui::{
buffer::Buffer,
layout::Rect,
@@ -126,15 +127,39 @@ impl MarkPane {
Some(selected) if idx == selected => Modifier::BOLD,
_ => Modifier::empty(),
};
- let name = Text::Styled(
- v.path.to_string_lossy(),
+ let path = format!(" {}", v.path.display());
+ let path_len = path.len();
+ let path = Text::Styled(
+ path.into(),
Style {
fg: COLOR_MARKED_LIGHT,
modifier,
..Style::default()
},
);
- vec![name]
+ let bytes = Text::Styled(
+ format!(
+ "{:>byte_column_width$}",
+ format.display(v.size).to_string(), // we would have to impl alignment/padding ourselves otherwise...
+ byte_column_width = format.width()
+ )
+ .into(),
+ Style {
+ fg: Color::Green,
+ ..Default::default()
+ },
+ );
+ let spacer = Text::Raw(
+ format!(
+ "{:-space$}",
+ "",
+ space = (area.width as usize)
+ .saturating_sub(path_len)
+ .saturating_sub(format.total_width())
+ )
+ .into(),
+ );
+ vec![path, spacer, bytes]
});
let props = ListProps {