summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2024-11-01 22:07:28 +0100
committerqkzk <qu3nt1n@gmail.com>2024-11-01 22:07:28 +0100
commit6ee662baff5ffe7c8d861f2686cb0ca937170ceb (patch)
tree8126815ae64de6833bc32f7e20ca30af91913f20
parent9996323e2e48071b037292f28ed68df563cace4f (diff)
menu content line & trash clear with ratatui widgets
-rw-r--r--development.md4
-rw-r--r--src/io/display.rs70
-rw-r--r--src/modes/menu/permissions.rs2
3 files changed, 43 insertions, 33 deletions
diff --git a/development.md b/development.md
index 7a561335..e9ba7ae4 100644
--- a/development.md
+++ b/development.md
@@ -1480,6 +1480,10 @@ New view: Tree ! Toggle with 't', fold with 'z'. Navigate normally.
- [x] header & footer
- [x] create 2 ratatui line & use alignment for display
- [x] conversion method header/footer->line
+ - [x] menu second line
+ - [x] menu content line
+ - [x] trash clear confirm
+ - [ ] Layout::vertical 1, max, 1 for each window would simplify rect offset
- [x] FIX: opening shortcut twice crashes
- [ ] header should be a trait implemented by Header (-> FilesHeader), PreviewHeader, MenuHeader or event variants
- [ ] at this point I should list what it should do for every menu and rewrite it from scratch
diff --git a/src/io/display.rs b/src/io/display.rs
index eded9bc6..de25407a 100644
--- a/src/io/display.rs
+++ b/src/io/display.rs
@@ -1099,23 +1099,25 @@ impl<'a> Menu<'a> {
let first = MENU_STYLES.get().expect("Menu colors should be set").first;
self.menu_line_chmod(f, rect, first, menu);
}
- edit => rect.print_with_style(f, 1, 2, edit.second_line(), menu),
+ // edit => rect.print_with_style(f, 1, 2, edit.second_line(), menu),
+ edit => {
+ let rect = rect.offset(Offset { x: 2, y: 1 }).intersection(*rect);
+ Span::styled(edit.second_line(), menu).render(rect, f.buffer_mut());
+ }
};
}
fn menu_line_chmod(&self, f: &mut Frame, rect: &Rect, first: Style, menu: Style) {
let input = self.status.menu.input.string();
- let mode_parsed = parse_input_mode(&input);
- let mut col = 11;
- if mode_parsed.len() == 1 {
- rect.print_with_style(f, 1, col, mode_parsed[0].0, first);
- } else {
- for (text, is_valid) in &mode_parsed {
+ let spans: Vec<_> = parse_input_mode(&input)
+ .iter()
+ .map(|(text, is_valid)| {
let style = if *is_valid { first } else { menu };
- col += 1 + text.utf_width_u16();
- rect.print_with_style(f, 1, col, text, style);
- }
- }
+ Span::styled(*text, style)
+ })
+ .collect();
+ let p_rect = rect.offset(Offset { x: 11, y: 1 }).intersection(*rect);
+ Line::from(spans).render(p_rect, f.buffer_mut());
}
fn content_per_mode(&self, f: &mut Frame, rect: &Rect, mode: MenuMode) {
@@ -1129,21 +1131,20 @@ impl<'a> Menu<'a> {
}
fn binds_per_mode(&self, f: &mut Frame, rect: &Rect, mode: MenuMode) {
- // TODO remove
- // stupid hack to allow some help for the trash...
if mode == MenuMode::Navigate(Navigate::Trash) {
return;
}
- let height = rect.height;
-
- rect.clear_line(f, height.saturating_sub(2));
- rect.print_with_style(
- f,
- height.saturating_sub(2),
- 2,
+ let p_rect = rect
+ .offset(Offset {
+ x: 2,
+ y: rect.height.saturating_sub(2) as i32,
+ })
+ .intersection(*rect);
+ Span::styled(
mode.binds_per_mode(),
MENU_STYLES.get().expect("Menu colors should be set").second,
- );
+ )
+ .render(p_rect, f.buffer_mut());
}
fn static_lines(lines: &[&str], f: &mut Frame, rect: &Rect) {
@@ -1391,20 +1392,25 @@ impl<'a> Menu<'a> {
fn confirm_non_empty_trash(&self, f: &mut Frame, rect: &Rect) {
let content = self.status.menu.trash.content();
- for (row, trashinfo, style) in enumerated_colored_iter!(content) {
- let style = self.status.menu.trash.style(row, &style);
- Self::content_line(f, rect, row as u16 + 4, &trashinfo.to_string(), style);
- }
+ let lines: Vec<_> = enumerated_colored_iter!(content)
+ .map(|(_row, trashinfo, style)| {
+ Span::raw(trashinfo.to_string());
+ Line::from(vec![Span::styled(trashinfo.to_string(), style)])
+ })
+ .collect();
+ let mut p_rect = rect.offset(Offset { x: 4, y: 4 }).intersection(*rect);
+ p_rect.height -= 1;
+ Paragraph::new(lines).render(p_rect, f.buffer_mut());
}
fn content_line(f: &mut Frame, rect: &Rect, row: u16, text: &str, style: Style) {
- rect.print_with_style(
- f,
- row + ContentWindow::WINDOW_MARGIN_TOP_U16,
- 4,
- text,
- style,
- );
+ let p_rect = rect
+ .offset(Offset {
+ x: 4,
+ y: (row + ContentWindow::WINDOW_MARGIN_TOP_U16) as i32,
+ })
+ .intersection(*rect);
+ Span::styled(text, style).render(p_rect, f.buffer_mut());
}
}
diff --git a/src/modes/menu/permissions.rs b/src/modes/menu/permissions.rs
index 120daea5..54388125 100644
--- a/src/modes/menu/permissions.rs
+++ b/src/modes/menu/permissions.rs
@@ -58,7 +58,7 @@ type IsValid = bool;
/// It's used to display a valid mode or not.
pub fn parse_input_mode(mode_str: &str) -> Vec<(&str, IsValid)> {
if mode_str.chars().any(|c| c.is_alphabetic()) {
- return vec![("", true)];
+ return vec![];
}
if mode_str.len() > 3 {
return vec![("Mode is too long", false)];