Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support light background #11

Merged
merged 1 commit into from
Mar 28, 2024
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
49 changes: 48 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dirs = "5"
toml = { version = "0.8" }
serde = { version = "1", features = ["derive"] }
clap = { version = "4", features = ["derive", "cargo"] }
terminal-light = "1"

[profile.release]
strip = true
6 changes: 6 additions & 0 deletions Release.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v0.5 - TBA

### Added

- Support light background

## v0.4 - 15/03/2024

### Added
Expand Down
99 changes: 82 additions & 17 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ pub enum FocusedBlock {
PassKeyConfirmation,
}

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ColorMode {
Dark,
Light,
}

#[derive(Debug)]
pub struct App {
pub running: bool,
Expand All @@ -55,6 +61,7 @@ pub struct App {
pub new_devices_state: TableState,
pub focused_block: FocusedBlock,
pub pairing_confirmation: PairingConfirmation,
pub color_mode: ColorMode,
}

#[derive(Debug)]
Expand Down Expand Up @@ -216,11 +223,26 @@ impl App {
} else {
Row::new(vec![
Cell::from(""),
Cell::from("Name").style(Style::default().fg(Color::White)),
Cell::from("Alias").style(Style::default().fg(Color::White)),
Cell::from("Power").style(Style::default().fg(Color::White)),
Cell::from("Pairable").style(Style::default().fg(Color::White)),
Cell::from("Discoverable").style(Style::default().fg(Color::White)),
Cell::from("Name").style(match self.color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
}),
Cell::from("Alias").style(match self.color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
}),
Cell::from("Power").style(match self.color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
}),
Cell::from("Pairable").style(match self.color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
}),
Cell::from("Discoverable").style(match self.color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
}),
])
.style(Style::new().bold())
.bottom_margin(1)
Expand Down Expand Up @@ -252,7 +274,10 @@ impl App {
}
}),
)
.style(Style::default().fg(Color::White))
.style(match self.color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
})
.highlight_style(if self.focused_block == FocusedBlock::Adapter {
Style::default().bg(Color::DarkGray)
} else {
Expand Down Expand Up @@ -356,10 +381,22 @@ impl App {
.bottom_margin(1)
} else {
Row::new(vec![
Cell::from("Name").style(Style::default().fg(Color::White)),
Cell::from("Trusted").style(Style::default().fg(Color::White)),
Cell::from("Connected").style(Style::default().fg(Color::White)),
Cell::from("Battery").style(Style::default().fg(Color::White)),
Cell::from("Name").style(match self.color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
}),
Cell::from("Trusted").style(match self.color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
}),
Cell::from("Connected").style(match self.color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
}),
Cell::from("Battery").style(match self.color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
}),
])
.style(Style::new().bold())
.bottom_margin(1)
Expand All @@ -374,9 +411,18 @@ impl App {
.bottom_margin(1)
} else {
Row::new(vec![
Cell::from("Name").style(Style::default().fg(Color::White)),
Cell::from("Trusted").style(Style::default().fg(Color::White)),
Cell::from("Connected").style(Style::default().fg(Color::White)),
Cell::from("Name").style(match self.color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
}),
Cell::from("Trusted").style(match self.color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
}),
Cell::from("Connected").style(match self.color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
}),
])
.style(Style::new().bold())
.bottom_margin(1)
Expand Down Expand Up @@ -408,7 +454,10 @@ impl App {
}
}),
)
.style(Style::default().fg(Color::White))
.style(match self.color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
})
.highlight_style(if self.focused_block == FocusedBlock::PairedDevices {
Style::default().bg(Color::DarkGray)
} else {
Expand Down Expand Up @@ -458,8 +507,14 @@ impl App {
.bottom_margin(1)
} else {
Row::new(vec![
Cell::from("Address").style(Style::default().fg(Color::White)),
Cell::from("Name").style(Style::default().fg(Color::White)),
Cell::from("Address").style(match self.color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
}),
Cell::from("Name").style(match self.color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
}),
])
.style(Style::new().bold())
.bottom_margin(1)
Expand Down Expand Up @@ -497,7 +552,10 @@ impl App {
}
}),
)
.style(Style::default().fg(Color::White))
.style(match self.color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
})
.highlight_style(if self.focused_block == FocusedBlock::NewDevices {
Style::default().bg(Color::Gray)
} else {
Expand Down Expand Up @@ -612,6 +670,12 @@ impl App {
}
}
pub async fn new(config: Arc<Config>) -> AppResult<Self> {
let color_mode = match terminal_light::luma() {
Ok(luma) if luma > 0.6 => ColorMode::Light,
Ok(_) => ColorMode::Dark,
Err(_) => ColorMode::Dark,
};

let session = Arc::new(bluer::Session::new().await?);

// Pairing confirmation
Expand Down Expand Up @@ -660,6 +724,7 @@ impl App {
new_devices_state: TableState::default(),
focused_block: FocusedBlock::Adapter,
pairing_confirmation,
color_mode,
})
}

Expand Down
10 changes: 6 additions & 4 deletions src/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ratatui::{
Frame,
};

use crate::config::Config;
use crate::{app::ColorMode, config::Config};

#[derive(Debug)]
pub struct Help {
Expand Down Expand Up @@ -128,7 +128,7 @@ impl Help {
self.state.select(Some(i));
}

pub fn render(&mut self, frame: &mut Frame) {
pub fn render(&mut self, frame: &mut Frame, color_mode: ColorMode) {
let block = help_rect(frame.size());

self.block_height = block.height as usize;
Expand All @@ -137,8 +137,10 @@ impl Help {
.keys
.iter()
.map(|key| {
Row::new(vec![key.0.to_owned(), key.1.into()])
.style(Style::default().fg(Color::White))
Row::new(vec![key.0.to_owned(), key.1.into()]).style(match color_mode {
ColorMode::Dark => Style::default().fg(Color::White),
ColorMode::Light => Style::default().fg(Color::Black),
})
})
.collect();
let rows_len = self.keys.len().saturating_sub(self.block_height - 6);
Expand Down
2 changes: 1 addition & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub fn render(app: &mut App, frame: &mut Frame) {

// Help
if let FocusedBlock::Help = app.focused_block {
app.help.render(frame);
app.help.render(frame, app.color_mode);
}

// Notifications
Expand Down