Skip to content

Commit

Permalink
ad info popup (not showing)
Browse files Browse the repository at this point in the history
  • Loading branch information
adgaultier committed Sep 29, 2024
1 parent 87d6c39 commit 8a27980
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 58 deletions.
1 change: 1 addition & 0 deletions oryx-tui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub mod export;
pub mod bandwidth;

pub mod packets {
pub mod info;
pub mod link;
pub mod network;
pub mod packet;
Expand Down
67 changes: 67 additions & 0 deletions oryx-tui/src/packets/info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use crossterm::event::{KeyCode, KeyEvent};
use ratatui::{
layout::{Alignment, Constraint, Direction, Layout},
style::{Style, Stylize},
widgets::{Block, BorderType, Borders, Clear},
Frame,
};

use crate::app::App;

use super::packet::AppPacket;

pub struct PacketInfo {}
impl PacketInfo {
pub fn render(frame: &mut Frame, app: &mut App) {
let layout = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Fill(1),
Constraint::Length(36),
Constraint::Fill(1),
])
.flex(ratatui::layout::Flex::SpaceBetween)
.split(frame.area());

let block = Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Fill(1),
Constraint::Max(80),
Constraint::Fill(1),
])
.flex(ratatui::layout::Flex::SpaceBetween)
.split(layout[1])[1];

let fuzzy = app.fuzzy.lock().unwrap();
let packets = app.packets.lock().unwrap();

let packet = if fuzzy.is_enabled() {
fuzzy.packets[app.packet_index.unwrap()]
} else {
packets[app.packet_index.unwrap()]
};

frame.render_widget(Clear, block);
frame.render_widget(
Block::new()
.title(" Packet Infos 󰋼 ")
.title_style(Style::new().bold().green())
.title_alignment(Alignment::Center)
.borders(Borders::all())
.border_style(Style::new().green())
.border_type(BorderType::Thick),
block,
);
match packet {
AppPacket::Ip(ip_packet) => ip_packet.render(block, frame),
AppPacket::Arp(arp_packet) => arp_packet.render(block, frame),
};
}
pub fn handle_key_events(&mut self, key_event: KeyEvent, app: &mut App) {
match key_event.code {
KeyCode::Esc => app.phase.popup = None,
_ => {}
}
}
}
5 changes: 4 additions & 1 deletion oryx-tui/src/popup.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
use ratatui::{layout::Rect, Frame};

use crate::app::App;
use crate::{app::App, packets::info::PacketInfo};

#[derive(Debug, Clone, PartialEq)]
pub enum PopupEnum {
Help,
FilterUpdate,
PacketInfo,
}
impl PopupEnum {
pub fn render(&self, frame: &mut Frame, _: Rect, app: &mut App) {
match self {
PopupEnum::Help => app.help.render(frame),
PopupEnum::FilterUpdate => app.filter_update.clone().render(frame, app),
PopupEnum::PacketInfo => PacketInfo::render(frame, app),
}
}
pub fn handle_key_events(&mut self, key_event: crossterm::event::KeyEvent, app: &mut App) {
match self {
PopupEnum::Help => app.help.clone().handle_key_events(key_event, app),
PopupEnum::FilterUpdate => app.filter_update.clone().handle_key_events(key_event, app),
_ => {}
}
}
}
61 changes: 4 additions & 57 deletions oryx-tui/src/sections/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use ratatui::{
style::{Color, Style, Stylize},
text::{Line, Span},
widgets::{
Block, BorderType, Borders, Cell, Clear, HighlightSpacing, Padding, Paragraph, Row,
Scrollbar, ScrollbarOrientation, ScrollbarState, Table,
Block, BorderType, Borders, Cell, HighlightSpacing, Padding, Paragraph, Row, Scrollbar,
ScrollbarOrientation, ScrollbarState, Table,
},
Frame,
};
Expand Down Expand Up @@ -87,7 +87,7 @@ impl Section {
match key_event.code {
KeyCode::Char('i') => {
if !app.packet_index.is_none() && !fuzzy.packets.is_empty() {
app.show_packet_infos_popup = true;
app.phase.popup = Some(PopupEnum::PacketInfo);
}
}
KeyCode::Char('/') => {
Expand Down Expand Up @@ -218,13 +218,7 @@ impl Section {
app.alert.title_span(*self == Section::Alerts),
);
match self {
Section::Packet => {
self.render_packets_section(frame, section_block, app);
// show packet info popup if needed
if app.show_packet_infos_popup {
self.render_packet_infos_popup(frame, app);
}
}
Section::Packet => self.render_packets_section(frame, section_block, app),
Section::Stats => self.render_stats_section(frame, section_block, app),
Section::Alerts => app.alert.render(frame, section_block),
Section::Firewall => app.firewall.render(frame, section_block),
Expand Down Expand Up @@ -693,51 +687,4 @@ impl Section {
frame.render_widget(fuzzy, fuzzy_block);
}
}

fn render_packet_infos_popup(&self, frame: &mut Frame, app: &mut App) {
let layout = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Fill(1),
Constraint::Length(36),
Constraint::Fill(1),
])
.flex(ratatui::layout::Flex::SpaceBetween)
.split(frame.area());

let block = Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Fill(1),
Constraint::Max(80),
Constraint::Fill(1),
])
.flex(ratatui::layout::Flex::SpaceBetween)
.split(layout[1])[1];

let fuzzy = app.fuzzy.lock().unwrap();
let packets = app.packets.lock().unwrap();

let packet = if fuzzy.is_enabled() {
fuzzy.packets[app.packet_index.unwrap()]
} else {
packets[app.packet_index.unwrap()]
};

frame.render_widget(Clear, block);
frame.render_widget(
Block::new()
.title(" Packet Infos 󰋼 ")
.title_style(Style::new().bold().green())
.title_alignment(Alignment::Center)
.borders(Borders::all())
.border_style(Style::new().green())
.border_type(BorderType::Thick),
block,
);
match packet {
AppPacket::Ip(ip_packet) => ip_packet.render(block, frame),
AppPacket::Arp(arp_packet) => arp_packet.render(block, frame),
};
}
}

0 comments on commit 8a27980

Please sign in to comment.