Skip to content
Open
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
200 changes: 175 additions & 25 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async-channel = "2"
crossterm = { version = "0.29", default-features = false, features = [
"event-stream",
] }
ratatui = "0.30"
ratatui = { version = "0.30", features = ["serde"] }
tui-input = { version = "0.15", features = [
"crossterm",
], default-features = false }
Expand Down
13 changes: 11 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ This will produce an executable file at `target/release/impala` that you can cop
$ impala
```

## 🛠️Custom keybindings
## 🛠️Custom keybindings and themes

Keybindings can be customized in the config file `$HOME/.config/impala/config.toml`
Keybindings and themes can be customized in the config file `$HOME/.config/impala/config.toml`

```toml

Expand Down Expand Up @@ -98,6 +98,15 @@ share = "p"
[station.new_network]
show_all = "a"
connect_hidden = ""

[theme]
background = "dark gray"
border = "green"
text_color = "white"
hidden_color = "dark gray"
info_color = "green"
warning_color = "yellow"
error_color = "red"
```

## Contributing
Expand Down
12 changes: 8 additions & 4 deletions src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use iwdrs::{adapter::Adapter as iwdAdapter, session::Session};
use ratatui::{
Frame,
layout::{Alignment, Constraint, Direction, Flex, Layout},
style::{Color, Style},
style::Style,
widgets::{Block, BorderType, Borders, Cell, Clear, Padding, Row, Table},
};

Expand Down Expand Up @@ -54,7 +54,7 @@ impl Adapter {
Ok(())
}

pub fn render(&self, frame: &mut Frame, device_addr: String) {
pub fn render(&self, frame: &mut Frame, device_addr: String, config: Arc<Config>) {
let popup_layout = Layout::default()
.direction(ratatui::layout::Direction::Vertical)
.constraints([
Expand Down Expand Up @@ -113,11 +113,15 @@ impl Adapter {
.title_alignment(Alignment::Center)
.padding(Padding::uniform(1))
.borders(Borders::ALL)
.border_style(Style::default().fg(Color::Green))
.border_style(Style::default().fg(config.theme.border))
.border_type(BorderType::Thick),
)
.column_spacing(3)
.row_highlight_style(Style::default().bg(Color::DarkGray).fg(Color::White));
.row_highlight_style(
Style::default()
.bg(config.theme.background)
.fg(config.theme.text_color),
);

frame.render_widget(Clear, area);
frame.render_widget(device_infos_table, area);
Expand Down
71 changes: 71 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use ratatui::style::Color;
use toml;

use dirs;
Expand All @@ -22,6 +23,9 @@ pub struct Config {

#[serde(default)]
pub ap: AccessPoint,

#[serde(default)]
pub theme: Theme,
}

fn default_switch_mode() -> char {
Expand Down Expand Up @@ -150,6 +154,73 @@ fn default_ap_stop() -> char {
'x'
}

// Theme
#[derive(Deserialize, Debug)]
pub struct Theme {
#[serde(default = "default_background")]
pub background: Color,

#[serde(default = "default_border")]
pub border: Color,

#[serde(default = "default_text_color")]
pub text_color: Color,

#[serde(default = "default_hidden_color")]
pub hidden_color: Color,

#[serde(default = "default_info_color")]
pub info_color: Color,

#[serde(default = "default_warning_color")]
pub warning_color: Color,

#[serde(default = "default_error_color")]
pub error_color: Color,
}

fn default_background() -> Color {
Color::DarkGray
}

fn default_border() -> Color {
Color::Green
}

fn default_text_color() -> Color {
Color::White
}

fn default_hidden_color() -> Color {
Color::DarkGray
}

fn default_info_color() -> Color {
Color::Green
}

fn default_warning_color() -> Color {
Color::Yellow
}

fn default_error_color() -> Color {
Color::Red
}

impl Default for Theme {
fn default() -> Self {
Self {
background: default_background(),
border: default_border(),
text_color: default_text_color(),
hidden_color: default_hidden_color(),
info_color: default_info_color(),
warning_color: default_warning_color(),
error_color: default_error_color(),
}
}
}

impl Config {
pub fn new() -> Self {
let conf_path = dirs::config_dir()
Expand Down
10 changes: 7 additions & 3 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use iwdrs::{device::Device as iwdDevice, modes::Mode, session::Session};
use ratatui::{
Frame,
layout::{Constraint, Direction, Flex, Layout},
style::{Color, Style, Stylize},
style::{Style, Stylize},
text::{Line, Span},
widgets::{Block, BorderType, Borders, Padding, Row, Table, TableState},
};
Expand Down Expand Up @@ -147,13 +147,17 @@ impl Device {
.title(" Device ")
.title_style(Style::default().bold())
.borders(Borders::ALL)
.border_style(Style::default().fg(Color::Green))
.border_style(Style::default().fg(config.theme.border))
.border_type(BorderType::Thick)
.padding(Padding::horizontal(1)),
)
.column_spacing(1)
.flex(Flex::SpaceAround)
.row_highlight_style(Style::default().bg(Color::DarkGray).fg(Color::White));
.row_highlight_style(
Style::default()
.bg(config.theme.background)
.fg(config.theme.text_color),
);

let mut device_state = TableState::default().with_selected(0);
frame.render_stateful_widget(device_table, device_block, &mut device_state);
Expand Down
33 changes: 18 additions & 15 deletions src/mode/ap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tokio::sync::mpsc::UnboundedSender;
use ratatui::{
Frame,
layout::{Alignment, Constraint, Direction, Flex, Layout},
style::{Color, Style, Stylize},
style::{Style, Stylize},
text::{Line, Span, Text},
widgets::{
Block, BorderType, Borders, Clear, List, Padding, Paragraph, Row, Table, TableState,
Expand Down Expand Up @@ -96,7 +96,7 @@ impl AccessPoint {
})
}

pub fn render_input(&self, frame: &mut Frame) {
pub fn render_input(&self, frame: &mut Frame, config: Arc<Config>) {
let popup_layout = Layout::default()
.direction(Direction::Vertical)
.constraints(
Expand Down Expand Up @@ -180,32 +180,31 @@ impl AccessPoint {

let ssid_msg = Paragraph::new(ssid_text)
.alignment(Alignment::Left)
.style(Style::default().fg(Color::White))
.style(Style::default().fg(config.theme.text_color))
.block(Block::new().padding(Padding::left(2)));

let ssid_input = Paragraph::new(self.ssid.value())
.alignment(Alignment::Center)
.style(Style::default().fg(Color::White))
.block(Block::new().style(Style::default().bg(Color::DarkGray)));
.style(Style::default().fg(config.theme.text_color))
.block(Block::new().style(Style::default().bg(config.theme.background)));

let psk_msg = Paragraph::new(psk_text)
.alignment(Alignment::Left)
.style(Style::default().fg(Color::White))
.style(Style::default().fg(config.theme.text_color))
.block(Block::new().padding(Padding::left(2)));

let psk_input = Paragraph::new(self.psk.value())
.alignment(Alignment::Center)
.style(Style::default().fg(Color::White))
.block(Block::new().style(Style::default().bg(Color::DarkGray)));
.style(Style::default().fg(config.theme.text_color))
.block(Block::new().style(Style::default().bg(config.theme.background)));

frame.render_widget(Clear, area);

frame.render_widget(
Block::new()
.borders(Borders::ALL)
.border_type(BorderType::Thick)
.style(Style::default().green())
.border_style(Style::default().fg(Color::Green)),
.style(Style::default().fg(config.theme.border)),
area,
);
frame.render_widget(ssid_msg, ssid_msg_area);
Expand Down Expand Up @@ -391,7 +390,7 @@ impl AccessPoint {
.padding(Padding::horizontal(1))
.border_style({
if focused_block == FocusedBlock::Device {
Style::default().fg(Color::Green)
Style::default().fg(config.theme.border)
} else {
Style::default()
}
Expand All @@ -407,7 +406,9 @@ impl AccessPoint {
.column_spacing(2)
.flex(Flex::SpaceAround)
.row_highlight_style(if focused_block == FocusedBlock::Device {
Style::default().bg(Color::DarkGray).fg(Color::White)
Style::default()
.bg(config.theme.background)
.fg(config.theme.text_color)
} else {
Style::default()
});
Expand Down Expand Up @@ -495,7 +496,7 @@ impl AccessPoint {
.borders(Borders::ALL)
.border_style({
if focused_block == FocusedBlock::AccessPoint {
Style::default().fg(Color::Green)
Style::default().fg(config.theme.border)
} else {
Style::default()
}
Expand All @@ -512,7 +513,9 @@ impl AccessPoint {
.column_spacing(2)
.flex(Flex::SpaceAround)
.row_highlight_style(if focused_block == FocusedBlock::AccessPoint {
Style::default().bg(Color::DarkGray).fg(Color::White)
Style::default()
.bg(config.theme.background)
.fg(config.theme.text_color)
} else {
Style::default()
});
Expand Down Expand Up @@ -540,7 +543,7 @@ impl AccessPoint {
.borders(Borders::ALL)
.border_style({
if focused_block == FocusedBlock::AccessPointConnectedDevices {
Style::default().fg(Color::Green)
Style::default().fg(config.theme.border)
} else {
Style::default()
}
Expand Down
26 changes: 16 additions & 10 deletions src/mode/station.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use iwdrs::{
use ratatui::{
Frame,
layout::{Constraint, Direction, Flex, Layout},
style::{Color, Style, Stylize},
style::{Style, Stylize},
text::{Line, Span},
widgets::{Block, BorderType, Borders, Padding, Paragraph, Row, Table, TableState},
};
Expand Down Expand Up @@ -457,7 +457,7 @@ impl Station {
.borders(Borders::ALL)
.border_style({
if focused_block == FocusedBlock::Device {
Style::default().fg(Color::Green)
Style::default().fg(config.theme.border)
} else {
Style::default()
}
Expand All @@ -474,7 +474,9 @@ impl Station {
.column_spacing(1)
.flex(Flex::SpaceAround)
.row_highlight_style(if focused_block == FocusedBlock::Device {
Style::default().bg(Color::DarkGray).fg(Color::White)
Style::default()
.bg(config.theme.background)
.fg(config.theme.text_color)
} else {
Style::default()
});
Expand Down Expand Up @@ -547,7 +549,7 @@ impl Station {
Line::from(""),
Line::from(""),
])
.fg(Color::DarkGray);
.fg(config.theme.hidden_color);

rows.push(row);
});
Expand Down Expand Up @@ -600,7 +602,7 @@ impl Station {
.borders(Borders::ALL)
.border_style({
if focused_block == FocusedBlock::KnownNetworks {
Style::default().fg(Color::Green)
Style::default().fg(config.theme.border)
} else {
Style::default()
}
Expand All @@ -617,7 +619,9 @@ impl Station {
.column_spacing(1)
.flex(Flex::SpaceAround)
.row_highlight_style(if focused_block == FocusedBlock::KnownNetworks {
Style::default().bg(Color::DarkGray).fg(Color::White)
Style::default()
.bg(config.theme.background)
.fg(config.theme.text_color)
} else {
Style::default()
});
Expand Down Expand Up @@ -681,7 +685,7 @@ impl Station {
})
.centered(),
])
.dark_gray(),
.fg(config.theme.hidden_color),
)
})
};
Expand Down Expand Up @@ -724,7 +728,7 @@ impl Station {
.borders(Borders::ALL)
.border_style({
if focused_block == FocusedBlock::NewNetworks {
Style::default().fg(Color::Green)
Style::default().fg(config.theme.border)
} else {
Style::default()
}
Expand All @@ -741,7 +745,9 @@ impl Station {
.column_spacing(1)
.flex(Flex::SpaceAround)
.row_highlight_style(if focused_block == FocusedBlock::NewNetworks {
Style::default().bg(Color::DarkGray).fg(Color::White)
Style::default()
.bg(config.theme.background)
.fg(config.theme.text_color)
} else {
Style::default()
});
Expand Down Expand Up @@ -947,7 +953,7 @@ impl Station {

// Share
if let Some(share) = &self.share {
share.render(frame);
share.render(frame, config.clone());
}
}
}
Loading