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 2986972 commit 3c8ada0
Show file tree
Hide file tree
Showing 9 changed files with 1,689 additions and 1,579 deletions.
578 changes: 45 additions & 533 deletions oryx-tui/src/app.rs

Large diffs are not rendered by default.

76 changes: 0 additions & 76 deletions oryx-tui/src/filters/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,80 +193,4 @@ impl Filter {

frame.render_widget(table, block);
}

pub fn update(&mut self, frame: &mut Frame, block: Rect, focused_block: &FocusedBlock) {
let layout = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Fill(1),
Constraint::Length(40),
Constraint::Fill(1),
])
.flex(ratatui::layout::Flex::SpaceBetween)
.split(block);

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

let (
transport_filter_block,
network_filter_block,
link_filter_block,
traffic_direction_block,
apply_block,
) = {
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Length(NB_TRANSPORT_PROTOCOL + 4),
Constraint::Length(NB_NETWORK_PROTOCOL + 4),
Constraint::Length(NB_LINK_PROTOCOL + 4),
Constraint::Length(6),
Constraint::Length(4),
])
.margin(1)
.flex(Flex::SpaceBetween)
.split(block);
(chunks[0], chunks[1], chunks[2], chunks[3], chunks[4])
};

frame.render_widget(Clear, block);
frame.render_widget(
Block::new()
.borders(Borders::all())
.border_type(BorderType::Thick)
.border_style(Style::default().green()),
block,
);

self.transport
.render(frame, transport_filter_block, focused_block);

self.network
.render(frame, network_filter_block, focused_block);

self.link.render(frame, link_filter_block, focused_block);

self.traffic_direction
.render(frame, traffic_direction_block, focused_block);

let apply = BigText::builder()
.pixel_size(PixelSize::Sextant)
.style(if *focused_block == FocusedBlock::Start {
Style::default().white().bold()
} else {
Style::default().dark_gray()
})
.lines(vec!["APPLY".into()])
.centered()
.build();
frame.render_widget(apply, apply_block);
}
}
12 changes: 7 additions & 5 deletions oryx-tui/src/filters/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,13 @@ impl NetworkFilter {
.title_style(Style::default().bold().fg(Color::Green))
.title_alignment(Alignment::Center)
.borders(Borders::LEFT)
.border_type(if *focused_block == FocusedBlock::NetworkFilter {
BorderType::Thick
} else {
BorderType::default()
})
.border_type(
if *focused_block == FocusedBlock::StartMenuBlock(NetworkFilter) {
BorderType::Thick
} else {
BorderType::default()
},
)
.border_style(Style::default().fg(Color::Green)),
area,
);
Expand Down
39 changes: 34 additions & 5 deletions oryx-tui/src/startmenu.rs → oryx-tui/src/filters/start_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,41 @@ impl StartMenuBlock {
KeyCode::Char('j') | KeyCode::Down => {
self.scroll_down(app);
}
KeyCode::Esc => {
if app.update_filters {
app.update_filters = false
}
}
_ => {}
}
}
pub fn render(&mut self, frame: &mut Frame, app: &mut App) {
let (interface_block, filter_block, start_block) = {
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Length(app.interface.interfaces.len() as u16 + 6),
Constraint::Fill(1),
Constraint::Length(4),
])
.margin(1)
.flex(Flex::SpaceAround)
.split(frame.area());
(chunks[0], chunks[1], chunks[2])
};

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

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

// Start Button
let start = BigText::builder()
.pixel_size(PixelSize::Sextant)
.style(if self.focused_block == FocusedBlock::Start {
Style::default().white().bold()
} else {
Style::default().dark_gray()
})
.lines(vec!["START".into()])
.centered()
.build();
frame.render_widget(start, start_block);
}
}
184 changes: 184 additions & 0 deletions oryx-tui/src/filters/update_menu.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
use crate::app::App;

#[derive(Debug, Copy, Clone, PartialEq)]
pub enum UpdateFilterMenuBLock {
TransportFilter,
NetworkFilter,
LinkFilter,
TrafficDirection,
Start,
}

