From 5754d83247416f81a6be480329db6e48ce07220e Mon Sep 17 00:00:00 2001 From: pythops Date: Fri, 13 Sep 2024 18:54:16 +0200 Subject: [PATCH] update filters display order --- oryx-tui/src/app.rs | 25 +++---- oryx-tui/src/handler.rs | 145 ++++++++++++++++++++++++++-------------- 2 files changed, 106 insertions(+), 64 deletions(-) diff --git a/oryx-tui/src/app.rs b/oryx-tui/src/app.rs index e8c420f..e7c0d64 100644 --- a/oryx-tui/src/app.rs +++ b/oryx-tui/src/app.rs @@ -107,8 +107,8 @@ impl App { if !self.start_sniffing { let ( interface_block, - network_filter_block, transport_filter_block, + network_filter_block, link_filter_block, traffic_direction_block, start_block, @@ -117,8 +117,8 @@ impl App { .direction(Direction::Vertical) .constraints([ Constraint::Length(self.interface.interfaces.len() as u16 + 6), - Constraint::Length(NB_NETWORK_PROTOCOL + 4), Constraint::Length(NB_TRANSPORT_PROTOCOL + 4), + Constraint::Length(NB_NETWORK_PROTOCOL + 4), Constraint::Length(NB_LINK_PROTOCOL + 4), Constraint::Length(6), Constraint::Length(4), @@ -245,10 +245,10 @@ impl App { let widths = [Constraint::Length(10), Constraint::Fill(1)]; let filters = [ Row::new(vec![ - Line::styled("Network", Style::new().bold()), - Line::from_iter(NetworkFilter::default().selected_protocols.iter().map( + Line::styled("Transport", Style::new().bold()), + Line::from_iter(TransportFilter::default().selected_protocols.iter().map( |filter| { - if self.network_filter.applied_protocols.contains(filter) { + if self.transport_filter.applied_protocols.contains(filter) { Span::styled( format!(" {} ", filter), Style::default().light_green(), @@ -263,10 +263,10 @@ impl App { )), ]), Row::new(vec![ - Line::styled("Transport", Style::new().bold()), - Line::from_iter(TransportFilter::default().selected_protocols.iter().map( + Line::styled("Network", Style::new().bold()), + Line::from_iter(NetworkFilter::default().selected_protocols.iter().map( |filter| { - if self.transport_filter.applied_protocols.contains(filter) { + if self.network_filter.applied_protocols.contains(filter) { Span::styled( format!(" {} ", filter), Style::default().light_green(), @@ -370,8 +370,8 @@ impl App { .split(layout[1])[1]; let ( - network_filter_block, transport_filter_block, + network_filter_block, link_filter_block, traffic_direction_block, apply_block, @@ -379,8 +379,8 @@ impl App { let chunks = Layout::default() .direction(Direction::Vertical) .constraints([ - Constraint::Length(NB_NETWORK_PROTOCOL + 4), Constraint::Length(NB_TRANSPORT_PROTOCOL + 4), + Constraint::Length(NB_NETWORK_PROTOCOL + 4), Constraint::Length(NB_LINK_PROTOCOL + 4), Constraint::Length(6), Constraint::Length(4), @@ -399,12 +399,13 @@ impl App { .border_style(Style::default().green()), block, ); - self.network_filter - .render(frame, network_filter_block, &self.focused_block); self.transport_filter .render(frame, transport_filter_block, &self.focused_block); + self.network_filter + .render(frame, network_filter_block, &self.focused_block); + self.link_filter .render(frame, link_filter_block, &self.focused_block); diff --git a/oryx-tui/src/handler.rs b/oryx-tui/src/handler.rs index a100d3d..9af8709 100644 --- a/oryx-tui/src/handler.rs +++ b/oryx-tui/src/handler.rs @@ -58,16 +58,16 @@ pub fn handle_key_events( if app.update_filters { match &app.focused_block { - FocusedBlock::NetworkFilter => { - app.focused_block = FocusedBlock::TransportFilter; + FocusedBlock::TransportFilter => { + app.focused_block = FocusedBlock::NetworkFilter; + app.network_filter.state.select(Some(0)); app.transport_filter.state.select(Some(0)); - app.network_filter.state.select(None); } - FocusedBlock::TransportFilter => { + FocusedBlock::NetworkFilter => { app.focused_block = FocusedBlock::LinkFilter; - app.traffic_direction_filter.state.select(None); app.link_filter.state.select(Some(0)); + app.network_filter.state.select(None); } FocusedBlock::LinkFilter => { @@ -82,8 +82,7 @@ pub fn handle_key_events( } FocusedBlock::Start => { - app.focused_block = FocusedBlock::NetworkFilter; - app.network_filter.state.select(Some(0)); + app.focused_block = FocusedBlock::TransportFilter; } _ => {} }; @@ -105,20 +104,20 @@ pub fn handle_key_events( if app.update_filters { match &app.focused_block { - FocusedBlock::NetworkFilter => { - app.focused_block = FocusedBlock::Start; - app.network_filter.state.select(None); - } - FocusedBlock::TransportFilter => { - app.focused_block = FocusedBlock::NetworkFilter; - app.network_filter.state.select(Some(0)); + app.focused_block = FocusedBlock::Start; app.transport_filter.state.select(None); } - FocusedBlock::LinkFilter => { + FocusedBlock::NetworkFilter => { app.focused_block = FocusedBlock::TransportFilter; app.transport_filter.state.select(Some(0)); + app.network_filter.state.select(None); + } + + FocusedBlock::LinkFilter => { + app.focused_block = FocusedBlock::NetworkFilter; + app.network_filter.state.select(Some(0)); app.link_filter.state.select(None); } @@ -161,14 +160,21 @@ pub fn handle_key_events( KeyCode::Char('f') => { if app.focused_block != FocusedBlock::Help && app.start_sniffing { app.update_filters = true; - app.focused_block = FocusedBlock::NetworkFilter; + app.focused_block = FocusedBlock::TransportFilter; + app.network_filter.selected_protocols = app.network_filter.applied_protocols.clone(); + app.transport_filter.selected_protocols = app.transport_filter.applied_protocols.clone(); + + app.link_filter.selected_protocols = + app.link_filter.applied_protocols.clone(); + app.traffic_direction_filter.selected_direction = app.traffic_direction_filter.applied_direction.clone(); - app.network_filter.state = TableState::default().with_selected(0); + + app.transport_filter.state = TableState::default().with_selected(0); } } @@ -229,6 +235,21 @@ pub fn handle_key_events( app.transport_filter.state.select(Some(i)); } + FocusedBlock::LinkFilter => { + let i = match app.link_filter.state.selected() { + Some(i) => { + if i < (NB_LINK_PROTOCOL - 1).into() { + i + 1 + } else { + i + } + } + None => 0, + }; + + app.link_filter.state.select(Some(i)); + } + FocusedBlock::TrafficDirection => { app.traffic_direction_filter.state.select(Some(1)); } @@ -294,6 +315,21 @@ pub fn handle_key_events( app.transport_filter.state.select(Some(i)); } + FocusedBlock::LinkFilter => { + let i = match app.link_filter.state.selected() { + Some(i) => { + if i > 1 { + i - 1 + } else { + 0 + } + } + None => 0, + }; + + app.link_filter.state.select(Some(i)); + } + FocusedBlock::TrafficDirection => { app.traffic_direction_filter.state.select(Some(0)); } @@ -364,7 +400,7 @@ pub fn handle_key_events( if app.focused_block != FocusedBlock::Help && app.start_sniffing { app.update_filters = true; - app.focused_block = FocusedBlock::NetworkFilter; + app.focused_block = FocusedBlock::TransportFilter; app.network_filter.selected_protocols = app.network_filter.applied_protocols.clone(); @@ -377,7 +413,7 @@ pub fn handle_key_events( app.traffic_direction_filter.selected_direction = app.traffic_direction_filter.applied_direction.clone(); - app.network_filter.state = TableState::default().with_selected(0); + app.transport_filter.state = TableState::default().with_selected(0); } } @@ -474,7 +510,7 @@ pub fn handle_key_events( } app.start_sniffing = true; - app.focused_block = FocusedBlock::NetworkFilter; + app.focused_block = FocusedBlock::TransportFilter; } else if app.start_sniffing && app.update_filters { // Remove egress if app @@ -566,16 +602,18 @@ pub fn handle_key_events( if app.update_filters { match &app.focused_block { - FocusedBlock::NetworkFilter => { - app.focused_block = FocusedBlock::TransportFilter; - app.transport_filter.state.select(Some(0)); - app.network_filter.state.select(None); - } FocusedBlock::TransportFilter => { + app.focused_block = FocusedBlock::NetworkFilter; + app.network_filter.state.select(Some(0)); + app.transport_filter.state.select(None); + } + + FocusedBlock::NetworkFilter => { app.focused_block = FocusedBlock::LinkFilter; app.link_filter.state.select(Some(0)); - app.transport_filter.state.select(None); + app.network_filter.state.select(None); } + FocusedBlock::LinkFilter => { app.focused_block = FocusedBlock::TrafficDirection; app.traffic_direction_filter.state.select(Some(0)); @@ -588,8 +626,8 @@ pub fn handle_key_events( } FocusedBlock::Start => { - app.focused_block = FocusedBlock::NetworkFilter; - app.network_filter.state.select(Some(0)); + app.focused_block = FocusedBlock::TransportFilter; + app.transport_filter.state.select(Some(0)); } _ => {} }; @@ -604,23 +642,26 @@ pub fn handle_key_events( } else { match &app.focused_block { FocusedBlock::Interface => { - app.focused_block = FocusedBlock::NetworkFilter; - app.previous_focused_block = app.focused_block; - app.interface.state.select(None); - app.network_filter.state.select(Some(0)); - } - FocusedBlock::NetworkFilter => { app.focused_block = FocusedBlock::TransportFilter; app.previous_focused_block = app.focused_block; + app.interface.state.select(None); app.transport_filter.state.select(Some(0)); - app.network_filter.state.select(None); } + FocusedBlock::TransportFilter => { + app.focused_block = FocusedBlock::NetworkFilter; + app.previous_focused_block = app.focused_block; + app.network_filter.state.select(Some(0)); + app.transport_filter.state.select(None); + } + + FocusedBlock::NetworkFilter => { app.focused_block = FocusedBlock::LinkFilter; app.previous_focused_block = app.focused_block; app.link_filter.state.select(Some(0)); - app.transport_filter.state.select(None); + app.network_filter.state.select(None); } + FocusedBlock::LinkFilter => { app.focused_block = FocusedBlock::TrafficDirection; app.previous_focused_block = app.focused_block; @@ -652,20 +693,20 @@ pub fn handle_key_events( if app.update_filters { match &app.focused_block { - FocusedBlock::NetworkFilter => { - app.focused_block = FocusedBlock::Start; - app.network_filter.state.select(None); - } - FocusedBlock::TransportFilter => { - app.focused_block = FocusedBlock::NetworkFilter; - app.network_filter.state.select(Some(0)); + app.focused_block = FocusedBlock::Start; app.transport_filter.state.select(None); } - FocusedBlock::LinkFilter => { + FocusedBlock::NetworkFilter => { app.focused_block = FocusedBlock::TransportFilter; app.transport_filter.state.select(Some(0)); + app.network_filter.state.select(None); + } + + FocusedBlock::LinkFilter => { + app.focused_block = FocusedBlock::NetworkFilter; + app.network_filter.state.select(Some(0)); app.link_filter.state.select(None); } @@ -695,21 +736,21 @@ pub fn handle_key_events( app.interface.state.select(None); } - FocusedBlock::NetworkFilter => { + FocusedBlock::TransportFilter => { app.focused_block = FocusedBlock::Interface; app.interface.state.select(Some(0)); - app.network_filter.state.select(None); - } - - FocusedBlock::TransportFilter => { - app.focused_block = FocusedBlock::NetworkFilter; - app.network_filter.state.select(Some(0)); app.transport_filter.state.select(None); } - FocusedBlock::LinkFilter => { + FocusedBlock::NetworkFilter => { app.focused_block = FocusedBlock::TransportFilter; app.transport_filter.state.select(Some(0)); + app.network_filter.state.select(None); + } + + FocusedBlock::LinkFilter => { + app.focused_block = FocusedBlock::NetworkFilter; + app.network_filter.state.select(Some(0)); app.link_filter.state.select(None); }