Skip to content

Commit 25418f0

Browse files
committed
refactor + rearrange sections
1 parent 944ad00 commit 25418f0

File tree

13 files changed

+288
-337
lines changed

13 files changed

+288
-337
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: 43 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -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,43 @@ 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+
},
551+
Line::from(self.device.address.clone()).centered(),
647552
Line::from(station_state).centered(),
648553
Line::from(station_is_scanning).centered(),
649554
Line::from(station_frequency).centered(),
650555
Line::from(station_security).centered(),
651-
];
652-
653-
let row = Row::new(row);
556+
]);
654557

655558
let widths = [
559+
Constraint::Length(15),
560+
Constraint::Length(8),
561+
Constraint::Length(10),
562+
Constraint::Length(17),
656563
Constraint::Length(12),
657564
Constraint::Length(10),
658565
Constraint::Length(10),
659566
Constraint::Length(15),
660567
];
661568

662-
let station_table = Table::new(vec![row], widths)
569+
let device_table = Table::new(vec![row], widths)
663570
.header({
664-
if focused_block == FocusedBlock::Station {
571+
if focused_block == FocusedBlock::Device {
665572
Row::new(vec![
573+
Line::from("Name").yellow().centered(),
574+
Line::from("Mode").yellow().centered(),
575+
Line::from("Powered").yellow().centered(),
576+
Line::from("Address").yellow().centered(),
666577
Line::from("State").yellow().centered(),
667578
Line::from("Scanning").yellow().centered(),
668579
Line::from("Frequency").yellow().centered(),
@@ -672,25 +583,25 @@ impl Adapter {
672583
.bottom_margin(1)
673584
} else {
674585
Row::new(vec![
675-
Line::from("State")
586+
Line::from("Name")
676587
.style(match color_mode {
677588
ColorMode::Dark => Style::default().fg(Color::White),
678589
ColorMode::Light => Style::default().fg(Color::Black),
679590
})
680591
.centered(),
681-
Line::from("Scanning")
592+
Line::from("Mode")
682593
.style(match color_mode {
683594
ColorMode::Dark => Style::default().fg(Color::White),
684595
ColorMode::Light => Style::default().fg(Color::Black),
685596
})
686597
.centered(),
687-
Line::from("Frequency")
598+
Line::from("Powered")
688599
.style(match color_mode {
689600
ColorMode::Dark => Style::default().fg(Color::White),
690601
ColorMode::Light => Style::default().fg(Color::Black),
691602
})
692603
.centered(),
693-
Line::from("Security")
604+
Line::from("Address")
694605
.style(match color_mode {
695606
ColorMode::Dark => Style::default().fg(Color::White),
696607
ColorMode::Light => Style::default().fg(Color::Black),
@@ -703,24 +614,24 @@ impl Adapter {
703614
})
704615
.block(
705616
Block::default()
706-
.title(" Station ")
617+
.title(" Device ")
707618
.title_style({
708-
if focused_block == FocusedBlock::Station {
619+
if focused_block == FocusedBlock::Device {
709620
Style::default().bold()
710621
} else {
711622
Style::default()
712623
}
713624
})
714625
.borders(Borders::ALL)
715626
.border_style({
716-
if focused_block == FocusedBlock::Station {
627+
if focused_block == FocusedBlock::Device {
717628
Style::default().fg(Color::Green)
718629
} else {
719630
Style::default()
720631
}
721632
})
722633
.border_type({
723-
if focused_block == FocusedBlock::Station {
634+
if focused_block == FocusedBlock::Device {
724635
BorderType::Thick
725636
} else {
726637
BorderType::default()
@@ -734,14 +645,14 @@ impl Adapter {
734645
ColorMode::Dark => Style::default().fg(Color::White),
735646
ColorMode::Light => Style::default().fg(Color::Black),
736647
})
737-
.row_highlight_style(if focused_block == FocusedBlock::Station {
648+
.row_highlight_style(if focused_block == FocusedBlock::Device {
738649
Style::default().bg(Color::DarkGray).fg(Color::White)
739650
} else {
740651
Style::default()
741652
});
742653

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

746657
// Known networks
747658
let known_networks = if let Some(station) = self.device.station.as_ref() {
@@ -1052,16 +963,6 @@ impl Adapter {
1052963
Span::from("⇄").bold(),
1053964
Span::from(" Nav"),
1054965
]),
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-
]),
1065966
FocusedBlock::KnownNetworks => Line::from(vec![
1066967
Span::from("k,").bold(),
1067968
Span::from(" Up"),
@@ -1090,6 +991,9 @@ impl Adapter {
1090991
.bold(),
1091992
Span::from(" Toggle Autoconnect"),
1092993
Span::from(" | "),
994+
Span::from(self.config.station.start_scanning.to_string()).bold(),
995+
Span::from(" Scan"),
996+
Span::from(" | "),
1093997
Span::from("󱊷 ").bold(),
1094998
Span::from(" Discard"),
1095999
Span::from(" | "),
@@ -1109,6 +1013,9 @@ impl Adapter {
11091013
Span::from("󱁐 ").bold(),
11101014
Span::from(" Connect"),
11111015
Span::from(" | "),
1016+
Span::from(self.config.station.start_scanning.to_string()).bold(),
1017+
Span::from(" Scan"),
1018+
Span::from(" | "),
11121019
Span::from("󱊷 ").bold(),
11131020
Span::from(" Discard"),
11141021
Span::from(" | "),

β€Ž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::Device,
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)]

β€Žsrc/handler.rsβ€Ž

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::sync::Arc;
22

3-
use crate::ap::APFocusedSection;
43
use crate::app::{App, AppResult, FocusedBlock};
54
use crate::config::Config;
65
use crate::event::Event;
6+
use crate::mode::ap::APFocusedSection;
77
use crate::notification::Notification;
88

99
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
@@ -161,9 +161,6 @@ pub async fn handle_key_events(
161161
KeyCode::Tab => match app.adapter.device.mode {
162162
Mode::Station => match app.focused_block {
163163
FocusedBlock::Device => {
164-
app.focused_block = FocusedBlock::Station;
165-
}
166-
FocusedBlock::Station => {
167164
app.focused_block = FocusedBlock::KnownNetworks;
168165
}
169166
FocusedBlock::KnownNetworks => {
@@ -212,11 +209,8 @@ pub async fn handle_key_events(
212209
FocusedBlock::Device => {
213210
app.focused_block = FocusedBlock::NewNetworks;
214211
}
215-
FocusedBlock::Station => {
216-
app.focused_block = FocusedBlock::Device;
217-
}
218212
FocusedBlock::KnownNetworks => {
219-
app.focused_block = FocusedBlock::Station;
213+
app.focused_block = FocusedBlock::Device;
220214
}
221215
FocusedBlock::NewNetworks => {
222216
app.focused_block = FocusedBlock::KnownNetworks;

β€Žsrc/lib.rsβ€Ž

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,10 @@ pub mod notification;
1414

1515
pub mod device;
1616

17-
pub mod station;
18-
19-
pub mod network;
20-
21-
pub mod known_network;
22-
23-
pub mod auth;
24-
2517
pub mod adapter;
2618

27-
pub mod ap;
28-
2919
pub mod cli;
3020

3121
pub mod rfkill;
22+
23+
pub mod mode;

β€Žsrc/mode.rsβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod ap;
2+
pub mod station;
File renamed without changes.

0 commit comments

Comments
Β (0)