Skip to content

Commit

Permalink
moved marked information from footer to title of mark pane
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed Jun 7, 2019
1 parent 8d21dbb commit 6cb2d92
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 31 deletions.
32 changes: 6 additions & 26 deletions src/interactive/widgets/footer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
interactive::{widgets::COLOR_MARKED_DARK, EntryMarkMap},
ByteFormat,
};
use crate::ByteFormat;
use std::borrow::Borrow;
use tui::{
buffer::Buffer,
Expand All @@ -13,28 +10,26 @@ use tui::{
};
pub struct Footer;

pub struct FooterProps<'a> {
pub struct FooterProps {
pub total_bytes: Option<u64>,
pub entries_traversed: u64,
pub format: ByteFormat,
pub marked: Option<&'a EntryMarkMap>,
pub message: Option<String>,
}

impl Footer {
pub fn render<'a>(&self, props: impl Borrow<FooterProps<'a>>, area: Rect, buf: &mut Buffer) {
pub fn render(&self, props: impl Borrow<FooterProps>, area: Rect, buf: &mut Buffer) {
let FooterProps {
total_bytes,
entries_traversed,
format,
marked,
message,
} = props.borrow();

let bg_color = Color::White;
let text_color = Color::Black;
let lines = [
Some(Text::Raw(
Text::Raw(
format!(
" Total disk usage: {} Entries: {} ",
match total_bytes {
Expand All @@ -44,23 +39,8 @@ impl Footer {
entries_traversed,
)
.into(),
)),
marked.and_then(|marked| match marked.is_empty() {
true => None,
false => Some(Text::Styled(
format!(
"Marked {} items ({}) ",
marked.len(),
format.display(marked.iter().map(|(_k, v)| v.size).sum::<u64>())
)
.into(),
Style {
fg: COLOR_MARKED_DARK,
bg: bg_color,
modifier: Modifier::BOLD | Modifier::RAPID_BLINK,
},
)),
}),
)
.into(),
message.as_ref().map(|m| {
Text::Styled(
m.into(),
Expand Down
4 changes: 2 additions & 2 deletions src/interactive/widgets/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl MainWindow {
if let Some((mark_area, pane)) = mark_pane {
let props = MarkPaneProps {
border_style: mark_style,
format: display.byte_format,
};
pane.render(props, mark_area, buf);
}
Expand Down Expand Up @@ -137,9 +138,8 @@ impl MainWindow {
Footer.render(
FooterProps {
total_bytes: *total_bytes,
entries_traversed: *entries_traversed,
marked: self.mark_pane.as_ref().map(|p| p.marked()),
format: display.byte_format,
entries_traversed: *entries_traversed,
message: state.message.clone(),
},
footer_area,
Expand Down
14 changes: 11 additions & 3 deletions src/interactive/widgets/mark.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::interactive::{widgets::COLOR_MARKED_LIGHT, CursorDirection, EntryMark, EntryMarkMap};
use dua::path_of;
use dua::traverse::{Tree, TreeIndex};
use dua::{path_of, ByteFormat};
use itertools::Itertools;
use std::borrow::Borrow;
use termion::{event::Key, event::Key::*};
Expand All @@ -24,6 +24,7 @@ pub struct MarkPane {

pub struct MarkPaneProps {
pub border_style: Style,
pub format: ByteFormat,
}

impl MarkPane {
Expand Down Expand Up @@ -90,10 +91,17 @@ impl MarkPane {
}

pub fn render(&mut self, props: impl Borrow<MarkPaneProps>, area: Rect, buf: &mut Buffer) {
let MarkPaneProps { border_style } = props.borrow();
let MarkPaneProps {
border_style,
format,
} = props.borrow();

let marked: &_ = &self.marked;
let title = format!("Marked Entries: {}", marked.len());
let title = format!(
"Marked {} items ({}) ",
marked.len(),
format.display(marked.iter().map(|(_k, v)| v.size).sum::<u64>())
);
let block = Block::default()
.title(&title)
.border_style(*border_style)
Expand Down

0 comments on commit 6cb2d92

Please sign in to comment.