Skip to content

Commit 5754d83

Browse files
committed
update filters display order
1 parent afdbb57 commit 5754d83

File tree

2 files changed

+106
-64
lines changed

2 files changed

+106
-64
lines changed

oryx-tui/src/app.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ impl App {
107107
if !self.start_sniffing {
108108
let (
109109
interface_block,
110-
network_filter_block,
111110
transport_filter_block,
111+
network_filter_block,
112112
link_filter_block,
113113
traffic_direction_block,
114114
start_block,
@@ -117,8 +117,8 @@ impl App {
117117
.direction(Direction::Vertical)
118118
.constraints([
119119
Constraint::Length(self.interface.interfaces.len() as u16 + 6),
120-
Constraint::Length(NB_NETWORK_PROTOCOL + 4),
121120
Constraint::Length(NB_TRANSPORT_PROTOCOL + 4),
121+
Constraint::Length(NB_NETWORK_PROTOCOL + 4),
122122
Constraint::Length(NB_LINK_PROTOCOL + 4),
123123
Constraint::Length(6),
124124
Constraint::Length(4),
@@ -245,10 +245,10 @@ impl App {
245245
let widths = [Constraint::Length(10), Constraint::Fill(1)];
246246
let filters = [
247247
Row::new(vec![
248-
Line::styled("Network", Style::new().bold()),
249-
Line::from_iter(NetworkFilter::default().selected_protocols.iter().map(
248+
Line::styled("Transport", Style::new().bold()),
249+
Line::from_iter(TransportFilter::default().selected_protocols.iter().map(
250250
|filter| {
251-
if self.network_filter.applied_protocols.contains(filter) {
251+
if self.transport_filter.applied_protocols.contains(filter) {
252252
Span::styled(
253253
format!(" {} ", filter),
254254
Style::default().light_green(),
@@ -263,10 +263,10 @@ impl App {
263263
)),
264264
]),
265265
Row::new(vec![
266-
Line::styled("Transport", Style::new().bold()),
267-
Line::from_iter(TransportFilter::default().selected_protocols.iter().map(
266+
Line::styled("Network", Style::new().bold()),
267+
Line::from_iter(NetworkFilter::default().selected_protocols.iter().map(
268268
|filter| {
269-
if self.transport_filter.applied_protocols.contains(filter) {
269+
if self.network_filter.applied_protocols.contains(filter) {
270270
Span::styled(
271271
format!(" {} ", filter),
272272
Style::default().light_green(),
@@ -370,17 +370,17 @@ impl App {
370370
.split(layout[1])[1];
371371

372372
let (
373-
network_filter_block,
374373
transport_filter_block,
374+
network_filter_block,
375375
link_filter_block,
376376
traffic_direction_block,
377377
apply_block,
378378
) = {
379379
let chunks = Layout::default()
380380
.direction(Direction::Vertical)
381381
.constraints([
382-
Constraint::Length(NB_NETWORK_PROTOCOL + 4),
383382
Constraint::Length(NB_TRANSPORT_PROTOCOL + 4),
383+
Constraint::Length(NB_NETWORK_PROTOCOL + 4),
384384
Constraint::Length(NB_LINK_PROTOCOL + 4),
385385
Constraint::Length(6),
386386
Constraint::Length(4),
@@ -399,12 +399,13 @@ impl App {
399399
.border_style(Style::default().green()),
400400
block,
401401
);
402-
self.network_filter
403-
.render(frame, network_filter_block, &self.focused_block);
404402

405403
self.transport_filter
406404
.render(frame, transport_filter_block, &self.focused_block);
407405

406+
self.network_filter
407+
.render(frame, network_filter_block, &self.focused_block);
408+
408409
self.link_filter
409410
.render(frame, link_filter_block, &self.focused_block);
410411

oryx-tui/src/handler.rs

Lines changed: 93 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,16 @@ pub fn handle_key_events(
5858

5959
if app.update_filters {
6060
match &app.focused_block {
61-
FocusedBlock::NetworkFilter => {
62-
app.focused_block = FocusedBlock::TransportFilter;
61+
FocusedBlock::TransportFilter => {
62+
app.focused_block = FocusedBlock::NetworkFilter;
63+
app.network_filter.state.select(Some(0));
6364
app.transport_filter.state.select(Some(0));
64-
app.network_filter.state.select(None);
6565
}
6666

67-
FocusedBlock::TransportFilter => {
67+
FocusedBlock::NetworkFilter => {
6868
app.focused_block = FocusedBlock::LinkFilter;
69-
app.traffic_direction_filter.state.select(None);
7069
app.link_filter.state.select(Some(0));
70+
app.network_filter.state.select(None);
7171
}
7272

7373
FocusedBlock::LinkFilter => {
@@ -82,8 +82,7 @@ pub fn handle_key_events(
8282
}
8383

8484
FocusedBlock::Start => {
85-
app.focused_block = FocusedBlock::NetworkFilter;
86-
app.network_filter.state.select(Some(0));
85+
app.focused_block = FocusedBlock::TransportFilter;
8786
}
8887
_ => {}
8988
};
@@ -105,20 +104,20 @@ pub fn handle_key_events(
105104

106105
if app.update_filters {
107106
match &app.focused_block {
108-
FocusedBlock::NetworkFilter => {
109-
app.focused_block = FocusedBlock::Start;
110-
app.network_filter.state.select(None);
111-
}
112-
113107
FocusedBlock::TransportFilter => {
114-
app.focused_block = FocusedBlock::NetworkFilter;
115-
app.network_filter.state.select(Some(0));
108+
app.focused_block = FocusedBlock::Start;
116109
app.transport_filter.state.select(None);
117110
}
118111

119-
FocusedBlock::LinkFilter => {
112+
FocusedBlock::NetworkFilter => {
120113
app.focused_block = FocusedBlock::TransportFilter;
121114
app.transport_filter.state.select(Some(0));
115+
app.network_filter.state.select(None);
116+
}
117+
118+
FocusedBlock::LinkFilter => {
119+
app.focused_block = FocusedBlock::NetworkFilter;
120+
app.network_filter.state.select(Some(0));
122121
app.link_filter.state.select(None);
123122
}
124123

@@ -161,14 +160,21 @@ pub fn handle_key_events(
161160
KeyCode::Char('f') => {
162161
if app.focused_block != FocusedBlock::Help && app.start_sniffing {
163162
app.update_filters = true;
164-
app.focused_block = FocusedBlock::NetworkFilter;
163+
app.focused_block = FocusedBlock::TransportFilter;
164+
165165
app.network_filter.selected_protocols =
166166
app.network_filter.applied_protocols.clone();
167+
167168
app.transport_filter.selected_protocols =
168169
app.transport_filter.applied_protocols.clone();
170+
171+
app.link_filter.selected_protocols =
172+
app.link_filter.applied_protocols.clone();
173+
169174
app.traffic_direction_filter.selected_direction =
170175
app.traffic_direction_filter.applied_direction.clone();
171-
app.network_filter.state = TableState::default().with_selected(0);
176+
177+
app.transport_filter.state = TableState::default().with_selected(0);
172178
}
173179
}
174180

@@ -229,6 +235,21 @@ pub fn handle_key_events(
229235
app.transport_filter.state.select(Some(i));
230236
}
231237

238+
FocusedBlock::LinkFilter => {
239+
let i = match app.link_filter.state.selected() {
240+
Some(i) => {
241+
if i < (NB_LINK_PROTOCOL - 1).into() {
242+
i + 1
243+
} else {
244+
i
245+
}
246+
}
247+
None => 0,
248+
};
249+
250+
app.link_filter.state.select(Some(i));
251+
}
252+
232253
FocusedBlock::TrafficDirection => {
233254
app.traffic_direction_filter.state.select(Some(1));
234255
}
@@ -294,6 +315,21 @@ pub fn handle_key_events(
294315
app.transport_filter.state.select(Some(i));
295316
}
296317

318+
FocusedBlock::LinkFilter => {
319+
let i = match app.link_filter.state.selected() {
320+
Some(i) => {
321+
if i > 1 {
322+
i - 1
323+
} else {
324+
0
325+
}
326+
}
327+
None => 0,
328+
};
329+
330+
app.link_filter.state.select(Some(i));
331+
}
332+
297333
FocusedBlock::TrafficDirection => {
298334
app.traffic_direction_filter.state.select(Some(0));
299335
}
@@ -364,7 +400,7 @@ pub fn handle_key_events(
364400
if app.focused_block != FocusedBlock::Help && app.start_sniffing {
365401
app.update_filters = true;
366402

367-
app.focused_block = FocusedBlock::NetworkFilter;
403+
app.focused_block = FocusedBlock::TransportFilter;
368404

369405
app.network_filter.selected_protocols =
370406
app.network_filter.applied_protocols.clone();
@@ -377,7 +413,7 @@ pub fn handle_key_events(
377413
app.traffic_direction_filter.selected_direction =
378414
app.traffic_direction_filter.applied_direction.clone();
379415

380-
app.network_filter.state = TableState::default().with_selected(0);
416+
app.transport_filter.state = TableState::default().with_selected(0);
381417
}
382418
}
383419

@@ -474,7 +510,7 @@ pub fn handle_key_events(
474510
}
475511

476512
app.start_sniffing = true;
477-
app.focused_block = FocusedBlock::NetworkFilter;
513+
app.focused_block = FocusedBlock::TransportFilter;
478514
} else if app.start_sniffing && app.update_filters {
479515
// Remove egress
480516
if app
@@ -566,16 +602,18 @@ pub fn handle_key_events(
566602

567603
if app.update_filters {
568604
match &app.focused_block {
569-
FocusedBlock::NetworkFilter => {
570-
app.focused_block = FocusedBlock::TransportFilter;
571-
app.transport_filter.state.select(Some(0));
572-
app.network_filter.state.select(None);
573-
}
574605
FocusedBlock::TransportFilter => {
606+
app.focused_block = FocusedBlock::NetworkFilter;
607+
app.network_filter.state.select(Some(0));
608+
app.transport_filter.state.select(None);
609+
}
610+
611+
FocusedBlock::NetworkFilter => {
575612
app.focused_block = FocusedBlock::LinkFilter;
576613
app.link_filter.state.select(Some(0));
577-
app.transport_filter.state.select(None);
614+
app.network_filter.state.select(None);
578615
}
616+
579617
FocusedBlock::LinkFilter => {
580618
app.focused_block = FocusedBlock::TrafficDirection;
581619
app.traffic_direction_filter.state.select(Some(0));
@@ -588,8 +626,8 @@ pub fn handle_key_events(
588626
}
589627

590628
FocusedBlock::Start => {
591-
app.focused_block = FocusedBlock::NetworkFilter;
592-
app.network_filter.state.select(Some(0));
629+
app.focused_block = FocusedBlock::TransportFilter;
630+
app.transport_filter.state.select(Some(0));
593631
}
594632
_ => {}
595633
};
@@ -604,23 +642,26 @@ pub fn handle_key_events(
604642
} else {
605643
match &app.focused_block {
606644
FocusedBlock::Interface => {
607-
app.focused_block = FocusedBlock::NetworkFilter;
608-
app.previous_focused_block = app.focused_block;
609-
app.interface.state.select(None);
610-
app.network_filter.state.select(Some(0));
611-
}
612-
FocusedBlock::NetworkFilter => {
613645
app.focused_block = FocusedBlock::TransportFilter;
614646
app.previous_focused_block = app.focused_block;
647+
app.interface.state.select(None);
615648
app.transport_filter.state.select(Some(0));
616-
app.network_filter.state.select(None);
617649
}
650+
618651
FocusedBlock::TransportFilter => {
652+
app.focused_block = FocusedBlock::NetworkFilter;
653+
app.previous_focused_block = app.focused_block;
654+
app.network_filter.state.select(Some(0));
655+
app.transport_filter.state.select(None);
656+
}
657+
658+
FocusedBlock::NetworkFilter => {
619659
app.focused_block = FocusedBlock::LinkFilter;
620660
app.previous_focused_block = app.focused_block;
621661
app.link_filter.state.select(Some(0));
622-
app.transport_filter.state.select(None);
662+
app.network_filter.state.select(None);
623663
}
664+
624665
FocusedBlock::LinkFilter => {
625666
app.focused_block = FocusedBlock::TrafficDirection;
626667
app.previous_focused_block = app.focused_block;
@@ -652,20 +693,20 @@ pub fn handle_key_events(
652693

653694
if app.update_filters {
654695
match &app.focused_block {
655-
FocusedBlock::NetworkFilter => {
656-
app.focused_block = FocusedBlock::Start;
657-
app.network_filter.state.select(None);
658-
}
659-
660696
FocusedBlock::TransportFilter => {
661-
app.focused_block = FocusedBlock::NetworkFilter;
662-
app.network_filter.state.select(Some(0));
697+
app.focused_block = FocusedBlock::Start;
663698
app.transport_filter.state.select(None);
664699
}
665700

666-
FocusedBlock::LinkFilter => {
701+
FocusedBlock::NetworkFilter => {
667702
app.focused_block = FocusedBlock::TransportFilter;
668703
app.transport_filter.state.select(Some(0));
704+
app.network_filter.state.select(None);
705+
}
706+
707+
FocusedBlock::LinkFilter => {
708+
app.focused_block = FocusedBlock::NetworkFilter;
709+
app.network_filter.state.select(Some(0));
669710
app.link_filter.state.select(None);
670711
}
671712

@@ -695,21 +736,21 @@ pub fn handle_key_events(
695736
app.interface.state.select(None);
696737
}
697738

698-
FocusedBlock::NetworkFilter => {
739+
FocusedBlock::TransportFilter => {
699740
app.focused_block = FocusedBlock::Interface;
700741
app.interface.state.select(Some(0));
701-
app.network_filter.state.select(None);
702-
}
703-
704-
FocusedBlock::TransportFilter => {
705-
app.focused_block = FocusedBlock::NetworkFilter;
706-
app.network_filter.state.select(Some(0));
707742
app.transport_filter.state.select(None);
708743
}
709744

710-
FocusedBlock::LinkFilter => {
745+
FocusedBlock::NetworkFilter => {
711746
app.focused_block = FocusedBlock::TransportFilter;
712747
app.transport_filter.state.select(Some(0));
748+
app.network_filter.state.select(None);
749+
}
750+
751+
FocusedBlock::LinkFilter => {
752+
app.focused_block = FocusedBlock::NetworkFilter;
753+
app.network_filter.state.select(Some(0));
713754
app.link_filter.state.select(None);
714755
}
715756

0 commit comments

Comments
 (0)