Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a4b991a

Browse files
committedOct 9, 2024·
Add help footer section
1 parent 9cc4ffe commit a4b991a

File tree

3 files changed

+227
-18
lines changed

3 files changed

+227
-18
lines changed
 

‎oryx-tui/src/filter.rs

+96-7
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ use oryx_common::{
1818
RawPacket,
1919
};
2020
use ratatui::{
21-
layout::{Alignment, Constraint, Direction, Flex, Layout, Rect},
21+
layout::{Alignment, Constraint, Direction, Flex, Layout, Margin, Rect},
2222
style::{Style, Stylize},
23-
text::{Line, Span},
23+
text::{Line, Span, Text},
2424
widgets::{Block, BorderType, Borders, Clear, Padding, Row, Table, TableState},
2525
Frame,
2626
};
@@ -570,6 +570,16 @@ impl Filter {
570570
}
571571

572572
pub fn render_on_setup(&mut self, frame: &mut Frame) {
573+
let (filters_block, help_block) = {
574+
let chunks = Layout::default()
575+
.direction(Direction::Vertical)
576+
.constraints([Constraint::Fill(1), Constraint::Length(3)])
577+
.flex(ratatui::layout::Flex::SpaceBetween)
578+
.split(frame.area());
579+
580+
(chunks[0], chunks[1])
581+
};
582+
573583
let (
574584
interface_block,
575585
transport_filter_block,
@@ -590,7 +600,7 @@ impl Filter {
590600
])
591601
.margin(1)
592602
.flex(Flex::SpaceAround)
593-
.split(frame.area());
603+
.split(filters_block);
594604
(
595605
chunks[0], chunks[1], chunks[2], chunks[3], chunks[4], chunks[5],
596606
)
@@ -638,6 +648,38 @@ impl Filter {
638648
.build();
639649

640650
frame.render_widget(start, start_block);
651+
652+
let help = Text::from(vec![
653+
Line::from(""),
654+
Line::from(vec![
655+
Span::from("k,⬆").bold(),
656+
Span::from(": Scroll up").bold(),
657+
Span::from(" | ").bold(),
658+
Span::from("j,⬇").bold(),
659+
Span::from(": Scroll down").bold(),
660+
Span::from(" | ").bold(),
661+
Span::from("󱞦 ").bold(),
662+
Span::from(": Apply").bold(),
663+
Span::from(" | ").bold(),
664+
Span::from(" ").bold(),
665+
Span::from(": Naviguate").bold(),
666+
]),
667+
])
668+
.centered();
669+
frame.render_widget(
670+
Block::new()
671+
.borders(Borders::ALL)
672+
.blue()
673+
.border_type(BorderType::Rounded),
674+
help_block,
675+
);
676+
frame.render_widget(
677+
help,
678+
help_block.inner(Margin {
679+
horizontal: 1,
680+
vertical: 0,
681+
}),
682+
);
641683
}
642684

643685
pub fn render_on_sniffing(&mut self, frame: &mut Frame, block: Rect) {
@@ -762,12 +804,22 @@ impl Filter {
762804
.direction(Direction::Horizontal)
763805
.constraints([
764806
Constraint::Fill(1),
765-
Constraint::Length(60),
807+
Constraint::Max(82),
766808
Constraint::Fill(1),
767809
])
768810
.flex(ratatui::layout::Flex::SpaceBetween)
769811
.split(layout[1])[1];
770812

813+
let (filters_block, help_block) = {
814+
let chunks = Layout::default()
815+
.direction(Direction::Vertical)
816+
.constraints([Constraint::Fill(1), Constraint::Length(3)])
817+
.flex(ratatui::layout::Flex::SpaceBetween)
818+
.split(block);
819+
820+
(chunks[0], chunks[1])
821+
};
822+
771823
let (
772824
transport_filter_block,
773825
network_filter_block,
@@ -778,6 +830,7 @@ impl Filter {
778830
let chunks = Layout::default()
779831
.direction(Direction::Vertical)
780832
.constraints([
833+
Constraint::Length(1),
781834
Constraint::Length(NB_TRANSPORT_PROTOCOL + 4),
782835
Constraint::Length(NB_NETWORK_PROTOCOL + 4),
783836
Constraint::Length(NB_LINK_PROTOCOL + 4),
@@ -786,17 +839,18 @@ impl Filter {
786839
])
787840
.margin(1)
788841
.flex(Flex::SpaceBetween)
789-
.split(block);
790-
(chunks[0], chunks[1], chunks[2], chunks[3], chunks[4])
842+
.split(filters_block);
843+
(chunks[1], chunks[2], chunks[3], chunks[4], chunks[5])
791844
};
792845

793846
frame.render_widget(Clear, block);
847+
794848
frame.render_widget(
795849
Block::new()
796850
.borders(Borders::all())
797851
.border_type(BorderType::Thick)
798852
.border_style(Style::default().green()),
799-
block,
853+
filters_block,
800854
);
801855

802856
self.network.render(
@@ -834,5 +888,40 @@ impl Filter {
834888
.centered()
835889
.build();
836890
frame.render_widget(apply, apply_block);
891+
892+
let help = Text::from(vec![
893+
Line::from(""),
894+
Line::from(vec![
895+
Span::from("k,⬆").bold(),
896+
Span::from(": Move up").bold(),
897+
Span::from(" | ").bold(),
898+
Span::from("j,⬇").bold(),
899+
Span::from(": Move down").bold(),
900+
Span::from(" | ").bold(),
901+
Span::from("󱊷 ").bold(),
902+
Span::from(": Discard").bold(),
903+
Span::from(" | ").bold(),
904+
Span::from("󱞦 ").bold(),
905+
Span::from(": Apply").bold(),
906+
Span::from(" | ").bold(),
907+
Span::from(" ").bold(),
908+
Span::from(": Naviguate").bold(),
909+
]),
910+
])
911+
.centered();
912+
frame.render_widget(
913+
Block::new()
914+
.borders(Borders::ALL)
915+
.blue()
916+
.border_type(BorderType::Rounded),
917+
help_block,
918+
);
919+
frame.render_widget(
920+
help,
921+
help_block.inner(Margin {
922+
horizontal: 1,
923+
vertical: 0,
924+
}),
925+
);
837926
}
838927
}

‎oryx-tui/src/section.rs

+85-7
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ use firewall::{Firewall, FirewallSignal};
1111

1212
use inspection::Inspection;
1313
use ratatui::{
14-
layout::{Alignment, Rect},
14+
layout::{Alignment, Constraint, Direction, Layout, Margin, Rect},
1515
style::{Color, Style, Stylize},
16-
text::{Line, Span},
16+
text::{Line, Span, Text},
1717
widgets::{Block, BorderType, Borders, Padding},
1818
Frame,
1919
};
@@ -89,6 +89,72 @@ impl Section {
8989
}
9090
}
9191

92+
fn render_footer_help(&self, frame: &mut Frame, block: Rect) {
93+
let message = match self.focused_section {
94+
FocusedSection::Inspection => Line::from(vec![
95+
Span::from("k,⬆").bold(),
96+
Span::from(": Move up").bold(),
97+
Span::from(" | ").bold(),
98+
Span::from("j,⬇").bold(),
99+
Span::from(": Move down").bold(),
100+
Span::from(" | ").bold(),
101+
Span::from("/").bold(),
102+
Span::from(": Search").bold(),
103+
Span::from(" | ").bold(),
104+
Span::from("i").bold(),
105+
Span::from(": Infos").bold(),
106+
Span::from(" | ").bold(),
107+
Span::from("f").bold(),
108+
Span::from(": Filters").bold(),
109+
Span::from(" | ").bold(),
110+
Span::from(" ").bold(),
111+
Span::from(": Naviguate").bold(),
112+
]),
113+
FocusedSection::Firewall => Line::from(vec![
114+
Span::from("k,⬆").bold(),
115+
Span::from(": Move up").bold(),
116+
Span::from(" | ").bold(),
117+
Span::from("j,⬇").bold(),
118+
Span::from(": Move down").bold(),
119+
Span::from(" | ").bold(),
120+
Span::from("n").bold(),
121+
Span::from(": New Rule").bold(),
122+
Span::from(" | ").bold(),
123+
Span::from("d").bold(),
124+
Span::from(": Delete Rule").bold(),
125+
Span::from(" | ").bold(),
126+
Span::from("f").bold(),
127+
Span::from(": Filters").bold(),
128+
Span::from(" | ").bold(),
129+
Span::from(" ").bold(),
130+
Span::from(": Naviguate").bold(),
131+
]),
132+
_ => Line::from(vec![
133+
Span::from("f").bold(),
134+
Span::from(": Filters").bold(),
135+
Span::from(" | ").bold(),
136+
Span::from(" ").bold(),
137+
Span::from(": Naviguate").bold(),
138+
]),
139+
};
140+
141+
let help = Text::from(vec![Line::from(""), message]).centered();
142+
frame.render_widget(
143+
Block::new()
144+
.borders(Borders::ALL)
145+
.blue()
146+
.border_type(BorderType::Rounded),
147+
block,
148+
);
149+
frame.render_widget(
150+
help,
151+
block.inner(Margin {
152+
horizontal: 1,
153+
vertical: 0,
154+
}),
155+
);
156+
}
157+
92158
pub fn render_header(&mut self, frame: &mut Frame, block: Rect) {
93159
frame.render_widget(
94160
Block::default()
@@ -110,12 +176,24 @@ impl Section {
110176
);
111177
}
112178
pub fn render(&mut self, frame: &mut Frame, block: Rect, network_interace: &str) {
113-
self.render_header(frame, block);
179+
let (section_block, help_block) = {
180+
let chunks = Layout::default()
181+
.direction(Direction::Vertical)
182+
.constraints([Constraint::Fill(1), Constraint::Length(3)])
183+
.flex(ratatui::layout::Flex::SpaceBetween)
184+
.split(block);
185+
186+
(chunks[0], chunks[1])
187+
};
188+
189+
self.render_header(frame, section_block);
190+
self.render_footer_help(frame, help_block);
191+
114192
match self.focused_section {
115-
FocusedSection::Inspection => self.inspection.render(frame, block),
116-
FocusedSection::Stats => self.stats.render(frame, block, network_interace),
117-
FocusedSection::Alerts => self.alert.render(frame, block),
118-
FocusedSection::Firewall => self.firewall.render(frame, block),
193+
FocusedSection::Inspection => self.inspection.render(frame, section_block),
194+
FocusedSection::Stats => self.stats.render(frame, section_block, network_interace),
195+
FocusedSection::Alerts => self.alert.render(frame, section_block),
196+
FocusedSection::Firewall => self.firewall.render(frame, section_block),
119197
}
120198
}
121199

‎oryx-tui/src/section/firewall.rs

+46-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ use oryx_common::MAX_FIREWALL_RULES;
44
use ratatui::{
55
layout::{Constraint, Direction, Flex, Layout, Margin, Rect},
66
style::{Color, Style, Stylize},
7-
text::{Line, Text},
8-
widgets::{Block, Borders, Cell, Clear, HighlightSpacing, Padding, Row, Table, TableState},
7+
text::{Line, Span, Text},
8+
widgets::{
9+
Block, BorderType, Borders, Cell, Clear, HighlightSpacing, Padding, Row, Table, TableState,
10+
},
911
Frame,
1012
};
1113
use std::{net::IpAddr, num::ParseIntError, str::FromStr};
@@ -139,7 +141,7 @@ impl UserInput {
139141
.direction(Direction::Vertical)
140142
.constraints([
141143
Constraint::Fill(1),
142-
Constraint::Length(9),
144+
Constraint::Length(12),
143145
Constraint::Fill(1),
144146
])
145147
.flex(ratatui::layout::Flex::SpaceBetween)
@@ -155,6 +157,16 @@ impl UserInput {
155157
.flex(ratatui::layout::Flex::SpaceBetween)
156158
.split(layout[1])[1];
157159

160+
let (user_input_block, help_block) = {
161+
let chunks = Layout::default()
162+
.direction(Direction::Vertical)
163+
.constraints([Constraint::Fill(1), Constraint::Length(3)])
164+
.flex(ratatui::layout::Flex::SpaceBetween)
165+
.split(block);
166+
167+
(chunks[0], chunks[1])
168+
};
169+
158170
let rows = [
159171
Row::new(vec![
160172
Cell::from(self.name.field.to_string())
@@ -253,6 +265,7 @@ impl UserInput {
253265
.block(
254266
Block::default()
255267
.title(" Firewall Rule ")
268+
.bold()
256269
.title_alignment(ratatui::layout::Alignment::Center)
257270
.borders(Borders::all())
258271
.border_type(ratatui::widgets::BorderType::Thick)
@@ -261,7 +274,36 @@ impl UserInput {
261274
);
262275

263276
frame.render_widget(Clear, block);
264-
frame.render_widget(table, block);
277+
frame.render_widget(table, user_input_block);
278+
279+
let help = Text::from(vec![
280+
Line::from(""),
281+
Line::from(vec![
282+
Span::from("󱊷 ").bold(),
283+
Span::from(": Discard").bold(),
284+
Span::from(" | ").bold(),
285+
Span::from("󱞦 ").bold(),
286+
Span::from(": Save").bold(),
287+
Span::from(" | ").bold(),
288+
Span::from(" ").bold(),
289+
Span::from(": Naviguate").bold(),
290+
]),
291+
])
292+
.centered();
293+
frame.render_widget(
294+
Block::new()
295+
.borders(Borders::ALL)
296+
.blue()
297+
.border_type(BorderType::Rounded),
298+
help_block,
299+
);
300+
frame.render_widget(
301+
help,
302+
help_block.inner(Margin {
303+
horizontal: 1,
304+
vertical: 0,
305+
}),
306+
);
265307
}
266308
}
267309

0 commit comments

Comments
 (0)
Please sign in to comment.