Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
395 changes: 220 additions & 175 deletions Cargo.lock

Large diffs are not rendered by default.

206 changes: 64 additions & 142 deletions src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,21 @@ impl Adapter {
None => false,
};

let (device_block, access_point_block, connected_devices_block, help_block) = {
let (access_point_block, connected_devices_block, device_block, help_block) = {
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints(if any_connected_devices {
&[
Constraint::Percentage(33),
Constraint::Percentage(33),
Constraint::Percentage(33),
Constraint::Length(5),
Constraint::Fill(1),
Constraint::Length(5),
Constraint::Length(1),
]
} else {
&[
Constraint::Percentage(50),
Constraint::Percentage(50),
Constraint::Fill(1),
Constraint::Length(0),
Constraint::Length(5),
Constraint::Length(1),
]
})
Expand Down Expand Up @@ -480,127 +480,21 @@ impl Adapter {
color_mode: ColorMode,
focused_block: FocusedBlock,
) {
let (device_block, station_block, known_networks_block, new_networks_block, help_block) = {
let (known_networks_block, new_networks_block, device_block, help_block) = {
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Length(5),
Constraint::Length(5),
Constraint::Min(5),
Constraint::Min(5),
Constraint::Length(5),
Constraint::Length(1),
])
.margin(1)
.split(frame.area());
(chunks[0], chunks[1], chunks[2], chunks[3], chunks[4])
(chunks[0], chunks[1], chunks[2], chunks[3])
};

// Device
let row = Row::new(vec![
Line::from(self.device.name.clone()).centered(),
Line::from("station").centered(),
{
if self.device.is_powered {
Line::from("On").centered()
} else {
Line::from("Off").centered()
}
},
Line::from(self.device.address.clone()).centered(),
]);

let widths = [
Constraint::Length(15),
Constraint::Length(8),
Constraint::Length(10),
Constraint::Length(17),
];

let device_table = Table::new(vec![row], widths)
.header({
if focused_block == FocusedBlock::Device {
Row::new(vec![
Line::from("Name").yellow().centered(),
Line::from("Mode").yellow().centered(),
Line::from("Powered").yellow().centered(),
Line::from("Address").yellow().centered(),
])
.style(Style::new().bold())
.bottom_margin(1)
} else {
Row::new(vec![
Line::from("Name")
.style(match color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
})
.centered(),
Line::from("Mode")
.style(match color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
})
.centered(),
Line::from("Powered")
.style(match color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
})
.centered(),
Line::from("Address")
.style(match color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
})
.centered(),
])
.style(Style::new().bold())
.bottom_margin(1)
}
})
.block(
Block::default()
.title(" Device ")
.title_style({
if focused_block == FocusedBlock::Device {
Style::default().bold()
} else {
Style::default()
}
})
.borders(Borders::ALL)
.border_style({
if focused_block == FocusedBlock::Device {
Style::default().fg(Color::Green)
} else {
Style::default()
}
})
.border_type({
if focused_block == FocusedBlock::Device {
BorderType::Thick
} else {
BorderType::default()
}
})
.padding(Padding::horizontal(1)),
)
.column_spacing(2)
.flex(Flex::SpaceBetween)
.style(match color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
})
.row_highlight_style(if focused_block == FocusedBlock::Device {
Style::default().bg(Color::DarkGray).fg(Color::White)
} else {
Style::default()
});

let mut device_state = TableState::default().with_selected(0);
frame.render_stateful_widget(device_table, device_block, &mut device_state);

// Station

