From fe3133a3116e84c13c6cc742f593f4e3c65e05fc Mon Sep 17 00:00:00 2001 From: adrien gaultier Date: Sun, 29 Sep 2024 13:06:55 +0200 Subject: [PATCH] fix --- oryx-tui/Cargo.toml | 1 - oryx-tui/src/app_.rs | 0 oryx-tui/src/filters/start_menu.rs | 60 +- oryx-tui/src/filters/update_menu.rs | 46 +- oryx-tui/src/handler.rs | 877 ---------------------------- oryx-tui/src/lib.rs | 2 + oryx-tui/src/mode.rs | 6 +- oryx-tui/src/ui.rs | 6 +- 8 files changed, 56 insertions(+), 942 deletions(-) create mode 100644 oryx-tui/src/app_.rs diff --git a/oryx-tui/Cargo.toml b/oryx-tui/Cargo.toml index 0c97533..7f38d0f 100644 --- a/oryx-tui/Cargo.toml +++ b/oryx-tui/Cargo.toml @@ -24,7 +24,6 @@ kanal = "0.1.0-pre8" mimalloc = "0.1" clap = { version = "4", features = ["derive", "cargo"] } network-types = "0.0.7" - [[bin]] name = "oryx" path = "src/main.rs" diff --git a/oryx-tui/src/app_.rs b/oryx-tui/src/app_.rs new file mode 100644 index 0000000..e69de29 diff --git a/oryx-tui/src/filters/start_menu.rs b/oryx-tui/src/filters/start_menu.rs index e18b098..9483573 100644 --- a/oryx-tui/src/filters/start_menu.rs +++ b/oryx-tui/src/filters/start_menu.rs @@ -1,4 +1,4 @@ -use crate::app::App; +use crate::app::{App, FocusedBlock}; use crossterm::event::{KeyCode, KeyEvent}; use ratatui::prelude::Stylize; use ratatui::{ @@ -20,9 +20,9 @@ pub enum StartMenuBlock { } impl StartMenuBlock { - pub fn next(&mut self, app: &mut App) { - self.unselect(app); - *self = match self { + pub fn next(self, app: &mut App) { + self.on_unselect(app); + let x = match self { StartMenuBlock::Interface => StartMenuBlock::TransportFilter, StartMenuBlock::TransportFilter => StartMenuBlock::NetworkFilter, StartMenuBlock::NetworkFilter => StartMenuBlock::LinkFilter, @@ -30,8 +30,23 @@ impl StartMenuBlock { StartMenuBlock::TrafficDirection => StartMenuBlock::Start, StartMenuBlock::Start => StartMenuBlock::Interface, }; - self.select(app); + app.focused_block = FocusedBlock::StartMenuBlock(x); + x.on_select(app) } + pub fn previous(self, app: &mut App) { + self.on_unselect(app); + let x = match self { + StartMenuBlock::Interface => StartMenuBlock::Start, + StartMenuBlock::TransportFilter => StartMenuBlock::Interface, + StartMenuBlock::NetworkFilter => StartMenuBlock::TransportFilter, + StartMenuBlock::LinkFilter => StartMenuBlock::NetworkFilter, + StartMenuBlock::TrafficDirection => StartMenuBlock::LinkFilter, + StartMenuBlock::Start => StartMenuBlock::TrafficDirection, + }; + app.focused_block = FocusedBlock::StartMenuBlock(x); + x.on_select(app) + } + pub fn app_component(self, app: &mut App) -> Option<&mut TableState> { match self { StartMenuBlock::Interface => Some(&mut app.interface.state), @@ -42,20 +57,8 @@ impl StartMenuBlock { StartMenuBlock::Start => None, } } - pub fn previous(&mut self, app: &mut App) { - self.unselect(app); - *self = match self { - StartMenuBlock::Interface => StartMenuBlock::Start, - StartMenuBlock::TransportFilter => StartMenuBlock::Interface, - StartMenuBlock::NetworkFilter => StartMenuBlock::TransportFilter, - StartMenuBlock::LinkFilter => StartMenuBlock::NetworkFilter, - StartMenuBlock::TrafficDirection => StartMenuBlock::LinkFilter, - StartMenuBlock::Start => StartMenuBlock::TrafficDirection, - }; - self.select(app); - } - fn select(self, app: &mut App) { + fn on_select(self, app: &mut App) { match self.app_component(app) { Some(p) => { p.select(Some(0)); @@ -63,7 +66,7 @@ impl StartMenuBlock { None => {} } } - fn unselect(self, app: &mut App) { + fn on_unselect(self, app: &mut App) { match self.app_component(app) { Some(p) => { p.select(None); @@ -98,18 +101,13 @@ impl StartMenuBlock { } pub fn handle_key_events(&mut self, key_event: KeyEvent, app: &mut App) { match key_event.code { - KeyCode::Tab => { - self.next(app); - } - KeyCode::BackTab => { - self.previous(app); - } - KeyCode::Char('k') | KeyCode::Up => { - self.scroll_up(app); - } - KeyCode::Char('j') | KeyCode::Down => { - self.scroll_down(app); - } + KeyCode::Tab => self.next(app), + KeyCode::BackTab => self.previous(app), + + KeyCode::Char('k') | KeyCode::Up => self.scroll_up(app), + + KeyCode::Char('j') | KeyCode::Down => self.scroll_down(app), + _ => {} } } diff --git a/oryx-tui/src/filters/update_menu.rs b/oryx-tui/src/filters/update_menu.rs index 6ed59f6..04e40ab 100644 --- a/oryx-tui/src/filters/update_menu.rs +++ b/oryx-tui/src/filters/update_menu.rs @@ -8,7 +8,7 @@ use ratatui::{ }; use tui_big_text::{BigText, PixelSize}; -use crate::app::App; +use crate::app::{App, FocusedBlock}; #[derive(Debug, Copy, Clone, PartialEq)] pub enum UpdateFilterMenuBlock { @@ -20,16 +20,17 @@ pub enum UpdateFilterMenuBlock { } impl UpdateFilterMenuBlock { - pub fn next(&mut self, app: &mut App) { - self.unselect(app); - *self = match self { + pub fn next(self, app: &mut App) { + self.on_unselect(app); + let x = match self { UpdateFilterMenuBlock::TransportFilter => UpdateFilterMenuBlock::NetworkFilter, UpdateFilterMenuBlock::NetworkFilter => UpdateFilterMenuBlock::LinkFilter, UpdateFilterMenuBlock::LinkFilter => UpdateFilterMenuBlock::TrafficDirection, UpdateFilterMenuBlock::TrafficDirection => UpdateFilterMenuBlock::Start, UpdateFilterMenuBlock::Start => UpdateFilterMenuBlock::TransportFilter, }; - self.select(app); + app.focused_block = FocusedBlock::UpdateFilterMenuBlock(x); + x.on_select(app) } pub fn app_component(self, app: &mut App) -> Option<&mut TableState> { match self { @@ -42,19 +43,20 @@ impl UpdateFilterMenuBlock { UpdateFilterMenuBlock::Start => None, } } - pub fn previous(&mut self, app: &mut App) { - self.unselect(app); - *self = match self { + pub fn previous(self, app: &mut App) { + self.on_unselect(app); + let x = match self { UpdateFilterMenuBlock::TransportFilter => UpdateFilterMenuBlock::Start, UpdateFilterMenuBlock::NetworkFilter => UpdateFilterMenuBlock::TransportFilter, UpdateFilterMenuBlock::LinkFilter => UpdateFilterMenuBlock::NetworkFilter, UpdateFilterMenuBlock::TrafficDirection => UpdateFilterMenuBlock::LinkFilter, UpdateFilterMenuBlock::Start => UpdateFilterMenuBlock::TrafficDirection, }; - self.select(app); + app.focused_block = FocusedBlock::UpdateFilterMenuBlock(x); + x.on_select(app) } - pub fn select(self, app: &mut App) { + pub fn on_select(self, app: &mut App) { match self.app_component(app) { Some(p) => { p.select(Some(0)); @@ -62,7 +64,7 @@ impl UpdateFilterMenuBlock { None => {} } } - fn unselect(self, app: &mut App) { + fn on_unselect(self, app: &mut App) { match self.app_component(app) { Some(p) => { p.select(None); @@ -95,23 +97,13 @@ impl UpdateFilterMenuBlock { } pub fn handle_key_events(&mut self, key_event: KeyEvent, app: &mut App) { match key_event.code { - KeyCode::Tab => { - self.next(app); - } - KeyCode::BackTab => { - self.previous(app); - } - KeyCode::Char('k') | KeyCode::Up => { - self.scroll_up(app); - } - KeyCode::Char('j') | KeyCode::Down => { - self.scroll_down(app); - } + KeyCode::Tab => self.next(app), + KeyCode::BackTab => self.previous(app), + + KeyCode::Char('k') | KeyCode::Up => self.scroll_up(app), + + KeyCode::Char('j') | KeyCode::Down => self.scroll_down(app), - KeyCode::Esc => { - app.focused_block = app.previous_focused_block.clone(); - app.update_filters = false; - } _ => {} } } diff --git a/oryx-tui/src/handler.rs b/oryx-tui/src/handler.rs index 712a473..124658d 100644 --- a/oryx-tui/src/handler.rs +++ b/oryx-tui/src/handler.rs @@ -57,880 +57,3 @@ pub fn handle_key_events( } return Ok(()); } - -// /////////////////////// -// // old -// pub fn old_handle_key_events( -// key_event: KeyEvent, -// app: &mut App, -// sender: kanal::Sender, -// ) -> AppResult<()> { -// // if app.show_packet_infos_popup { -// // if key_event.code == KeyCode::Esc { -// // app.show_packet_infos_popup = false; -// // } - -// // return Ok(()); -// // } - -// // let fuzzy = app.fuzzy.clone(); -// // let mut fuzzy = fuzzy.lock().unwrap(); - -// // if fuzzy.is_enabled() { -// // match key_event.code { -// // KeyCode::Esc => { -// // // if app.focused_block == FocusedBlock::Help { -// // // app.focused_block = FocusedBlock::Main; -// // // return Ok(()); -// // // } - -// // if app.update_filters { -// // app.update_filters = false; -// // return Ok(()); -// // } - -// // if fuzzy.is_paused() { -// // if app.manuall_scroll { -// // app.manuall_scroll = false; -// // } else { -// // fuzzy.disable(); -// // } -// // } else { -// // fuzzy.pause(); -// // } -// // } - -// _ => { -// if app.focused_block == FocusedBlock::Help { -// return Ok(()); -// } -// // if !fuzzy.is_paused() && !app.update_filters { -// // fuzzy -// // .filter -// // .handle_event(&crossterm::event::Event::Key(key_event)); -// } else { -// match key_event.code { -// KeyCode::Char('/') => { -// if !app.update_filters { -// fuzzy.unpause(); -// } -// } - -// // KeyCode::Char('?') => { -// // app.focused_block = FocusedBlock::Help; -// // } - -// // KeyCode::Char('i') => { -// // 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; -// // } -// KeyCode::Char('f') => { -// if app.focused_block != FocusedBlock::Help -// && app.start_sniffing -// && !app.update_filters -// { -// app.update_filters = true; -// app.focused_block = FocusedBlock::TransportFilter; - -// app.filter.network.selected_protocols = -// app.filter.network.applied_protocols.clone(); - -// app.filter.transport.selected_protocols = -// app.filter.transport.applied_protocols.clone(); - -// app.filter.link.selected_protocols = -// app.filter.link.applied_protocols.clone(); - -// app.filter.traffic_direction.selected_direction = -// app.filter.traffic_direction.applied_direction.clone(); - -// app.filter.transport.state = TableState::default().with_selected(0); -// } -// } - -// KeyCode::Char('j') | KeyCode::Down => { -// if !app.update_filters { -// // if !app.manuall_scroll { -// // app.manuall_scroll = true; -// // // Record the last position. Usefull for selecting the packets to display -// // fuzzy.packet_end_index = fuzzy.packets.len(); -// // } -// // let i = match fuzzy.scroll_state.selected() { -// // Some(i) => { -// // if i < app.packet_window_size - 1 { -// // i + 1 -// // } else if i == app.packet_window_size - 1 -// // && fuzzy.packets.len() > fuzzy.packet_end_index -// // { -// // // shit the window by one -// // fuzzy.packet_end_index += 1; -// // i + 1 -// // } else { -// // i -// // } -// // } -// // None => fuzzy.packets.len(), -// // }; - -// // fuzzy.scroll_state.select(Some(i)); -// } else { -// match &app.focused_block { -// // FocusedBlock::NetworkFilter => { -// // app.filter.network.scroll_down(); -// // } - -// // FocusedBlock::TransportFilter => { -// // app.filter.transport.scroll_down(); -// // } - -// // FocusedBlock::LinkFilter => { -// // app.filter.link.scroll_down(); -// // } - -// // FocusedBlock::TrafficDirection => { -// // app.filter.traffic_direction.state.select(Some(1)); -// // } -// _ => {} -// }; -// } -// } -// KeyCode::Char('k') | KeyCode::Up => { -// if !app.update_filters { -// // if !app.manuall_scroll { -// // app.manuall_scroll = true; -// // // Record the last position. Usefull for selecting the packets to display -// // fuzzy.packet_end_index = fuzzy.packets.len(); -// // } -// // let i = match fuzzy.scroll_state.selected() { -// // Some(i) => { -// // if i > 1 { -// // i - 1 -// // } else if i == 0 -// // && fuzzy.packet_end_index > app.packet_window_size -// // { -// // // shit the window by one -// // fuzzy.packet_end_index -= 1; -// // 0 -// // } else { -// // 0 -// // } -// // } -// // None => fuzzy.packets.len(), -// // }; - -// // fuzzy.scroll_state.select(Some(i)); -// } else { -// // match &app.focused_block { -// // FocusedBlock::NetworkFilter => { -// // app.filter.network.scroll_up(); -// // } - -// // FocusedBlock::TransportFilter => { -// // app.filter.transport.scroll_up(); -// // } - -// // FocusedBlock::LinkFilter => { -// // app.filter.link.scroll_up(); -// // } - -// // FocusedBlock::TrafficDirection => { -// // app.filter.traffic_direction.state.select(Some(0)); -// // } - -// // FocusedBlock::Help => { -// // app.help.scroll_up(); -// // } -// // _ => {} -// } -// } -// } - -// _ => {} -// } -// } -// } -// } -// } else { -// match key_event.code { -// // KeyCode::Char('q') => { -// // app.filter -// // .traffic_direction -// // .terminate(TrafficDirection::Egress); -// // app.filter -// // .traffic_direction -// // .terminate(TrafficDirection::Ingress); -// // thread::sleep(Duration::from_millis(110)); -// // app.quit(); -// // } - -// // KeyCode::Char('c') | KeyCode::Char('C') => { -// // if key_event.modifiers == KeyModifiers::CONTROL { -// // app.filter -// // .traffic_direction -// // .terminate(TrafficDirection::Egress); -// // app.filter -// // .traffic_direction -// // .terminate(TrafficDirection::Ingress); -// // thread::sleep(Duration::from_millis(110)); -// // app.quit(); -// // } -// // } -// KeyCode::Esc => { -// if app.focused_block == FocusedBlock::Help { -// if app.start_sniffing { -// app.focused_block = FocusedBlock::Main -// } else { -// app.focused_block = app.previous_focused_block; -// } -// return Ok(()); -// } - -// if app.update_filters { -// app.update_filters = false; -// return Ok(()); -// } - -// if app.manuall_scroll { -// app.manuall_scroll = false; -// } -// } - -// // KeyCode::Char('?') => { -// // app.focused_block = FocusedBlock::Help; -// // } -// KeyCode::Char('f') => { -// if app.focused_block != FocusedBlock::Help -// && app.start_sniffing -// && !app.update_filters -// { -// app.update_filters = true; - -// app.focused_block = FocusedBlock::TransportFilter; - -// app.filter.network.selected_protocols = -// app.filter.network.applied_protocols.clone(); - -// app.filter.transport.selected_protocols = -// app.filter.transport.applied_protocols.clone(); - -// app.filter.link.selected_protocols = app.filter.link.applied_protocols.clone(); - -// app.filter.traffic_direction.selected_direction = -// app.filter.traffic_direction.applied_direction.clone(); - -// app.filter.transport.state = TableState::default().with_selected(0); -// } -// } - -// KeyCode::Char('s') => { -// if app.focused_block == FocusedBlock::Help || app.update_filters { -// return Ok(()); -// } - -// if app.start_sniffing { -// let app_packets = app.packets.lock().unwrap(); -// if app_packets.is_empty() { -// Notification::send( -// "There is no packets".to_string(), -// NotificationLevel::Info, -// sender, -// )?; -// } else { -// match export(&app_packets) { -// Ok(_) => { -// Notification::send( -// "Packets exported to ~/oryx/capture file".to_string(), -// NotificationLevel::Info, -// sender, -// )?; -// } -// Err(e) => { -// Notification::send( -// e.to_string(), -// NotificationLevel::Error, -// sender, -// )?; -// } -// } -// } -// } -// } - -// // KeyCode::Char('/') => { -// // if app.focused_block == FocusedBlock::Help || app.update_filters { -// // return Ok(()); -// // } -// // if app.start_sniffing { -// // fuzzy.enable(); -// // fuzzy.unpause(); -// // } -// // } -// // KeyCode::Char('i') => { -// // 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; -// // } -// // KeyCode::Char('r') => { -// // if app.focused_block == FocusedBlock::Help || app.update_filters { -// // return Ok(()); -// // } -// // if key_event.modifiers == KeyModifiers::CONTROL { -// // app.detach_interfaces(); -// // sender.send(Event::Reset)?; -// // } -// // } - -// KeyCode::Enter => { -// if app.focused_block == FocusedBlock::Start && !app.start_sniffing { -// let iface = app.interface.selected_interface.name.clone(); - -// app.filter.network.apply(); -// app.filter.transport.apply(); -// app.filter.link.apply(); -// app.filter.traffic_direction.apply(); - -// if app -// .filter -// .traffic_direction -// .applied_direction -// .contains(&TrafficDirection::Ingress) -// { -// Ebpf::load_ingress( -// iface.clone(), -// sender.clone(), -// app.data_channel_sender.clone(), -// app.filter.ingress_channel.receiver.clone(), -// app.filter.traffic_direction.terminate_ingress.clone(), -// ); -// } - -// if app -// .filter -// .traffic_direction -// .applied_direction -// .contains(&TrafficDirection::Egress) -// { -// Ebpf::load_egress( -// iface, -// sender.clone(), -// app.data_channel_sender.clone(), -// app.filter.egress_channel.receiver.clone(), -// app.filter.traffic_direction.terminate_egress.clone(), -// ); -// } - -// app.start_sniffing = true; -// app.focused_block = FocusedBlock::TransportFilter; -// } else if app.start_sniffing && app.update_filters { -// // Remove egress -// if app -// .filter -// .traffic_direction -// .applied_direction -// .contains(&TrafficDirection::Egress) -// && !app -// .filter -// .traffic_direction -// .selected_direction -// .contains(&TrafficDirection::Egress) -// { -// app.filter -// .traffic_direction -// .terminate(TrafficDirection::Egress); -// } - -// // Add egress -// if !app -// .filter -// .traffic_direction -// .applied_direction -// .contains(&TrafficDirection::Egress) -// && app -// .filter -// .traffic_direction -// .selected_direction -// .contains(&TrafficDirection::Egress) -// { -// app.filter -// .traffic_direction -// .terminate_egress -// .store(false, std::sync::atomic::Ordering::Relaxed); -// let iface = app.interface.selected_interface.name.clone(); -// Ebpf::load_egress( -// iface, -// sender.clone(), -// app.data_channel_sender.clone(), -// app.filter.egress_channel.receiver.clone(), -// app.filter.traffic_direction.terminate_egress.clone(), -// ); -// } - -// // Remove ingress -// if app -// .filter -// .traffic_direction -// .applied_direction -// .contains(&TrafficDirection::Ingress) -// && !app -// .filter -// .traffic_direction -// .selected_direction -// .contains(&TrafficDirection::Ingress) -// { -// app.filter -// .traffic_direction -// .terminate(TrafficDirection::Ingress); -// } - -// // Add ingress -// if !app -// .filter -// .traffic_direction -// .applied_direction -// .contains(&TrafficDirection::Ingress) -// && app -// .filter -// .traffic_direction -// .selected_direction -// .contains(&TrafficDirection::Ingress) -// { -// let iface = app.interface.selected_interface.name.clone(); -// app.filter -// .traffic_direction -// .terminate_ingress -// .store(false, std::sync::atomic::Ordering::Relaxed); -// Ebpf::load_ingress( -// iface, -// sender.clone(), -// app.data_channel_sender.clone(), -// app.filter.ingress_channel.receiver.clone(), -// app.filter.traffic_direction.terminate_ingress.clone(), -// ); -// } -// app.filter.network.apply(); -// app.filter.transport.apply(); -// app.filter.link.apply(); -// app.filter.traffic_direction.apply(); - -// thread::sleep(Duration::from_millis(150)); -// app.filter -// .traffic_direction -// .terminate_ingress -// .store(false, std::sync::atomic::Ordering::Relaxed); -// app.filter -// .traffic_direction -// .terminate_ingress -// .store(false, std::sync::atomic::Ordering::Relaxed); - -// app.update_filters = false; -// } - -// for protocol in TransportProtocol::all().iter() { -// if app.filter.transport.applied_protocols.contains(protocol) { -// app.filter -// .ingress_channel -// .sender -// .send((Protocol::Transport(*protocol), false))?; -// app.filter -// .egress_channel -// .sender -// .send((Protocol::Transport(*protocol), false))?; -// } else { -// app.filter -// .ingress_channel -// .sender -// .send((Protocol::Transport(*protocol), true))?; -// app.filter -// .egress_channel -// .sender -// .send((Protocol::Transport(*protocol), true))?; -// } -// } - -// for protocol in NetworkProtocol::all().iter() { -// if app.filter.network.applied_protocols.contains(protocol) { -// app.filter -// .ingress_channel -// .sender -// .send((Protocol::Network(*protocol), false))?; -// app.filter -// .egress_channel -// .sender -// .send((Protocol::Network(*protocol), false))?; -// } else { -// app.filter -// .ingress_channel -// .sender -// .send((Protocol::Network(*protocol), true))?; -// app.filter -// .egress_channel -// .sender -// .send((Protocol::Network(*protocol), true))?; -// } -// } - -// for protocol in LinkProtocol::all().iter() { -// if app.filter.link.applied_protocols.contains(protocol) { -// app.filter -// .ingress_channel -// .sender -// .send((Protocol::Link(*protocol), false))?; -// app.filter -// .egress_channel -// .sender -// .send((Protocol::Link(*protocol), false))?; -// } else { -// app.filter -// .ingress_channel -// .sender -// .send((Protocol::Link(*protocol), true))?; -// app.filter -// .egress_channel -// .sender -// .send((Protocol::Link(*protocol), true))?; -// } -// } -// } - -// // KeyCode::Tab => { -// // if app.start_sniffing { -// // if app.focused_block == FocusedBlock::Help { -// // return Ok(()); -// // } - -// // if app.update_filters { -// // match &app.focused_block { -// // FocusedBlock::TransportFilter => { -// // app.focused_block = FocusedBlock::NetworkFilter; -// // app.filter.network.state.select(Some(0)); -// // app.filter.transport.state.select(None); -// // } - -// // FocusedBlock::NetworkFilter => { -// // app.focused_block = FocusedBlock::LinkFilter; -// // app.filter.link.state.select(Some(0)); -// // app.filter.network.state.select(None); -// // } - -// // FocusedBlock::LinkFilter => { -// // app.focused_block = FocusedBlock::TrafficDirection; -// // app.filter.traffic_direction.state.select(Some(0)); -// // app.filter.link.state.select(None); -// // } - -// // FocusedBlock::TrafficDirection => { -// // app.focused_block = FocusedBlock::Start; -// // app.filter.traffic_direction.state.select(None); -// // } - -// // FocusedBlock::Start => { -// // app.focused_block = FocusedBlock::TransportFilter; -// // app.filter.transport.state.select(Some(0)); -// // } -// // _ => {} -// // }; - -// // return Ok(()); -// // } - -// // match app.mode { -// // Mode::Packet => app.mode = Mode::Stats, -// // Mode::Stats => app.mode = Mode::Alerts, -// // Mode::Alerts => app.mode = Mode::Firewall, -// // Mode::Firewall => app.mode = Mode::Packet, -// // }; -// // } else { -// // match &app.focused_block { -// // FocusedBlock::Interface => { -// // app.focused_block = FocusedBlock::TransportFilter; -// // app.previous_focused_block = app.focused_block; -// // app.interface.state.select(None); -// // app.filter.transport.state.select(Some(0)); -// // } - -// // FocusedBlock::TransportFilter => { -// // app.focused_block = FocusedBlock::NetworkFilter; -// // app.previous_focused_block = app.focused_block; -// // app.filter.network.state.select(Some(0)); -// // app.filter.transport.state.select(None); -// // } - -// // FocusedBlock::NetworkFilter => { -// // app.focused_block = FocusedBlock::LinkFilter; -// // app.previous_focused_block = app.focused_block; -// // app.filter.link.state.select(Some(0)); -// // app.filter.network.state.select(None); -// // } - -// // FocusedBlock::LinkFilter => { -// // app.focused_block = FocusedBlock::TrafficDirection; -// // app.previous_focused_block = app.focused_block; -// // app.filter.traffic_direction.state.select(Some(0)); -// // app.filter.link.state.select(None); -// // } - -// // FocusedBlock::TrafficDirection => { -// // app.focused_block = FocusedBlock::Start; -// // app.previous_focused_block = app.focused_block; -// // app.filter.traffic_direction.state.select(None); -// // } - -// // FocusedBlock::Start => { -// // app.focused_block = FocusedBlock::Interface; -// // app.previous_focused_block = app.focused_block; -// // app.interface.state.select(Some(0)); -// // } -// // _ => {} -// // } -// // } -// // } - -// // KeyCode::BackTab => { -// // if app.start_sniffing { -// // if app.focused_block == FocusedBlock::Help { -// // return Ok(()); -// // } - -// // if app.update_filters { -// // match &app.focused_block { -// // FocusedBlock::TransportFilter => { -// // app.focused_block = FocusedBlock::Start; -// // app.filter.transport.state.select(None); -// // } - -// // FocusedBlock::NetworkFilter => { -// // app.focused_block = FocusedBlock::TransportFilter; -// // app.filter.transport.state.select(Some(0)); -// // app.filter.network.state.select(None); -// // } - -// // FocusedBlock::LinkFilter => { -// // app.focused_block = FocusedBlock::NetworkFilter; -// // app.filter.network.state.select(Some(0)); -// // app.filter.link.state.select(None); -// // } - -// // FocusedBlock::TrafficDirection => { -// // app.focused_block = FocusedBlock::LinkFilter; -// // app.filter.link.state.select(Some(0)); -// // app.filter.traffic_direction.state.select(None); -// // } - -// // FocusedBlock::Start => { -// // app.focused_block = FocusedBlock::TrafficDirection; -// // app.filter.traffic_direction.state.select(Some(0)); -// // } -// // _ => {} -// // } -// // return Ok(()); -// // }; - -// // match app.mode { -// // Mode::Packet => app.mode = Mode::Alerts, -// // Mode::Stats => app.mode = Mode::Packet, -// // Mode::Alerts => app.mode = Mode::Firewall, -// // Mode::Firewall => app.mode = Mode::Packet, -// // }; -// // } else { -// // match &app.focused_block { -// // FocusedBlock::Interface => { -// // app.focused_block = FocusedBlock::Start; -// // app.interface.state.select(None); -// // } - -// // FocusedBlock::TransportFilter => { -// // app.focused_block = FocusedBlock::Interface; -// // app.interface.state.select(Some(0)); -// // app.filter.transport.state.select(None); -// // } - -// // FocusedBlock::NetworkFilter => { -// // app.focused_block = FocusedBlock::TransportFilter; -// // app.filter.transport.state.select(Some(0)); -// // app.filter.network.state.select(None); -// // } - -// // FocusedBlock::LinkFilter => { -// // app.focused_block = FocusedBlock::NetworkFilter; -// // app.filter.network.state.select(Some(0)); -// // app.filter.link.state.select(None); -// // } - -// // FocusedBlock::TrafficDirection => { -// // app.focused_block = FocusedBlock::LinkFilter; -// // app.filter.link.state.select(Some(0)); -// // app.filter.traffic_direction.state.select(None); -// // } - -// // FocusedBlock::Start => { -// // app.focused_block = FocusedBlock::TrafficDirection; -// // app.filter.traffic_direction.state.select(Some(0)); -// // } -// // _ => {} -// // } -// // } -// // } -// KeyCode::Char(' ') => { -// if !app.start_sniffing || app.update_filters { -// match &app.focused_block { -// FocusedBlock::Interface => { -// if let Some(index) = app.interface.state.selected() { -// let net_interface = app.interface.interfaces[index].clone(); -// if net_interface.is_up { -// app.interface.selected_interface = -// app.interface.interfaces[index].clone(); -// } -// } -// } -// FocusedBlock::NetworkFilter => { -// app.filter.network.select(); -// } - -// FocusedBlock::TransportFilter => { -// app.filter.transport.select(); -// } - -// FocusedBlock::LinkFilter => { -// app.filter.link.select(); -// } - -// FocusedBlock::TrafficDirection => { -// app.filter.traffic_direction.select(); -// } - -// _ => {} -// } -// } -// } - -// KeyCode::Char('j') | KeyCode::Down => { -// if let FocusedBlock::Help = app.focused_block { -// return Ok(()); -// } -// let app_packets = app.packets.lock().unwrap(); -// // Sniff mode -// if app.start_sniffing && !app.update_filters { -// if !app.manuall_scroll { -// app.manuall_scroll = true; -// // Record the last position. Usefull for selecting the packets to display -// app.packet_end_index = app_packets.len(); -// } -// let i = match app.packets_table_state.selected() { -// Some(i) => { -// if i < app.packet_window_size - 1 { -// i + 1 -// } else if i == app.packet_window_size - 1 -// && app_packets.len() > app.packet_end_index -// { -// // shit the window by one -// app.packet_end_index += 1; -// i + 1 -// } else { -// i -// } -// } -// None => app_packets.len(), -// }; - -// app.packets_table_state.select(Some(i)); -// } else { -// match &app.focused_block { -// // FocusedBlock::Interface => { -// // app.interface.scroll_down(); -// // } - -// // FocusedBlock::NetworkFilter => { -// // app.filter.network.scroll_down(); -// // } - -// // FocusedBlock::TransportFilter => { -// // app.filter.transport.scroll_down(); -// // } - -// // FocusedBlock::LinkFilter => { -// // app.filter.link.scroll_down(); -// // } - -// // FocusedBlock::TrafficDirection => { -// // app.filter.traffic_direction.state.select(Some(1)); -// // } - -// // FocusedBlock::Help => { -// // app.help.scroll_down(); -// // } -// _ => {} -// } -// } -// } - -// KeyCode::Char('k') | KeyCode::Up => { -// let app_packets = app.packets.lock().unwrap(); -// if let FocusedBlock::Help = app.focused_block { -// return Ok(()); -// } -// if app.start_sniffing && !app.update_filters { -// if !app.manuall_scroll { -// app.manuall_scroll = true; -// // Record the last position. Usefull for selecting the packets to display -// app.packet_end_index = app_packets.len(); -// } -// let i = match app.packets_table_state.selected() { -// Some(i) => { -// if i > 1 { -// i - 1 -// } else if i == 0 && app.packet_end_index > app.packet_window_size { -// // shit the window by one -// app.packet_end_index -= 1; -// 0 -// } else { -// 0 -// } -// } -// None => app.packet_window_size, -// }; - -// app.packets_table_state.select(Some(i)); -// } else { -// match &app.focused_block { -// // FocusedBlock::Interface => { -// // app.interface.scroll_up(); -// // } -// // FocusedBlock::NetworkFilter => { -// // app.filter.network.scroll_up(); -// // } -// // FocusedBlock::TransportFilter => { -// // app.filter.transport.scroll_up(); -// // } -// // FocusedBlock::LinkFilter => { -// // app.filter.link.scroll_up(); -// // } -// // FocusedBlock::TrafficDirection => { -// // app.filter.traffic_direction.state.select(Some(0)); -// // } -// FocusedBlock::Help => { -// app.help.scroll_up(); -// } -// _ => {} -// } -// } -// } - -// _ => {} -// } -// } - -// Ok(()) -// } diff --git a/oryx-tui/src/lib.rs b/oryx-tui/src/lib.rs index 414a63c..1b291d7 100644 --- a/oryx-tui/src/lib.rs +++ b/oryx-tui/src/lib.rs @@ -48,3 +48,5 @@ pub mod alerts { pub mod firewall; pub mod mode; + +pub mod app_; diff --git a/oryx-tui/src/mode.rs b/oryx-tui/src/mode.rs index d7a5716..18faae8 100644 --- a/oryx-tui/src/mode.rs +++ b/oryx-tui/src/mode.rs @@ -29,7 +29,7 @@ pub enum Mode { impl Mode { pub fn next(&mut self) { - *self = match self { + *self = match *self { Mode::Packet => Mode::Stats, Mode::Stats => Mode::Alerts, Mode::Alerts => Mode::Firewall, @@ -37,7 +37,7 @@ impl Mode { } } pub fn previous(&mut self) { - *self = match self { + *self = match *self { Mode::Packet => Mode::Firewall, Mode::Stats => Mode::Packet, Mode::Alerts => Mode::Stats, @@ -150,7 +150,7 @@ impl Mode { app.focused_block = FocusedBlock::UpdateFilterMenuBlock( UpdateFilterMenuBlock::TransportFilter, ); - UpdateFilterMenuBlock::TransportFilter.select(app); + UpdateFilterMenuBlock::TransportFilter.on_select(app); app.filter.network.selected_protocols = app.filter.network.applied_protocols.clone(); diff --git a/oryx-tui/src/ui.rs b/oryx-tui/src/ui.rs index cee7227..2fd1e8a 100644 --- a/oryx-tui/src/ui.rs +++ b/oryx-tui/src/ui.rs @@ -5,9 +5,9 @@ use crate::app::{App, FocusedBlock}; pub fn render(app: &mut App, frame: &mut Frame) { app.render(frame); - if let FocusedBlock::Help = app.focused_block { - app.help.render(frame); - } + // if let FocusedBlock::Help = app.focused_block { + // app.help.render(frame); + // } for (index, notification) in app.notifications.iter().enumerate() { notification.render(index, frame);