Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f34ceeb

Browse files
author
Sebastian Thiel
committed
First version of help line which tells what to do to delete things
1 parent 88ec5d5 commit f34ceeb

2 files changed

Lines changed: 62 additions & 20 deletions

File tree

src/interactive/widgets/main.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ impl MainWindow {
6565
}
6666
};
6767

68-
let regions = Layout::default()
69-
.direction(Direction::Vertical)
70-
.constraints([Length(1), Max(256), Length(1)].as_ref())
71-
.split(area);
72-
let (header_area, entries_area, footer_area) = (regions[0], regions[1], regions[2]);
68+
let (header_area, entries_area, footer_area) = {
69+
let regions = Layout::default()
70+
.direction(Direction::Vertical)
71+
.constraints([Length(1), Max(256), Length(1)].as_ref())
72+
.split(area);
73+
(regions[0], regions[1], regions[2])
74+
};
7375
{
7476
let marked = self.mark_pane.as_ref().map(|p| p.marked());
7577
let bg_color = match (marked.map_or(true, |m| m.is_empty()), state.focussed) {

src/interactive/widgets/mark.rs

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ use termion::{event::Key, event::Key::*};
1212
use tui::{
1313
buffer::Buffer,
1414
layout::Rect,
15-
style::Color,
16-
style::{Modifier, Style},
15+
layout::{Constraint, Direction, Layout},
16+
style::{Color, Modifier, Style},
1717
widgets::Block,
1818
widgets::Borders,
1919
widgets::Text,
20+
widgets::{Paragraph, Widget},
2021
};
2122
use tui_react::{List, ListProps};
2223
use unicode_segmentation::UnicodeSegmentation;
@@ -111,17 +112,6 @@ impl MarkPane {
111112
marked.len(),
112113
format.display(marked.iter().map(|(_k, v)| v.size).sum::<u64>())
113114
);
114-
let block = Block::default()
115-
.title(&title)
116-
.border_style(*border_style)
117-
.borders(Borders::ALL);
118-
let entry_in_view = match self.selected {
119-
Some(s) => Some(s),
120-
None => {
121-
self.list.offset = 0;
122-
Some(marked.len().saturating_sub(1))
123-
}
124-
};
125115
let selected = self.selected;
126116
let entries = marked
127117
.values()
@@ -180,10 +170,60 @@ impl MarkPane {
180170
vec![path, spacer, bytes]
181171
});
182172

173+
let entry_in_view = match self.selected {
174+
Some(s) => Some(s),
175+
None => {
176+
self.list.offset = 0;
177+
Some(marked.len().saturating_sub(1))
178+
}
179+
};
180+
let mut block = Block::default()
181+
.title(&title)
182+
.border_style(*border_style)
183+
.borders(Borders::ALL);
184+
185+
let inner_area = block.inner(area);
186+
block.draw(area, buf);
187+
188+
let (help_line_area, list_area) = {
189+
let regions = Layout::default()
190+
.direction(Direction::Vertical)
191+
.constraints([Constraint::Length(1), Constraint::Max(256)].as_ref())
192+
.split(inner_area);
193+
(regions[0], regions[1])
194+
};
195+
196+
let default_style = Style {
197+
fg: Color::Black,
198+
bg: Color::White,
199+
modifier: Modifier::BOLD,
200+
..Default::default()
201+
};
202+
Paragraph::new(
203+
[
204+
Text::Styled(
205+
" Ctrl + Shift + r".into(),
206+
Style {
207+
fg: Color::Red,
208+
..default_style
209+
},
210+
),
211+
Text::Styled(
212+
" permanently deletes list without prompt".into(),
213+
default_style,
214+
),
215+
]
216+
.iter(),
217+
)
218+
.style(Style {
219+
bg: Color::White,
220+
..Style::default()
221+
})
222+
.draw(help_line_area, buf);
183223
let props = ListProps {
184-
block: Some(block),
224+
block: None,
185225
entry_in_view,
186226
};
187-
self.list.render(props, entries, area, buf)
227+
self.list.render(props, entries, list_area, buf)
188228
}
189229
}

0 commit comments

Comments
 (0)