fix(client): no panic on empty inspector (#1768)

* fix(client): no panic on empty inspector

* fix: clippy warning

Although I am not that happy with this clippy rule.
I am old school and we learned to put the most likely path first.
Back then compiler optimizations were not too great and cache prediction
was better handled this way.

* Update atuin/src/command/client/search/interactive.rs

---------

Co-authored-by: Ellie Huxtable <ellie@elliehuxtable.com>
This commit is contained in:
Helmut K. C. Tessarek 2024-02-26 06:57:23 -05:00 committed by GitHub
parent cf09464d4d
commit 91ddcd60ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -39,7 +39,7 @@ use ratatui::{
prelude::*, prelude::*,
style::{Color, Modifier, Style}, style::{Color, Modifier, Style},
text::{Line, Span, Text}, text::{Line, Span, Text},
widgets::{Block, BorderType, Borders, Paragraph, Tabs}, widgets::{block::Title, Block, BorderType, Borders, Padding, Paragraph, Tabs},
Frame, Terminal, TerminalOptions, Viewport, Frame, Terminal, TerminalOptions, Viewport,
}; };
@ -580,12 +580,26 @@ impl State {
} }
1 => { 1 => {
super::inspector::draw( if results.is_empty() {
f, let message = Paragraph::new("Nothing to inspect")
results_list_chunk, .block(
&results[self.results_state.selected()], Block::new()
&stats.expect("Drawing inspector, but no stats"), .title(
); Title::from(" Info ".to_string()).alignment(Alignment::Center),
)
.borders(Borders::ALL)
.padding(Padding::vertical(2)),
)
.alignment(Alignment::Center);
f.render_widget(message, results_list_chunk);
} else {
super::inspector::draw(
f,
results_list_chunk,
&results[self.results_state.selected()],
&stats.expect("Drawing inspector, but no stats"),
);
}
// HACK: I'm following up with abstracting this into the UI container, with a // HACK: I'm following up with abstracting this into the UI container, with a
// sub-widget for search + for inspector // sub-widget for search + for inspector
@ -988,9 +1002,11 @@ pub async fn history(
stats = if app.tab_index == 0 { stats = if app.tab_index == 0 {
None None
} else { } else if !results.is_empty() {
let selected = results[app.results_state.selected()].clone(); let selected = results[app.results_state.selected()].clone();
Some(db.stats(&selected).await?) Some(db.stats(&selected).await?)
} else {
None
}; };
}; };