Skip to content

Commit

Permalink
First version of help line which tells what to do to delete things
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed Jun 7, 2019
1 parent 88ec5d5 commit f34ceeb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 20 deletions.
12 changes: 7 additions & 5 deletions src/interactive/widgets/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ impl MainWindow {
}
};

let regions = Layout::default()
.direction(Direction::Vertical)
.constraints([Length(1), Max(256), Length(1)].as_ref())
.split(area);
let (header_area, entries_area, footer_area) = (regions[0], regions[1], regions[2]);
let (header_area, entries_area, footer_area) = {
let regions = Layout::default()
.direction(Direction::Vertical)
.constraints([Length(1), Max(256), Length(1)].as_ref())
.split(area);
(regions[0], regions[1], regions[2])
};
{
let marked = self.mark_pane.as_ref().map(|p| p.marked());
let bg_color = match (marked.map_or(true, |m| m.is_empty()), state.focussed) {
Expand Down
70 changes: 55 additions & 15 deletions src/interactive/widgets/mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ use termion::{event::Key, event::Key::*};
use tui::{
buffer::Buffer,
layout::Rect,
style::Color,
style::{Modifier, Style},
layout::{Constraint, Direction, Layout},
style::{Color, Modifier, Style},
widgets::Block,
widgets::Borders,
widgets::Text,
widgets::{Paragraph, Widget},
};
use tui_react::{List, ListProps};
use unicode_segmentation::UnicodeSegmentation;
Expand Down Expand Up @@ -111,17 +112,6 @@ impl MarkPane {
marked.len(),
format.display(marked.iter().map(|(_k, v)| v.size).sum::<u64>())
);
let block = Block::default()
.title(&title)
.border_style(*border_style)
.borders(Borders::ALL);
let entry_in_view = match self.selected {
Some(s) => Some(s),
None => {
self.list.offset = 0;
Some(marked.len().saturating_sub(1))
}
};
let selected = self.selected;
let entries = marked
.values()
Expand Down Expand Up @@ -180,10 +170,60 @@ impl MarkPane {
vec![path, spacer, bytes]
});

let entry_in_view = match self.selected {
Some(s) => Some(s),
None => {
self.list.offset = 0;
Some(marked.len().saturating_sub(1))
}
};
let mut block = Block::default()
.title(&title)
.border_style(*border_style)
.borders(Borders::ALL);

let inner_area = block.inner(area);
block.draw(area, buf);

let (help_line_area, list_area) = {
let regions = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Length(1), Constraint::Max(256)].as_ref())
.split(inner_area);
(regions[0], regions[1])
};

let default_style = Style {
fg: Color::Black,
bg: Color::White,
modifier: Modifier::BOLD,
..Default::default()
};
Paragraph::new(
[
Text::Styled(
" Ctrl + Shift + r".into(),
Style {
fg: Color::Red,
..default_style
},
),
Text::Styled(
" permanently deletes list without prompt".into(),
default_style,
),
]
.iter(),
)
.style(Style {
bg: Color::White,
..Style::default()
})
.draw(help_line_area, buf);
let props = ListProps {
block: Some(block),
block: None,
entry_in_view,
};
self.list.render(props, entries, area, buf)
self.list.render(props, entries, list_area, buf)
}
}

0 comments on commit f34ceeb

Please sign in to comment.