Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
adgaultier committed Sep 29, 2024
1 parent 3d80049 commit fe3133a
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 942 deletions.
1 change: 0 additions & 1 deletion oryx-tui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ kanal = "0.1.0-pre8"
mimalloc = "0.1"
clap = { version = "4", features = ["derive", "cargo"] }
network-types = "0.0.7"

[[bin]]
name = "oryx"
path = "src/main.rs"
Empty file added oryx-tui/src/app_.rs
Empty file.
60 changes: 29 additions & 31 deletions oryx-tui/src/filters/start_menu.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::app::App;
use crate::app::{App, FocusedBlock};
use crossterm::event::{KeyCode, KeyEvent};
use ratatui::prelude::Stylize;
use ratatui::{
Expand All @@ -20,18 +20,33 @@ pub enum StartMenuBlock {
}

impl StartMenuBlock {
pub fn next(&mut self, app: &mut App) {
self.unselect(app);
*self = match self {
pub fn next(self, app: &mut App) {
self.on_unselect(app);
let x = match self {
StartMenuBlock::Interface => StartMenuBlock::TransportFilter,
StartMenuBlock::TransportFilter => StartMenuBlock::NetworkFilter,
StartMenuBlock::NetworkFilter => StartMenuBlock::LinkFilter,
StartMenuBlock::LinkFilter => StartMenuBlock::TrafficDirection,
StartMenuBlock::TrafficDirection => StartMenuBlock::Start,
StartMenuBlock::Start => StartMenuBlock::Interface,
};
self.select(app);
app.focused_block = FocusedBlock::StartMenuBlock(x);
x.on_select(app)
}
pub fn previous(self, app: &mut App) {
self.on_unselect(app);
let x = match self {
StartMenuBlock::Interface => StartMenuBlock::Start,
StartMenuBlock::TransportFilter => StartMenuBlock::Interface,
StartMenuBlock::NetworkFilter => StartMenuBlock::TransportFilter,
StartMenuBlock::LinkFilter => StartMenuBlock::NetworkFilter,
StartMenuBlock::TrafficDirection => StartMenuBlock::LinkFilter,
StartMenuBlock::Start => StartMenuBlock::TrafficDirection,
};
app.focused_block = FocusedBlock::StartMenuBlock(x);
x.on_select(app)
}

pub fn app_component(self, app: &mut App) -> Option<&mut TableState> {
match self {
StartMenuBlock::Interface => Some(&mut app.interface.state),
Expand All @@ -42,28 +57,16 @@ impl StartMenuBlock {
StartMenuBlock::Start => None,
}
}
pub fn previous(&mut self, app: &mut App) {
self.unselect(app);
*self = match self {
StartMenuBlock::Interface => StartMenuBlock::Start,
StartMenuBlock::TransportFilter => StartMenuBlock::Interface,
StartMenuBlock::NetworkFilter => StartMenuBlock::TransportFilter,
StartMenuBlock::LinkFilter => StartMenuBlock::NetworkFilter,
StartMenuBlock::TrafficDirection => StartMenuBlock::LinkFilter,
StartMenuBlock::Start => StartMenuBlock::TrafficDirection,
};
self.select(app);
}

fn select(self, app: &mut App) {
fn on_select(self, app: &mut App) {
match self.app_component(app) {
Some(p) => {
p.select(Some(0));
}
None => {}
}
}
fn unselect(self, app: &mut App) {
fn on_unselect(self, app: &mut App) {
match self.app_component(app) {
Some(p) => {
p.select(None);
Expand Down Expand Up @@ -98,18 +101,13 @@ impl StartMenuBlock {
}
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_down(app);
}
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_down(app),

_ => {}
}
}
Expand Down
46 changes: 19 additions & 27 deletions oryx-tui/src/filters/update_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ratatui::{
};
use tui_big_text::{BigText, PixelSize};

use crate::app::App;
use crate::app::{App, FocusedBlock};

#[derive(Debug, Copy, Clone, PartialEq)]
pub enum UpdateFilterMenuBlock {
Expand All @@ -20,16 +20,17 @@ pub enum UpdateFilterMenuBlock {
}

impl UpdateFilterMenuBlock {
pub fn next(&mut self, app: &mut App) {
self.unselect(app);
*self = match self {
pub fn next(self, app: &mut App) {
self.on_unselect(app);
let x = match self {
UpdateFilterMenuBlock::TransportFilter => UpdateFilterMenuBlock::NetworkFilter,
UpdateFilterMenuBlock::NetworkFilter => UpdateFilterMenuBlock::LinkFilter,
UpdateFilterMenuBlock::LinkFilter => UpdateFilterMenuBlock::TrafficDirection,
UpdateFilterMenuBlock::TrafficDirection => UpdateFilterMenuBlock::Start,
UpdateFilterMenuBlock::Start => UpdateFilterMenuBlock::TransportFilter,
};
self.select(app);
app.focused_block = FocusedBlock::UpdateFilterMenuBlock(x);
x.on_select(app)
}
pub fn app_component(self, app: &mut App) -> Option<&mut TableState> {
match self {
Expand All @@ -42,27 +43,28 @@ impl UpdateFilterMenuBlock {
UpdateFilterMenuBlock::Start => None,
}
}
pub fn previous(&mut self, app: &mut App) {
self.unselect(app);
*self = match self {
pub fn previous(self, app: &mut App) {
self.on_unselect(app);
let x = match self {
UpdateFilterMenuBlock::TransportFilter => UpdateFilterMenuBlock::Start,
UpdateFilterMenuBlock::NetworkFilter => UpdateFilterMenuBlock::TransportFilter,
UpdateFilterMenuBlock::LinkFilter => UpdateFilterMenuBlock::NetworkFilter,
UpdateFilterMenuBlock::TrafficDirection => UpdateFilterMenuBlock::LinkFilter,
UpdateFilterMenuBlock::Start => UpdateFilterMenuBlock::TrafficDirection,
};
self.select(app);
app.focused_block = FocusedBlock::UpdateFilterMenuBlock(x);
x.on_select(app)
}

pub fn select(self, app: &mut App) {
pub fn on_select(self, app: &mut App) {
match self.app_component(app) {
Some(p) => {
p.select(Some(0));
}
None => {}
}
}
fn unselect(self, app: &mut App) {
fn on_unselect(self, app: &mut App) {
match self.app_component(app) {
Some(p) => {
p.select(None);
Expand Down Expand Up @@ -95,23 +97,13 @@ impl UpdateFilterMenuBlock {
}
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_down(app);
}
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_down(app),

KeyCode::Esc => {
app.focused_block = app.previous_focused_block.clone();
app.update_filters = false;
}
_ => {}
}
}
Expand Down
Loading

0 comments on commit fe3133a

Please sign in to comment.