Skip to content

Commit

Permalink
fix crash when i is pressed while packets is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
pythops committed Sep 23, 2024
1 parent 7feca23 commit c2b6396
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
30 changes: 18 additions & 12 deletions oryx-tui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,28 +597,34 @@ impl App {
let packets_to_display = match self.manuall_scroll {
true => {
if fuzzy.is_enabled() & !fuzzy.filter.value().is_empty() {
let selected_packet_index = fuzzy.scroll_state.selected().unwrap();
if fuzzy_packets.len() > window_size {
self.packet_index = Some(
fuzzy.packet_end_index.saturating_sub(window_size)
+ selected_packet_index,
);
if let Some(selected_index) = fuzzy.scroll_state.selected() {
self.packet_index = Some(
fuzzy.packet_end_index.saturating_sub(window_size) + selected_index,
);
}
&fuzzy_packets[fuzzy.packet_end_index.saturating_sub(window_size)
..fuzzy.packet_end_index]
} else {
self.packet_index = Some(selected_packet_index);
if let Some(selected_index) = fuzzy.scroll_state.selected() {
self.packet_index = Some(selected_index);
} else {
self.packet_index = None;
}
&fuzzy_packets
}
} else if app_packets.len() > window_size {
let selected_packet_index = self.packets_table_state.selected().unwrap();
self.packet_index = Some(
self.packet_end_index.saturating_sub(window_size) + selected_packet_index,
);
if let Some(selected_index) = self.packets_table_state.selected() {
self.packet_index = Some(
self.packet_end_index.saturating_sub(window_size) + selected_index,
);
}
&app_packets
[self.packet_end_index.saturating_sub(window_size)..self.packet_end_index]
} else {
let selected_packet_index = self.packets_table_state.selected().unwrap();
self.packet_index = Some(selected_packet_index);
if let Some(selected_index) = self.packets_table_state.selected() {
self.packet_index = Some(selected_index);
}
&app_packets
}
}
Expand Down
10 changes: 10 additions & 0 deletions oryx-tui/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ pub fn handle_key_events(
if app.focused_block == FocusedBlock::Help || app.update_filters {
return Ok(());
}
if app.packet_index.is_none() || fuzzy.packets.is_empty() {
return Ok(());
}

app.show_packet_infos_popup = true;
}

Expand Down Expand Up @@ -482,6 +486,12 @@ pub fn handle_key_events(
if app.focused_block == FocusedBlock::Help || app.update_filters {
return Ok(());
}
let packets = app.packets.lock().unwrap();

if app.packet_index.is_none() || packets.is_empty() {
return Ok(());
}

app.show_packet_infos_popup = true;
}

Expand Down
8 changes: 5 additions & 3 deletions oryx-tui/src/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct Notification {

#[derive(Debug, Clone)]
pub enum NotificationLevel {
Alert,
Error,
Warning,
Info,
Expand All @@ -25,9 +26,10 @@ pub enum NotificationLevel {
impl Notification {
pub fn render(&self, index: usize, frame: &mut Frame) {
let (color, title) = match self.level {
NotificationLevel::Info => (Color::Green, "Info"),
NotificationLevel::Warning => (Color::Yellow, "Warning"),
NotificationLevel::Error => (Color::Red, "Error"),
NotificationLevel::Info => (Color::Green, "Infos 󰋼 "),
NotificationLevel::Warning => (Color::Yellow, "Warning  "),
NotificationLevel::Error => (Color::Red, "Error  "),
NotificationLevel::Alert => (Color::Red, "Alert  "),
};

let mut text = Text::from(vec![
Expand Down

0 comments on commit c2b6396

Please sign in to comment.