Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
adgaultier committed Sep 28, 2024
1 parent 3c8ada0 commit 96cb98c
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 136 deletions.
43 changes: 14 additions & 29 deletions oryx-tui/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
use oryx_common::RawPacket;
use ratatui::{
layout::{Alignment, Constraint, Direction, Flex, Layout, Margin, Rect},
style::{Style, Stylize},
text::{Line, Span},
widgets::{
Block, BorderType, Borders, Cell, Clear, HighlightSpacing, Padding, Paragraph, Row,
Scrollbar, ScrollbarOrientation, ScrollbarState, Table, TableState,
},
layout::{Constraint, Direction, Layout, Rect},
widgets::TableState,
Frame,
};
use std::{
Expand All @@ -15,26 +10,16 @@ use std::{
thread,
time::Duration,
};
use tui_big_text::{BigText, PixelSize};

use crate::filters::{
direction::{TrafficDirection, TrafficDirectionFilter},
filter::Filter,
fuzzy::{self, Fuzzy},
link::LinkFilter,
network::NetworkFilter,
start_menu::StartMenuBlock,
transport::TransportFilter,
update_menu::UpdateFilterMenuBLock,
direction::TrafficDirection, filter::Filter, fuzzy::Fuzzy, start_menu::StartMenuBlock,
update_menu::UpdateFilterMenuBlock,
};

use crate::help::Help;
use crate::interface::Interface;
use crate::notification::Notification;
use crate::packets::{
network::{IpPacket, IpProto},
packet::AppPacket,
};
use crate::packets::packet::AppPacket;

use crate::stats::Stats;
use crate::{alerts::alert::Alert, firewall::Firewall};
Expand All @@ -43,10 +28,10 @@ pub type AppResult<T> = std::result::Result<T, Box<dyn error::Error>>;

pub const TICK_RATE: u64 = 40;

#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq)]
pub enum FocusedBlock {
StartMenuBlock(StartMenuBlock),
UpdateFilterMenuBlock(UpdateFilterMenuBLock),
UpdateFilterMenuBlock(UpdateFilterMenuBlock),
Help,
Main(Mode),
}
Expand Down Expand Up @@ -140,13 +125,13 @@ impl App {

pub fn render(&mut self, frame: &mut Frame) {
// Setup
match self.focused_block {
FocusedBlock::StartMenuBlock(b) => b.render(frame, &mut self),
FocusedBlock::Main(mode) => self.render_main_section(frame, mode),
match self.focused_block.clone() {
FocusedBlock::StartMenuBlock(b) => b.render(frame, self),
FocusedBlock::Main(mode) => self.render_main_section(frame, &mode),
_ => {
match self.previous_focused_block {
FocusedBlock::StartMenuBlock(b) => b.render(frame, &mut self),
FocusedBlock::Main(mode) => self.render_main_section(frame, mode),
match self.previous_focused_block.clone() {
FocusedBlock::StartMenuBlock(b) => b.render(frame, self),
FocusedBlock::Main(mode) => self.render_main_section(frame, &mode),
_ => {}
}
match self.focused_block {
Expand All @@ -158,7 +143,7 @@ impl App {
}
}

fn render_main_section(&mut self, frame: &mut Frame, mode: Mode) {
fn render_main_section(&mut self, frame: &mut Frame, mode: &Mode) {
// Build layout
let (settings_block, mode_block) = {
let chunks: std::rc::Rc<[Rect]> = Layout::default()
Expand Down
12 changes: 8 additions & 4 deletions oryx-tui/src/filters/direction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use ratatui::{

use crate::app::FocusedBlock;

use super::{start_menu::StartMenuBlock, update_menu::UpdateFilterMenuBlock};

#[derive(Debug)]
pub struct TrafficDirectionFilter {
pub state: TableState,
Expand Down Expand Up @@ -130,10 +132,12 @@ impl TrafficDirectionFilter {
.title_style(Style::default().bold().fg(Color::Green))
.title_alignment(Alignment::Center)
.borders(Borders::LEFT)
.border_type(if *focused_block == FocusedBlock::TrafficDirection {
BorderType::Thick
} else {
BorderType::default()
.border_type(match *focused_block {
FocusedBlock::StartMenuBlock(StartMenuBlock::TrafficDirection)
| FocusedBlock::UpdateFilterMenuBlock(
UpdateFilterMenuBlock::TrafficDirection,
) => BorderType::Thick,
_ => BorderType::default(),
})
.border_style(Style::default().fg(Color::Green)),
area,
Expand Down
3 changes: 1 addition & 2 deletions oryx-tui/src/filters/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ use ratatui::{
layout::{Alignment, Constraint, Direction, Flex, Layout, Rect},
style::{Style, Stylize},
text::{Line, Span},
widgets::{Block, BorderType, Borders, Clear, Padding, Row, Table},
widgets::{Block, BorderType, Borders, Padding, Row, Table},
Frame,
};
use tui_big_text::{BigText, PixelSize};

use crate::app::FocusedBlock;

Expand Down
12 changes: 8 additions & 4 deletions oryx-tui/src/filters/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use ratatui::{

use crate::app::FocusedBlock;

use super::{start_menu::StartMenuBlock, update_menu::UpdateFilterMenuBlock};

#[derive(Debug)]
pub struct LinkFilter {
pub state: TableState,
Expand Down Expand Up @@ -112,10 +114,12 @@ impl LinkFilter {
.title_style(Style::default().bold().fg(Color::Green))
.title_alignment(Alignment::Center)
.borders(Borders::LEFT)
.border_type(if *focused_block == FocusedBlock::LinkFilter {
BorderType::Thick
} else {
BorderType::default()
.border_type(match *focused_block {
FocusedBlock::StartMenuBlock(StartMenuBlock::LinkFilter)
| FocusedBlock::UpdateFilterMenuBlock(UpdateFilterMenuBlock::LinkFilter) => {
BorderType::Thick
}
_ => BorderType::default(),
})
.border_style(Style::default().fg(Color::Green)),
area,
Expand Down
14 changes: 8 additions & 6 deletions oryx-tui/src/filters/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use ratatui::{

use crate::app::FocusedBlock;

use super::{start_menu::StartMenuBlock, update_menu::UpdateFilterMenuBlock};

#[derive(Debug)]
pub struct NetworkFilter {
pub state: TableState,
Expand Down Expand Up @@ -144,13 +146,13 @@ impl NetworkFilter {
.title_style(Style::default().bold().fg(Color::Green))
.title_alignment(Alignment::Center)
.borders(Borders::LEFT)
.border_type(
if *focused_block == FocusedBlock::StartMenuBlock(NetworkFilter) {
.border_type(match *focused_block {
FocusedBlock::StartMenuBlock(StartMenuBlock::NetworkFilter)
| FocusedBlock::UpdateFilterMenuBlock(UpdateFilterMenuBlock::NetworkFilter) => {
BorderType::Thick
} else {
BorderType::default()
},
)
}
_ => BorderType::default(),
})
.border_style(Style::default().fg(Color::Green)),
area,
);
Expand Down
19 changes: 15 additions & 4 deletions oryx-tui/src/filters/start_menu.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
use crate::app::App;
use crossterm::event::{KeyCode, KeyEvent};
use ratatui::prelude::Stylize;
use ratatui::{
layout::{Constraint, Direction, Flex, Layout},
style::Style,
widgets::TableState,
Frame,
};
use tui_big_text::{BigText, PixelSize};

#[derive(Debug, Copy, Clone, PartialEq)]
pub enum StartMenuBlock {
Expand Down Expand Up @@ -104,7 +113,7 @@ impl StartMenuBlock {
_ => {}
}
}
pub fn render(&mut self, frame: &mut Frame, app: &mut App) {
pub fn render(&self, frame: &mut Frame, app: &mut App) {
let (interface_block, filter_block, start_block) = {
let chunks = Layout::default()
.direction(Direction::Vertical)
Expand All @@ -120,15 +129,17 @@ impl StartMenuBlock {
};

// interfaces
app.interface.render_on_setup(frame, interface_block, &self);
app.interface
.render_on_setup(frame, interface_block, &app.focused_block);

// Filters
app.filter.render_on_setup(frame, filter_block, &self);
app.filter
.render_on_setup(frame, filter_block, &app.focused_block);

// Start Button
let start = BigText::builder()
.pixel_size(PixelSize::Sextant)
.style(if self.focused_block == FocusedBlock::Start {
.style(if *self == StartMenuBlock::Start {
Style::default().white().bold()
} else {
Style::default().dark_gray()
Expand Down
12 changes: 8 additions & 4 deletions oryx-tui/src/filters/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use ratatui::{

use crate::app::FocusedBlock;

use super::{start_menu::StartMenuBlock, update_menu::UpdateFilterMenuBlock};

#[derive(Debug)]
pub struct TransportFilter {
pub state: TableState,
Expand Down Expand Up @@ -129,10 +131,12 @@ impl TransportFilter {
.title_style(Style::default().bold().fg(Color::Green))
.title_alignment(Alignment::Center)
.borders(Borders::LEFT)
.border_type(if *focused_block == FocusedBlock::TransportFilter {
BorderType::Thick
} else {
BorderType::default()
.border_type(match *focused_block {
FocusedBlock::StartMenuBlock(StartMenuBlock::TransportFilter)
| FocusedBlock::UpdateFilterMenuBlock(UpdateFilterMenuBlock::TransportFilter) => {
BorderType::Thick
}
_ => BorderType::default(),
})
.border_style(Style::default().fg(Color::Green)),
area,
Expand Down
Loading

0 comments on commit 96cb98c

Please sign in to comment.