Skip to content

Commit

Permalink
enhance firewall rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
pythops committed Oct 5, 2024
1 parent 850f0f3 commit 92b76c9
Show file tree
Hide file tree
Showing 5 changed files with 316 additions and 227 deletions.
1 change: 1 addition & 0 deletions oryx-tui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub enum ActivePopup {
Help,
UpdateFilters,
PacketInfos,
NewFirewallRule,
}

#[derive(Debug)]
Expand Down
59 changes: 43 additions & 16 deletions oryx-tui/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
export::export,
filter::FocusedBlock,
notification::{Notification, NotificationLevel},
section::{FocusedSection, Section},
};
use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers};

Expand Down Expand Up @@ -56,25 +57,41 @@ pub fn handle_key_events(
match key_event.code {
KeyCode::Esc => {
app.active_popup = None;
if popup == ActivePopup::UpdateFilters {
app.filter.handle_key_events(key_event, true);
match popup {
ActivePopup::UpdateFilters => {
app.filter.handle_key_events(key_event, true);
}
ActivePopup::NewFirewallRule => {
app.section.firewall.handle_keys(key_event);
app.is_editing = false;
}
_ => {}
}
}
KeyCode::Enter => {
if popup == ActivePopup::UpdateFilters
&& app.filter.focused_block == FocusedBlock::Apply
{
app.filter
.update(sender.clone(), app.data_channel_sender.clone())?;
KeyCode::Enter => match popup {
ActivePopup::UpdateFilters => {
if app.filter.focused_block == FocusedBlock::Apply {
app.filter
.update(sender.clone(), app.data_channel_sender.clone())?;

app.active_popup = None;
app.active_popup = None;
}
}
}
_ => {
if popup == ActivePopup::UpdateFilters {
ActivePopup::NewFirewallRule => {
app.section.firewall.handle_keys(key_event);
}
_ => {}
},

_ => match popup {
ActivePopup::UpdateFilters => {
app.filter.handle_key_events(key_event, true);
}
}
ActivePopup::NewFirewallRule => {
app.section.firewall.handle_keys(key_event);
}
_ => {}
},
}

return Ok(());
Expand Down Expand Up @@ -122,9 +139,19 @@ pub fn handle_key_events(
}
}

KeyCode::Char('/') | KeyCode::Char('n') => {
app.is_editing = true;
app.section.handle_keys(key_event);
KeyCode::Char('/') => {
if app.section.focused_section == FocusedSection::Inspection {
app.is_editing = true;
app.section.handle_keys(key_event);
}
}

KeyCode::Char('n') => {
if app.section.focused_section == FocusedSection::Firewall {
app.is_editing = true;
app.section.handle_keys(key_event);
app.active_popup = Some(ActivePopup::NewFirewallRule);
}
}

KeyCode::Char('i') => {
Expand Down
9 changes: 7 additions & 2 deletions oryx-tui/src/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum FocusedSection {

#[derive(Debug)]
pub struct Section {
focused_section: FocusedSection,
pub focused_section: FocusedSection,
pub inspection: Inspection,
pub stats: Stats,
pub alert: Alert,
Expand Down Expand Up @@ -111,7 +111,7 @@ impl Section {
FocusedSection::Inspection => self.inspection.render(frame, block),
FocusedSection::Stats => self.stats.render(frame, block, network_interace),
FocusedSection::Alerts => self.alert.render(frame, block),
FocusedSection::Firewall => self.alert.render(frame, block),
FocusedSection::Firewall => self.firewall.render(frame, block),
}
}

Expand All @@ -135,6 +135,11 @@ impl Section {
if self.focused_section == FocusedSection::Inspection {
self.inspection.handle_keys(key_event);
}
match self.focused_section {
FocusedSection::Inspection => self.inspection.handle_keys(key_event),
FocusedSection::Firewall => self.firewall.handle_keys(key_event),
_ => {}
}
}
}
}
Expand Down
Loading

0 comments on commit 92b76c9

Please sign in to comment.