diff options
author | Helmut K. C. Tessarek <tessarek@evermeet.cx> | 2024-02-26 06:57:23 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-26 11:57:23 +0000 |
commit | 91ddcd60ca5e7d65c60367e28a47fb3a34606a49 (patch) | |
tree | 9499d441c00a3f27d7aea7b1b1592e06b1cb72fc | |
parent | cf09464d4d6afbe9383c5a93ed2b5c66ae69e4d5 (diff) |
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>
-rw-r--r-- | atuin/src/command/client/search/interactive.rs | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/atuin/src/command/client/search/interactive.rs b/atuin/src/command/client/search/interactive.rs index 1f3a2cff..8c6a672b 100644 --- a/atuin/src/command/client/search/interactive.rs +++ b/atuin/src/command/client/search/interactive.rs @@ -39,7 +39,7 @@ use ratatui::{ prelude::*, style::{Color, Modifier, Style}, text::{Line, Span, Text}, - widgets::{Block, BorderType, Borders, Paragraph, Tabs}, + widgets::{block::Title, Block, BorderType, Borders, Padding, Paragraph, Tabs}, Frame, Terminal, TerminalOptions, Viewport, }; @@ -580,12 +580,26 @@ impl State { } 1 => { - super::inspector::draw( - f, - results_list_chunk, - &results[self.results_state.selected()], - &stats.expect("Drawing inspector, but no stats"), - ); + if results.is_empty() { + let message = Paragraph::new("Nothing to inspect") + .block( + Block::new() + .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 // sub-widget for search + for inspector @@ -988,9 +1002,11 @@ pub async fn history( stats = if app.tab_index == 0 { None - } else { + } else if !results.is_empty() { let selected = results[app.results_state.selected()].clone(); Some(db.stats(&selected).await?) + } else { + None }; }; |