impl UpdateFilterMenuBLock {
pub fn next(&mut self, app: &mut App) {
self.unselect(app);
*self = 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);
}
pub fn app_component(self, app: &mut App) -> Option<&mut TableState> {
match self {
UpdateFilterMenuBLock::TransportFilter => Some(&mut (*app).filter.transport.state),
UpdateFilterMenuBLock::NetworkFilter => Some(&mut (*app).filter.network.state),
UpdateFilterMenuBLock::LinkFilter => Some(&mut (*app).filter.link.state),
UpdateFilterMenuBLock::TrafficDirection => {
Some(&mut (*app).filter.traffic_direction.state)
}
UpdateFilterMenuBLock::Start => None,
}
}
pub fn previous(&mut self, app: &mut App) {
self.unselect(app);
*self = 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);
}

fn select(self, app: &mut App) {
match self.app_component(app) {
Some(p) => {
p.select(Some(0));
}
None => {}
}
}
fn unselect(self, app: &mut App) {
match self.app_component(app) {
Some(p) => {
p.select(None);
}
None => {}
}
}
pub fn scroll_up(self, app: &mut App) {
match self {
UpdateFilterMenuBLock::TransportFilter => (*app).filter.transport.scroll_up(),
UpdateFilterMenuBLock::NetworkFilter => (*app).filter.network.scroll_up(),
UpdateFilterMenuBLock::LinkFilter => (*app).filter.link.scroll_up(),
UpdateFilterMenuBLock::TrafficDirection => {
(*app).filter.traffic_direction.state.select(Some(0))
}
_ => {}
}
}

pub fn scroll_down(self, app: &mut App) {
match self {
UpdateFilterMenuBLock::TransportFilter => (*app).filter.transport.scroll_down(),
UpdateFilterMenuBLock::NetworkFilter => (*app).filter.network.scroll_down(),
UpdateFilterMenuBLock::LinkFilter => (*app).filter.link.scroll_down(),
UpdateFilterMenuBLock::TrafficDirection => {
(*app).filter.traffic_direction.state.select(Some(1))
}
_ => {}
}
}
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::Esc => {
app.focused_block = app.previous_focused_block;
app.update_filters = false;
}
_ => {}
}
}
pub fn render(&mut self, frame: &mut Frame, app: App) {
let layout = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Fill(1),
Constraint::Length(40),
Constraint::Fill(1),
])
.flex(ratatui::layout::Flex::SpaceBetween)
.split(frame.area());

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

let (
transport_filter_block,
network_filter_block,
link_filter_block,
traffic_direction_block,
apply_block,
) = {
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Length(NB_TRANSPORT_PROTOCOL + 4),
Constraint::Length(NB_NETWORK_PROTOCOL + 4),
Constraint::Length(NB_LINK_PROTOCOL + 4),
Constraint::Length(6),
Constraint::Length(4),
])
.margin(1)
.flex(Flex::SpaceBetween)
.split(block);
(chunks[0], chunks[1], chunks[2], chunks[3], chunks[4])
};

frame.render_widget(Clear, block);
frame.render_widget(
Block::new()
.borders(Borders::all())
.border_type(BorderType::Thick)
.border_style(Style::default().green()),
block,
);

app.filter
.transport
.render(frame, transport_filter_block, self);

app.filter.network.render(frame, network_filter_block, self);

app.filter.link.render(frame, link_filter_block, self);

app.filter
.traffic_direction
.render(frame, traffic_direction_block, self);

let apply = BigText::builder()
.pixel_size(PixelSize::Sextant)
.style(if *self == UpdateFilterMenuBLock::Start {
Style::default().white().bold()
} else {
Style::default().dark_gray()
})
.lines(vec!["APPLY".into()])
.centered()
.build();
frame.render_widget(apply, apply_block);
}
}
Loading

0 comments on commit 3c8ada0

Please sign in to comment.