Skip to content

Commit 4edae57

Browse files
authored
refactor: rearrange sections (#64)
* rearrange sections for station * remove address column and add missing columns titles * shorten help message length * put the adapter popup in the center * rearrange section for ap
1 parent 944ad00 commit 4edae57

File tree

13 files changed

+309
-343
lines changed

13 files changed

+309
-343
lines changed

Cargo.lock

Lines changed: 220 additions & 175 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/adapter.rs

Lines changed: 64 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,21 @@ impl Adapter {
8989
None => false,
9090
};
9191

92-
let (device_block, access_point_block, connected_devices_block, help_block) = {
92+
let (access_point_block, connected_devices_block, device_block, help_block) = {
9393
let chunks = Layout::default()
9494
.direction(Direction::Vertical)
9595
.constraints(if any_connected_devices {
9696
&[
97-
Constraint::Percentage(33),
98-
Constraint::Percentage(33),
99-
Constraint::Percentage(33),
97+
Constraint::Length(5),
98+
Constraint::Fill(1),
99+
Constraint::Length(5),
100100
Constraint::Length(1),
101101
]
102102
} else {
103103
&[
104-
Constraint::Percentage(50),
105-
Constraint::Percentage(50),
106104
Constraint::Fill(1),
105+
Constraint::Length(0),
106+
Constraint::Length(5),
107107
Constraint::Length(1),
108108
]
109109
})
@@ -480,127 +480,21 @@ impl Adapter {
480480
color_mode: ColorMode,
481481
focused_block: FocusedBlock,
482482
) {
483-
let (device_block, station_block, known_networks_block, new_networks_block, help_block) = {
483+
let (known_networks_block, new_networks_block, device_block, help_block) = {
484484
let chunks = Layout::default()
485485
.direction(Direction::Vertical)
486486
.constraints([
487-
Constraint::Length(5),
488-
Constraint::Length(5),
489487
Constraint::Min(5),
490488
Constraint::Min(5),
489+
Constraint::Length(5),
491490
Constraint::Length(1),
492491
])
493492
.margin(1)
494493
.split(frame.area());
495-
(chunks[0], chunks[1], chunks[2], chunks[3], chunks[4])
494+
(chunks[0], chunks[1], chunks[2], chunks[3])
496495
};
497496

498497
// Device
499-
let row = Row::new(vec![
500-
Line::from(self.device.name.clone()).centered(),
501-
Line::from("station").centered(),
502-
{
503-
if self.device.is_powered {
504-
Line::from("On").centered()
505-
} else {
506-
Line::from("Off").centered()
507-
}
508-
},
509-
Line::from(self.device.address.clone()).centered(),
510-
]);
511-
512-
let widths = [
513-
Constraint::Length(15),
514-
Constraint::Length(8),
515-
Constraint::Length(10),
516-
Constraint::Length(17),
517-
];
518-
519-
let device_table = Table::new(vec![row], widths)
520-
.header({
521-
if focused_block == FocusedBlock::Device {
522-
Row::new(vec![
523-
Line::from("Name").yellow().centered(),
524-
Line::from("Mode").yellow().centered(),
525-
Line::from("Powered").yellow().centered(),
526-
Line::from("Address").yellow().centered(),
527-
])
528-
.style(Style::new().bold())
529-
.bottom_margin(1)
530-
} else {
531-
Row::new(vec![
532-
Line::from("Name")
533-
.style(match color_mode {
534-
ColorMode::Dark => Style::default().fg(Color::White),
535-
ColorMode::Light => Style::default().fg(Color::Black),
536-
})
537-
.centered(),
538-
Line::from("Mode")
539-
.style(match color_mode {
540-
ColorMode::Dark => Style::default().fg(Color::White),
541-
ColorMode::Light => Style::default().fg(Color::Black),
542-
})
543-
.centered(),
544-
Line::from("Powered")
545-
.style(match color_mode {
546-
ColorMode::Dark => Style::default().fg(Color::White),
547-
ColorMode::Light => Style::default().fg(Color::Black),
548-
})
549-
.centered(),
550-
Line::from("Address")
551-
.style(match color_mode {
552-
ColorMode::Dark => Style::default().fg(Color::White),
553-
ColorMode::Light => Style::default().fg(Color::Black),
554-
})
555-
.centered(),
556-
])
557-
.style(Style::new().bold())
558-
.bottom_margin(1)
559-
}
560-
})
561-
.block(
562-
Block::default()
563-
.title(" Device ")
564-
.title_style({
565-
if focused_block == FocusedBlock::Device {
566-
Style::default().bold()
567-
} else {
568-
Style::default()
569-
}
570-
})
571-
.borders(Borders::ALL)
572-
.border_style({
573-
if focused_block == FocusedBlock::Device {
574-
Style::default().fg(Color::Green)
575-
} else {
576-
Style::default()
577-
}
578-
})
579-
.border_type({
580-
if focused_block == FocusedBlock::Device {
581-
BorderType::Thick
582-
} else {
583-
BorderType::default()
584-
}
585-
})
586-
.padding(Padding::horizontal(1)),
587-
)
588-
.column_spacing(2)
589-
.flex(Flex::SpaceBetween)
590-
.style(match color_mode {
591-
ColorMode::Dark => Style::default().fg(Color::White),
592-
ColorMode::Light => Style::default().fg(Color::Black),
593-
})
594-
.row_highlight_style(if focused_block == FocusedBlock::Device {
595-
Style::default().bg(Color::DarkGray).fg(Color::White)
596-
} else {
597-
Style::default()
598-
});
599-
600-
let mut device_state = TableState::default().with_selected(0);
601-
frame.render_stateful_widget(device_table, device_block, &mut device_state);
602-
603-
// Station
604498

605499
let station_frequency = {
606500
match self.device.station.as_ref() {
@@ -643,26 +537,40 @@ impl Adapter {
643537
station_state = station.state.clone();
644538
station_is_scanning = station.is_scanning.clone().to_string();
645539
}
646-
let row = vec![
540+
541+
let row = Row::new(vec![
542+
Line::from(self.device.name.clone()).centered(),
543+
Line::from("station").centered(),
544+
{
545+
if self.device.is_powered {
546+
Line::from("On").centered()
547+
} else {
548+
Line::from("Off").centered()
549+
}
550+
},
647551
Line::from(station_state).centered(),
648552
Line::from(station_is_scanning).centered(),
649553
Line::from(station_frequency).centered(),
650554
Line::from(station_security).centered(),
651-
];
652-
653-
let row = Row::new(row);
555+
]);
654556

655557
let widths = [
558+
Constraint::Length(10),
559+
Constraint::Length(8),
560+
Constraint::Length(10),
656561
Constraint::Length(12),
657562
Constraint::Length(10),
658563
Constraint::Length(10),
659564
Constraint::Length(15),
660565
];
661566

662-
let station_table = Table::new(vec![row], widths)
567+
let device_table = Table::new(vec![row], widths)
663568
.header({
664-
if focused_block == FocusedBlock::Station {
569+
if focused_block == FocusedBlock::Device {
665570
Row::new(vec![
571+
Line::from("Name").yellow().centered(),
572+
Line::from("Mode").yellow().centered(),
573+
Line::from("Powered").yellow().centered(),
666574
Line::from("State").yellow().centered(),
667575
Line::from("Scanning").yellow().centered(),
668576
Line::from("Frequency").yellow().centered(),
@@ -672,6 +580,24 @@ impl Adapter {
672580
.bottom_margin(1)
673581
} else {
674582
Row::new(vec![
583+
Line::from("Name")
584+
.style(match color_mode {
585+
ColorMode::Dark => Style::default().fg(Color::White),
586+
ColorMode::Light => Style::default().fg(Color::Black),
587+
})
588+
.centered(),
589+
Line::from("Mode")
590+
.style(match color_mode {
591+
ColorMode::Dark => Style::default().fg(Color::White),
592+
ColorMode::Light => Style::default().fg(Color::Black),
593+
})
594+
.centered(),
595+
Line::from("Powered")
596+
.style(match color_mode {
597+
ColorMode::Dark => Style::default().fg(Color::White),
598+
ColorMode::Light => Style::default().fg(Color::Black),
599+
})
600+
.centered(),
675601
Line::from("State")
676602
.style(match color_mode {
677603
ColorMode::Dark => Style::default().fg(Color::White),
@@ -703,45 +629,45 @@ impl Adapter {
703629
})
704630
.block(
705631
Block::default()
706-
.title(" Station ")
632+
.title(" Device ")
707633
.title_style({
708-
if focused_block == FocusedBlock::Station {
634+
if focused_block == FocusedBlock::Device {
709635
Style::default().bold()
710636
} else {
711637
Style::default()
712638
}
713639
})
714640
.borders(Borders::ALL)
715641
.border_style({
716-
if focused_block == FocusedBlock::Station {
642+
if focused_block == FocusedBlock::Device {
717643
Style::default().fg(Color::Green)
718644
} else {
719645
Style::default()
720646
}
721647
})
722648
.border_type({
723-
if focused_block == FocusedBlock::Station {
649+
if focused_block == FocusedBlock::Device {
724650
BorderType::Thick
725651
} else {
726652
BorderType::default()
727653
}
728654
})
729655
.padding(Padding::horizontal(1)),
730656
)
731-
.column_spacing(2)
657+
.column_spacing(1)
732658
.flex(Flex::SpaceBetween)
733659
.style(match color_mode {
734660
ColorMode::Dark => Style::default().fg(Color::White),
735661
ColorMode::Light => Style::default().fg(Color::Black),
736662
})
737-
.row_highlight_style(if focused_block == FocusedBlock::Station {
663+
.row_highlight_style(if focused_block == FocusedBlock::Device {
738664
Style::default().bg(Color::DarkGray).fg(Color::White)
739665
} else {
740666
Style::default()
741667
});
742668

743-
let mut station_state = TableState::default().with_selected(0);
744-
frame.render_stateful_widget(station_table, station_block, &mut station_state);
669+
let mut device_state = TableState::default().with_selected(0);
670+
frame.render_stateful_widget(device_table, device_block, &mut device_state);
745671

746672
// Known networks
747673
let known_networks = if let Some(station) = self.device.station.as_ref() {
@@ -1052,16 +978,6 @@ impl Adapter {
1052978
Span::from("⇄").bold(),
1053979
Span::from(" Nav"),
1054980
]),
1055-
FocusedBlock::Station => Line::from(vec![
1056-
Span::from(self.config.station.start_scanning.to_string()).bold(),
1057-
Span::from(" Scan"),
1058-
Span::from(" | "),
1059-
Span::from("ctrl+r").bold(),
1060-
Span::from(" Switch Mode"),
1061-
Span::from(" | "),
1062-
Span::from("⇄").bold(),
1063-
Span::from(" Nav"),
1064-
]),
1065981
FocusedBlock::KnownNetworks => Line::from(vec![
1066982
Span::from("k,").bold(),
1067983
Span::from(" Up"),
@@ -1075,7 +991,7 @@ impl Adapter {
1075991
self.config.station.toggle_connect.to_string()
1076992
})
1077993
.bold(),
1078-
Span::from(" Connect/Disconnect"),
994+
Span::from(" Dis/connect"),
1079995
Span::from(" | "),
1080996
Span::from(self.config.station.known_network.remove.to_string()).bold(),
1081997
Span::from(" Remove"),
@@ -1088,7 +1004,10 @@ impl Adapter {
10881004
.to_string(),
10891005
)
10901006
.bold(),
1091-
Span::from(" Toggle Autoconnect"),
1007+
Span::from(" Autoconnect"),
1008+
Span::from(" | "),
1009+
Span::from(self.config.station.start_scanning.to_string()).bold(),
1010+
Span::from(" Scan"),
10921011
Span::from(" | "),
10931012
Span::from("󱊷 ").bold(),
10941013
Span::from(" Discard"),
@@ -1109,6 +1028,9 @@ impl Adapter {
11091028
Span::from("󱁐 ").bold(),
11101029
Span::from(" Connect"),
11111030
Span::from(" | "),
1031+
Span::from(self.config.station.start_scanning.to_string()).bold(),
1032+
Span::from(" Scan"),
1033+
Span::from(" | "),
11121034
Span::from("󱊷 ").bold(),
11131035
Span::from(" Discard"),
11141036
Span::from(" | "),
@@ -1135,7 +1057,7 @@ impl Adapter {
11351057
.constraints([
11361058
Constraint::Fill(1),
11371059
Constraint::Length(9),
1138-
Constraint::Fill(5),
1060+
Constraint::Fill(1),
11391061
])
11401062
.flex(Flex::Start)
11411063
.split(frame.area());

src/app.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ pub type AppResult<T> = std::result::Result<T, Box<dyn Error>>;
2525
#[derive(Debug, Clone, Copy, PartialEq)]
2626
pub enum FocusedBlock {
2727
Device,
28-
Station,
2928
AccessPoint,
3029
KnownNetworks,
3130
NewNetworks,
@@ -143,9 +142,14 @@ impl App {
143142
Ok(_) | Err(_) => ColorMode::Dark,
144143
};
145144

145+
let focused_block = match current_mode {
146+
Mode::Station => FocusedBlock::KnownNetworks,
147+
_ => FocusedBlock::AccessPoint,
148+
};
149+
146150
Ok(Self {
147151
running: true,
148-
focused_block: FocusedBlock::Device,
152+
focused_block,
149153
color_mode,
150154
notifications: Vec::new(),
151155
session,

src/device.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use iwdrs::{device::Device as iwdDevice, modes::Mode, session::Session};
55
use tokio::sync::mpsc::UnboundedSender;
66

77
use crate::{
8-
ap::AccessPoint, app::AppResult, event::Event, notification::Notification, station::Station,
8+
app::AppResult, event::Event, mode::ap::AccessPoint, mode::station::Station,
9+
notification::Notification,
910
};
1011

1112
#[derive(Debug, Clone)]

0 commit comments

Comments
 (0)