Skip to content

Commit

Permalink
layout update & add tabs enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Chleba committed May 2, 2024
1 parent 8db619c commit b1085d2
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/components/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ impl Interfaces {
let active_interface = &self.active_interfaces[self.active_interface_index];
let header = Row::new(vec!["", "name", "mac", "ipv4", "ipv6"])
.style(Style::default().fg(Color::Yellow))
.bottom_margin(1);
.height(1);
// .bottom_margin(1);
let mut rows = Vec::new();
for w in &self.interfaces {
let mut active = String::from("");
Expand Down Expand Up @@ -158,7 +159,6 @@ impl Interfaces {
.header(header)
.block(
Block::default()
// .title("|Interfaces|")
.title(Line::from(vec![
Span::styled("|Inter", Style::default().fg(Color::Yellow)),
Span::styled("f", Style::default().fg(Color::Red)),
Expand All @@ -168,7 +168,7 @@ impl Interfaces {
.title_style(Style::default().fg(Color::Yellow))
.title_alignment(Alignment::Right)
.borders(Borders::ALL)
.padding(Padding::new(1, 0, 1, 0)),
.padding(Padding::new(0, 0, 1, 0)),
)
.column_spacing(1);
table
Expand Down
11 changes: 9 additions & 2 deletions src/components/packetdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,11 +778,15 @@ impl PacketDump {
fn make_table<'a>(rows: Vec<Row<'a>>, packet_type: PacketTypeEnum) -> Table<'a> {
let header = Row::new(vec!["time", "packet log"])
.style(Style::default().fg(Color::Yellow))
.top_margin(1)
.bottom_margin(1);

let mut type_titles = vec![
Span::styled("|", Style::default().fg(Color::Yellow)),
String::from(char::from_u32(0x25c0).unwrap_or('<')).into(),
Span::styled(
String::from(char::from_u32(0x25c0).unwrap_or('<')),
Style::default().fg(Color::Red),
),
];
let mut enum_titles = PacketTypeEnum::iter()
.enumerate()
Expand All @@ -799,7 +803,10 @@ impl PacketDump {
})
.collect::<Vec<Span>>();
type_titles.append(&mut enum_titles);
type_titles.push(String::from(char::from_u32(0x25b6).unwrap_or('>')).into());
type_titles.push(Span::styled(
String::from(char::from_u32(0x25b6).unwrap_or('>')),
Style::default().fg(Color::Red),
));
type_titles.push(Span::styled("|", Style::default().fg(Color::Yellow)));

let table = Table::new(rows, [Constraint::Min(10), Constraint::Percentage(100)])
Expand Down
24 changes: 18 additions & 6 deletions src/components/wifi_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,21 @@ impl WifiInterface {
.unwrap_or(&"")
.parse::<String>()
.unwrap_or(String::from("")),
ssid: hash.get("ssid").unwrap_or(&"").parse::<String>().unwrap_or(String::from("")),
ifindex: hash.get("ifindex").unwrap_or(&"").parse::<u8>().unwrap_or(0),
mac: hash.get("addr").unwrap_or(&"").parse::<String>().unwrap_or(String::from("")),
ssid: hash
.get("ssid")
.unwrap_or(&"")
.parse::<String>()
.unwrap_or(String::from("")),
ifindex: hash
.get("ifindex")
.unwrap_or(&"")
.parse::<u8>()
.unwrap_or(0),
mac: hash
.get("addr")
.unwrap_or(&"")
.parse::<String>()
.unwrap_or(String::from("")),
channel: hash
.get("channel")
.unwrap_or(&"")
Expand Down Expand Up @@ -155,11 +167,11 @@ impl WifiInterface {

let list = List::new(items).block(
Block::default()
.borders(Borders::ALL)
.borders(Borders::TOP)
.title("|WiFi Interface|")
.border_style(Style::default().fg(Color::Rgb(100, 100, 100)))
// .border_type(BorderType::Rounded)
.title_style(Style::default().fg(Color::Yellow))
.padding(Padding::new(2, 0, 0, 0))
.title_alignment(Alignment::Right),
);

Expand Down Expand Up @@ -258,7 +270,7 @@ impl Component for WifiInterface {
.split(area);
let rect = Rect::new(
(area.width / 2) + 1,
(layout[0].y + layout[0].height) - 4,
(layout[0].y + layout[0].height) - 3,
(area.width / 2) - 2,
4,
);
Expand Down
6 changes: 3 additions & 3 deletions src/components/wifi_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ impl WifiScan {

fn make_table(&mut self) -> Table {
let header = Row::new(vec!["time", "ssid", "ch", "mac", "signal"])
.style(Style::default().fg(Color::Yellow))
.bottom_margin(1);
.style(Style::default().fg(Color::Yellow));
// .bottom_margin(1);
let mut rows = Vec::new();
for w in &self.wifis {
let s_clamp = w.signal.max(MIN_DBM).min(MAX_DBM);
Expand Down Expand Up @@ -152,7 +152,7 @@ impl WifiScan {
)
.border_style(Style::default().fg(Color::Rgb(100, 100, 100)))
.borders(Borders::ALL)
.padding(Padding::new(1, 0, 1, 0)),
.padding(Padding::new(0, 0, 1, 0)),
)
.column_spacing(1);
table
Expand Down
11 changes: 11 additions & 0 deletions src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ pub enum PacketsInfoTypesEnum {
Icmp6(ICMP6PacketInfo),
}

#[derive(Default, Clone, Copy, Display, FromRepr, EnumIter, EnumCount, PartialEq, Debug)]
pub enum TabsEnum {
#[default]
#[strum(to_string = "Discovery")]
Discovery,
#[strum(to_string = "Packets")]
Packets,
#[strum(to_string = "Ports")]
Ports,
}

#[derive(Default, Clone, Copy, Display, FromRepr, EnumIter, EnumCount, PartialEq, Debug)]
pub enum PacketTypeEnum {
#[default]
Expand Down

0 comments on commit b1085d2

Please sign in to comment.