Skip to content

Commit

Permalink
refactor traffic direction filter
Browse files Browse the repository at this point in the history
  • Loading branch information
pythops committed Sep 25, 2024
1 parent c0f872e commit 1c07bf9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
12 changes: 11 additions & 1 deletion oryx-tui/src/filters/direction.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::{
fmt::Display,
sync::{atomic::AtomicBool, Arc},
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
};

use ratatui::{
Expand Down Expand Up @@ -53,6 +56,13 @@ impl TrafficDirectionFilter {
}
}

pub fn terminate(&mut self, direction: TrafficDirection) {
match direction {
TrafficDirection::Ingress => self.terminate_ingress.store(true, Ordering::Relaxed),
TrafficDirection::Egress => self.terminate_egress.store(true, Ordering::Relaxed),
}
}

pub fn select(&mut self) {
if let Some(i) = self.state.selected() {
let traffic_direction = match i {
Expand Down
25 changes: 8 additions & 17 deletions oryx-tui/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,16 +301,13 @@ pub fn handle_key_events(
}
} else {
match key_event.code {
//TODO: add terminate method on ingress and egress
KeyCode::Char('q') => {
app.filter
.traffic_direction
.terminate_egress
.store(true, std::sync::atomic::Ordering::Relaxed);
.terminate(TrafficDirection::Egress);
app.filter
.traffic_direction
.terminate_ingress
.store(true, std::sync::atomic::Ordering::Relaxed);
.terminate(TrafficDirection::Ingress);
thread::sleep(Duration::from_millis(110));
app.quit();
}
Expand All @@ -319,12 +316,10 @@ pub fn handle_key_events(
if key_event.modifiers == KeyModifiers::CONTROL {
app.filter
.traffic_direction
.terminate_egress
.store(true, std::sync::atomic::Ordering::Relaxed);
.terminate(TrafficDirection::Egress);
app.filter
.traffic_direction
.terminate_ingress
.store(true, std::sync::atomic::Ordering::Relaxed);
.terminate(TrafficDirection::Ingress);
thread::sleep(Duration::from_millis(110));
app.quit();
}
Expand Down Expand Up @@ -439,12 +434,10 @@ pub fn handle_key_events(
if key_event.modifiers == KeyModifiers::CONTROL {
app.filter
.traffic_direction
.terminate_egress
.store(true, std::sync::atomic::Ordering::Relaxed);
.terminate(TrafficDirection::Ingress);
app.filter
.traffic_direction
.terminate_ingress
.store(true, std::sync::atomic::Ordering::Relaxed);
.terminate(TrafficDirection::Egress);
thread::sleep(Duration::from_millis(150));
sender.send(Event::Reset)?;
}
Expand Down Expand Up @@ -506,8 +499,7 @@ pub fn handle_key_events(
{
app.filter
.traffic_direction
.terminate_egress
.store(true, std::sync::atomic::Ordering::Relaxed);
.terminate(TrafficDirection::Egress);
}

// Add egress
Expand Down Expand Up @@ -550,8 +542,7 @@ pub fn handle_key_events(
{
app.filter
.traffic_direction
.terminate_ingress
.store(true, std::sync::atomic::Ordering::Relaxed);
.terminate(TrafficDirection::Ingress);
}

// Add ingress
Expand Down

0 comments on commit 1c07bf9

Please sign in to comment.