* feat(app): show confirm modal before exit add keyEvent handler function for exiting mode add Exiting variant to UiMode enum | add prompt_exit method implement ExitingMode widget rendering fix mixed UiState issue * resolved requested changes * feat(app) add confirm modal before exit fix panic in modals when terminal-width=50 listen for all possible keys when user tries to exit exit without confirmation in ScreenTooSmall mode fix tests to be compatible with ConfirmModal Changes * docs(readme): add gentoo installation info (#47) * feat(ux): make enter select largest folder if nothing is selected (#45) * Make enter select largest folder if nothing is selected * Rename method * Renamed and changed method to do what it originally said * Efficiency improvements * Added test for the feature * Run cargo insta review * Fixed len for assert_eq! * Fixed asserts at end of test * Run cargo insta review again * docs(changelog): enter largest folder * docs(readme): fix error in how it works * feat(ui): show quit shortcut ('q') in the legend (#46) * Add <q> shortcut in the legend * Fix typo for description * Use <arrows> instead of <hjkl> or <arrow keys> * Apply fmt * Merge main * feat(navigation): keep a stack of visited items and make go_up use it (#53) * Keep a stack up visited items and make go_up use it This will allow us to keep track of where our previous selections were so can can automatically select the parents when we go up in the hierarchy. Closes #48. Signed-off-by: Daniel Egger <daniel@eggers-club.de> * Redo snapshot tests to fix failures Signed-off-by: Daniel Egger <daniel@eggers-club.de> * style(naming): minor naming change for clarity Co-authored-by: Aram Drevekenin <aram@poor.dev> * fix(formatting): prevent crashes on files with multibyte characters (#51) * Fix crash when truncating to middle of a character * Fix alignment of file names with wide characters * Respect use ::formatting convention * docs(changelog): update recent changes * chore(release): 0.4.0 * fix enter_largest_folder_with_no_selected_tile test and its snapshot Co-authored-by: Aram Drevekenin <aram@poor.dev> Co-authored-by: telans <telans@protonmail.com> Co-authored-by: redzic <48274562+redzic@users.noreply.github.com> Co-authored-by: Oleh <45392385+olehs0@users.noreply.github.com> Co-authored-by: Daniel Egger <daniel@eggers-club.de> Co-authored-by: Renée Kooi <renee@kooi.me>
79 lines
2.4 KiB
Rust
79 lines
2.4 KiB
Rust
use ::tui::buffer::Buffer;
|
|
use ::tui::layout::Rect;
|
|
use ::tui::style::{Color, Modifier, Style};
|
|
use ::tui::widgets::Widget;
|
|
|
|
use crate::ui::format::truncate_end;
|
|
use crate::ui::grid::draw_filled_rect;
|
|
|
|
pub struct ErrorBox<'a> {
|
|
error_message: &'a str,
|
|
}
|
|
|
|
impl<'a> ErrorBox<'a> {
|
|
pub fn new(error_message: &'a str) -> Self {
|
|
Self { error_message }
|
|
}
|
|
}
|
|
|
|
impl<'a> Widget for ErrorBox<'a> {
|
|
fn render(self, area: Rect, buf: &mut Buffer) {
|
|
let (width, height) = if area.width > 150 {
|
|
(150, 10)
|
|
} else if area.width >= 50 {
|
|
(area.width / 2, 10)
|
|
} else {
|
|
unreachable!("app should not be rendered if window is so small")
|
|
};
|
|
|
|
// position self in the middle of the rect
|
|
let x = ((area.x + area.width) / 2) - width / 2;
|
|
let y = ((area.y + area.height) / 2) - height / 2;
|
|
|
|
let message_rect = Rect {
|
|
x,
|
|
y,
|
|
width,
|
|
height,
|
|
};
|
|
let fill_style = Style::default()
|
|
.bg(Color::Black)
|
|
.fg(Color::Red)
|
|
.modifier(Modifier::BOLD);
|
|
let text_max_length = message_rect.width - 4;
|
|
|
|
// here we truncate the end and not the middle because
|
|
// when dealing with error messages, the beginning tends
|
|
// to be the important part
|
|
let error_text = truncate_end(self.error_message, text_max_length);
|
|
let error_text_start_position =
|
|
((message_rect.width - error_text.chars().count() as u16) as f64 / 2.0).ceil() as u16
|
|
+ message_rect.x;
|
|
|
|
let controls_text = ["(Press <ESC> to dismiss)", "(<ESC> to dismiss)"];
|
|
|
|
draw_filled_rect(buf, fill_style, &message_rect);
|
|
buf.set_string(
|
|
error_text_start_position,
|
|
message_rect.y + message_rect.height / 2 - 2,
|
|
error_text,
|
|
fill_style,
|
|
);
|
|
|
|
for line in controls_text.iter() {
|
|
if text_max_length >= line.chars().count() as u16 {
|
|
let start_position =
|
|
((message_rect.width - line.chars().count() as u16) as f64 / 2.0).ceil() as u16
|
|
+ message_rect.x;
|
|
buf.set_string(
|
|
start_position,
|
|
message_rect.y + message_rect.height / 2 + 2,
|
|
line,
|
|
fill_style,
|
|
);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|