let station_frequency = {
match self.device.station.as_ref() {
Expand Down Expand Up @@ -643,26 +537,40 @@ impl Adapter {
station_state = station.state.clone();
station_is_scanning = station.is_scanning.clone().to_string();
}
let row = vec![

let row = Row::new(vec![
Line::from(self.device.name.clone()).centered(),
Line::from("station").centered(),
{
if self.device.is_powered {
Line::from("On").centered()
} else {
Line::from("Off").centered()
}
},
Line::from(station_state).centered(),
Line::from(station_is_scanning).centered(),
Line::from(station_frequency).centered(),
Line::from(station_security).centered(),
];

let row = Row::new(row);
]);

let widths = [
Constraint::Length(10),
Constraint::Length(8),
Constraint::Length(10),
Constraint::Length(12),
Constraint::Length(10),
Constraint::Length(10),
Constraint::Length(15),
];

let station_table = Table::new(vec![row], widths)
let device_table = Table::new(vec![row], widths)
.header({
if focused_block == FocusedBlock::Station {
if focused_block == FocusedBlock::Device {
Row::new(vec![
Line::from("Name").yellow().centered(),
Line::from("Mode").yellow().centered(),
Line::from("Powered").yellow().centered(),
Line::from("State").yellow().centered(),
Line::from("Scanning").yellow().centered(),
Line::from("Frequency").yellow().centered(),
Expand All @@ -672,6 +580,24 @@ impl Adapter {
.bottom_margin(1)
} else {
Row::new(vec![
Line::from("Name")
.style(match color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
})
.centered(),
Line::from("Mode")
.style(match color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
})
.centered(),
Line::from("Powered")
.style(match color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
})
.centered(),
Line::from("State")
.style(match color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
Expand Down Expand Up @@ -703,45 +629,45 @@ impl Adapter {
})
.block(
Block::default()
.title(" Station ")
.title(" Device ")
.title_style({
if focused_block == FocusedBlock::Station {
if focused_block == FocusedBlock::Device {
Style::default().bold()
} else {
Style::default()
}
})
.borders(Borders::ALL)
.border_style({
if focused_block == FocusedBlock::Station {
if focused_block == FocusedBlock::Device {
Style::default().fg(Color::Green)
} else {
Style::default()
}
})
.border_type({
if focused_block == FocusedBlock::Station {
if focused_block == FocusedBlock::Device {
BorderType::Thick
} else {
BorderType::default()
}
})
.padding(Padding::horizontal(1)),
)
.column_spacing(2)
.column_spacing(1)
.flex(Flex::SpaceBetween)
.style(match color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
})
.row_highlight_style(if focused_block == FocusedBlock::Station {
.row_highlight_style(if focused_block == FocusedBlock::Device {
Style::default().bg(Color::DarkGray).fg(Color::White)
} else {
Style::default()
});

let mut station_state = TableState::default().with_selected(0);
frame.render_stateful_widget(station_table, station_block, &mut station_state);
let mut device_state = TableState::default().with_selected(0);
frame.render_stateful_widget(device_table, device_block, &mut device_state);

// Known networks
let known_networks = if let Some(station) = self.device.station.as_ref() {
Expand Down Expand Up @@ -1052,16 +978,6 @@ impl Adapter {
Span::from("⇄").bold(),
Span::from(" Nav"),
]),
FocusedBlock::Station => Line::from(vec![
Span::from(self.config.station.start_scanning.to_string()).bold(),
Span::from(" Scan"),
Span::from(" | "),
Span::from("ctrl+r").bold(),
Span::from(" Switch Mode"),
Span::from(" | "),
Span::from("⇄").bold(),
Span::from(" Nav"),
]),
FocusedBlock::KnownNetworks => Line::from(vec![
Span::from("k,").bold(),
Span::from(" Up"),
Expand All @@ -1075,7 +991,7 @@ impl Adapter {
self.config.station.toggle_connect.to_string()
})
.bold(),
Span::from(" Connect/Disconnect"),
Span::from(" Dis/connect"),
Span::from(" | "),
Span::from(self.config.station.known_network.remove.to_string()).bold(),
Span::from(" Remove"),
Expand All @@ -1088,7 +1004,10 @@ impl Adapter {
.to_string(),
)
.bold(),
Span::from(" Toggle Autoconnect"),
Span::from(" Autoconnect"),
Span::from(" | "),
Span::from(self.config.station.start_scanning.to_string()).bold(),
Span::from(" Scan"),
Span::from(" | "),
Span::from("󱊷 ").bold(),
Span::from(" Discard"),
Expand All @@ -1109,6 +1028,9 @@ impl Adapter {
Span::from("󱁐 ").bold(),
Span::from(" Connect"),
Span::from(" | "),
Span::from(self.config.station.start_scanning.to_string()).bold(),
Span::from(" Scan"),
Span::from(" | "),
Span::from("󱊷 ").bold(),
Span::from(" Discard"),
Span::from(" | "),
Expand All @@ -1135,7 +1057,7 @@ impl Adapter {
.constraints([
Constraint::Fill(1),
Constraint::Length(9),
Constraint::Fill(5),
Constraint::Fill(1),
])
.flex(Flex::Start)
.split(frame.area());
Expand Down
8 changes: 6 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub type AppResult<T> = std::result::Result<T, Box<dyn Error>>;
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum FocusedBlock {
Device,
Station,
AccessPoint,
KnownNetworks,
NewNetworks,
Expand Down Expand Up @@ -143,9 +142,14 @@ impl App {
Ok(_) | Err(_) => ColorMode::Dark,
};

let focused_block = match current_mode {
Mode::Station => FocusedBlock::KnownNetworks,
_ => FocusedBlock::AccessPoint,
};

Ok(Self {
running: true,
focused_block: FocusedBlock::Device,
focused_block,
color_mode,
notifications: Vec::new(),
session,
Expand Down
3 changes: 2 additions & 1 deletion src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use iwdrs::{device::Device as iwdDevice, modes::Mode, session::Session};
use tokio::sync::mpsc::UnboundedSender;

use crate::{
ap::AccessPoint, app::AppResult, event::Event, notification::Notification, station::Station,
app::AppResult, event::Event, mode::ap::AccessPoint, mode::station::Station,
notification::Notification,
};

#[derive(Debug, Clone)]
Expand Down
Loading