Skip to content

Commit

Permalink
wip bis
Browse files Browse the repository at this point in the history
  • Loading branch information
adgaultier committed Sep 27, 2024
1 parent 723582b commit 4c7b4fa
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 143 deletions.
57 changes: 41 additions & 16 deletions oryx-tui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ impl StartMenuBlock {
pub fn app_component(self, app: &mut App) -> Option<&mut TableState> {
match self {
StartMenuBlock::Interface => Some(&mut app.interface.state),
StartMenuBlock::TransportFilter => Some(&mut app.filter.transport.state),
StartMenuBlock::NetworkFilter => Some(&mut app.filter.network.state),
StartMenuBlock::LinkFilter => Some(&mut app.filter.link.state),
StartMenuBlock::TrafficDirection => Some(&mut app.filter.traffic_direction.state),
StartMenuBlock::TransportFilter => Some(&mut (*app).filter.transport.state),
StartMenuBlock::NetworkFilter => Some(&mut (*app).filter.network.state),
StartMenuBlock::LinkFilter => Some(&mut (*app).filter.link.state),
StartMenuBlock::TrafficDirection => Some(&mut (*app).filter.traffic_direction.state),
StartMenuBlock::Start => None,
}
}
Expand Down Expand Up @@ -103,23 +103,48 @@ impl StartMenuBlock {
None => {}
}
}
pub fn scroll_up(self,app: &mut App){
pub fn scroll_up(self, app: &mut App) {
match self {
StartMenuBlock::Interface => app.interface.scroll_up(),
StartMenuBlock::TransportFilter => (*app).filter.transport.scroll_up(),
StartMenuBlock::NetworkFilter => (*app).filter.network.scroll_up(),
StartMenuBlock::LinkFilter => (*app).filter.link.scroll_up(),
StartMenuBlock::TrafficDirection => (*app).filter.traffic_direction.state.select(Some(0)),
_ => {}
StartMenuBlock::TransportFilter => (*app).filter.transport.scroll_up(),
StartMenuBlock::NetworkFilter => (*app).filter.network.scroll_up(),
StartMenuBlock::LinkFilter => (*app).filter.link.scroll_up(),
StartMenuBlock::TrafficDirection => {
(*app).filter.traffic_direction.state.select(Some(0))
}
_ => {}
}
}
pub fn scroll_down(self,app: &mut App){

pub fn scroll_down(self, app: &mut App) {
match self {
StartMenuBlock::Interface => app.interface.scroll_down(),
StartMenuBlock::TransportFilter => (*app).filter.transport.scroll_down(),
StartMenuBlock::NetworkFilter => (*app).filter.network.scroll_down(),
StartMenuBlock::LinkFilter => (*app).filter.link.scroll_down(),
StartMenuBlock::TrafficDirection => (*app).filter.traffic_direction.state.select(Some(1)),
_ => {}
StartMenuBlock::TransportFilter => (*app).filter.transport.scroll_down(),
StartMenuBlock::NetworkFilter => (*app).filter.network.scroll_down(),
StartMenuBlock::LinkFilter => (*app).filter.link.scroll_down(),
StartMenuBlock::TrafficDirection => {
(*app).filter.traffic_direction.state.select(Some(1))
}
_ => {}
}
}
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_up(app);
}

_ => {}
}
}
}
#[derive(Debug, Copy, Clone, PartialEq)]
Expand Down
105 changes: 54 additions & 51 deletions oryx-tui/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,19 @@ fn handle_key_events_help(key_event: KeyEvent, app: &mut App) {
}
}

fn handle_key_events_start(key_event: KeyEvent, app: &mut App, block: &mut StartMenuBlock) {
match key_event.code {
KeyCode::Tab => {
block.next(app);
}
KeyCode::BackTab => {
block.previous(app);
}
KeyCode::Char('k') | KeyCode::Up => {
block.scroll_up(app);
}
KeyCode::Char('j') | KeyCode::Down => {
block.scroll_up(app);
}

_ => {}
}
}
pub fn handle_key_events(
key_event: KeyEvent,
app: &mut App,
sender: kanal::Sender<Event>,
) -> AppResult<()> {

fn handle_global_keys(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
// handle global key events
if !app.is_editing {
match key_event.code {
KeyCode::Char('?') => {
app.focused_block = FocusedBlock::Help;
return Ok(())
}
KeyCode::Char('q') => {
app.detach_interfaces();
Expand All @@ -62,35 +51,49 @@ fn handle_global_keys(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
app.quit();
}
}
KeyCode::Char('r') => {
if key_event.modifiers == KeyModifiers::CONTROL {
app.detach_interfaces();
sender.send(Event::Reset)?;
return Ok(())
}
}

_ => {}
}
}
return Ok(());
}

pub fn handle_key_events(
key_event: KeyEvent,
app: &mut App,
sender: kanal::Sender<Event>,
) -> AppResult<()> {
handle_global_keys(key_event, app);
match app.focused_block {
FocusedBlock::Help => handle_key_events_help(key_event, app),
FocusedBlock::StartMenuBlock(start_block) => {
handle_key_events_start(key_event, app, &mut start_block)
}
FocusedBlock::Main(mode_block) => mode_block.handle_key_events(key_event, app),
FocusedBlock::StartMenuBlock( &mut start_block) => start_block.handle_key_events(key_event, app),
FocusedBlock::Main( &mut mode_block) => mode_block.handle_key_events(key_event, app),
}
// old
return Ok(())
}






if app.show_packet_infos_popup {
if key_event.code == KeyCode::Esc {
app.show_packet_infos_popup = false;
}

return Ok(());
}




///////////////////////
// old
pub fn old_handle_key_events(
key_event: KeyEvent,
app: &mut App,
sender: kanal::Sender<Event>,
) -> 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();
Expand Down Expand Up @@ -123,10 +126,10 @@ pub fn handle_key_events(
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));
// if !fuzzy.is_paused() && !app.update_filters {
// fuzzy
// .filter
// .handle_event(&crossterm::event::Event::Key(key_event));
} else {
match key_event.code {
KeyCode::Char('/') => {
Expand Down Expand Up @@ -402,15 +405,15 @@ pub fn handle_key_events(

// 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::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 {
Expand Down
Loading

0 comments on commit 4c7b4fa

Please sign in to comment.