feat(M8.5): add built-in TUI themes

Centralize semantic terminal colors and add Default, Dracula, Nord, Gruvbox Dark, Catppuccin Mocha, and Solarized Dark palettes. Support launch-time --theme selection and live cycling with t while keeping theme state session-local.\n\nTests: cargo fmt --all -- --check; cargo check --workspace --all-targets --all-features; cargo test --workspace --all-targets --all-features; cargo test --workspace --doc --all-features; cargo clippy --workspace --all-targets --all-features -- -D warnings; cargo build --workspace --release --all-features; default/no-default/individual-backend matrix (all pass).
This commit is contained in:
Dandaedre 2026-10-15 03:21:32 +02:00
parent 1fae9bef73
commit b1a1f0769b
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
8 changed files with 326 additions and 40 deletions

View File

@ -37,9 +37,12 @@ cargo run --locked -p fader_master -- tui
```
Use Up/Down or J/K to select a configured application or group, Left/Right to
change its volume, M to toggle mute, and Q or Escape to quit. Offline objects
remain visible, and aggregate rows show `MIXED` when member state differs. See
the hands-on checklist for the exact milestone scope and restoration steps.
change its volume, M to toggle mute, T to cycle the built-in themes, and Q or
Escape to quit. Pass `--theme dracula`, `nord`, `gruvbox-dark`,
`catppuccin-mocha`, or `solarized-dark` to choose an initial theme. Offline
objects remain visible, and aggregate rows show `MIXED` when member state
differs. See the hands-on checklist for the exact milestone scope and
restoration steps.
# References

View File

@ -306,6 +306,14 @@ replace the local base and retain optimistic overlays until observation settles
them. Poll quickly while writes are pending, slowly while idle, and resnapshot
then retry once after a stale edit.
Terminal colors come from semantic theme palettes rather than renderer-local
literals. The built-ins are Default, Dracula, Nord, Gruvbox Dark, Catppuccin
Mocha, and Solarized Dark. `tui --theme NAME` selects the initial palette and
`t` cycles themes for the current session; theme selection is presentation-only
and is not persisted in the audio profile. Each palette defines background,
foreground, accent/selection, secondary meter, muted, warning, error, and meter
track colors so status meaning remains consistent across themes.
TUI tabs:
- **Mixer:** faders, resolved applications/streams, volume, mute, mixed/offline/pending/errors, pickup status.

View File

@ -30,6 +30,9 @@ pub enum Command {
/// Override the XDG runtime socket path.
#[arg(long)]
socket: Option<PathBuf>,
/// Initial built-in color theme; press `t` to cycle themes while running.
#[arg(long, value_enum, default_value_t)]
theme: ThemeArgument,
},
/// Validate a profile without opening devices or changing audio.
Validate {
@ -64,6 +67,31 @@ pub enum AudioArgument {
Pipewire,
}
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, ValueEnum)]
pub enum ThemeArgument {
#[default]
Default,
Dracula,
Nord,
GruvboxDark,
CatppuccinMocha,
SolarizedDark,
}
impl ThemeArgument {
#[must_use]
pub const fn theme(self) -> tui::ThemeName {
match self {
Self::Default => tui::ThemeName::Default,
Self::Dracula => tui::ThemeName::Dracula,
Self::Nord => tui::ThemeName::Nord,
Self::GruvboxDark => tui::ThemeName::GruvboxDark,
Self::CatppuccinMocha => tui::ThemeName::CatppuccinMocha,
Self::SolarizedDark => tui::ThemeName::SolarizedDark,
}
}
}
impl AudioArgument {
#[must_use]
pub const fn choice(self) -> AdapterChoice {

View File

@ -16,9 +16,10 @@ use volume_lib::{AudioBackend, CompiledAdapterProbe, TargetRequirements, select_
fn main() -> Result<()> {
match Cli::parse().command {
Command::Tui { socket } => {
Command::Tui { socket, theme } => {
let socket = socket.map_or_else(default_socket_path, Ok)?;
tui::run_live(IpcMixerClient::new(socket)).context("terminal UI failed")
tui::run_live_with_theme(IpcMixerClient::new(socket), theme.theme())
.context("terminal UI failed")
}
Command::Validate { config } => {
let profile = load_profile(&config)?;

View File

@ -1,7 +1,7 @@
use std::path::PathBuf;
use clap::{CommandFactory, Parser};
use fader_master::cli::{AudioArgument, Cli, Command};
use fader_master::cli::{AudioArgument, Cli, Command, ThemeArgument};
#[test]
fn every_planned_command_is_present_in_help() {
@ -48,3 +48,26 @@ fn unknown_commands_and_adapter_values_are_rejected() {
.is_err()
);
}
#[test]
fn tui_accepts_known_themes_and_rejects_unknown_names() {
assert_eq!(
Cli::try_parse_from(["fader_master", "tui"])
.unwrap()
.command,
Command::Tui {
socket: None,
theme: ThemeArgument::Default,
}
);
assert_eq!(
Cli::try_parse_from(["fader_master", "tui", "--theme", "catppuccin-mocha"])
.unwrap()
.command,
Command::Tui {
socket: None,
theme: ThemeArgument::CatppuccinMocha,
}
);
assert!(Cli::try_parse_from(["fader_master", "tui", "--theme", "hot-dog-stand"]).is_err());
}

View File

@ -275,6 +275,11 @@ Dependencies: M7, M4 for real use.
TUI, and external edits rebase only the affected member; zero is reversible;
joins adopt live maxima and removals discard anchors. Do not enable this mode
in shipped profiles without a separate product decision.
- [x] **M8.5 Built-in themes (stretch):** centralize semantic TUI colors and
provide Default, Dracula, Nord, Gruvbox Dark, Catppuccin Mocha, and Solarized
Dark palettes. `tui --theme` chooses the initial palette and `t` cycles it for
the current session. Tests: known CLI names parse, unknown names fail, cycling
wraps deterministically, and the selected palette/name reach rendered cells.
First live TUI slice verification on 2026-10-15: a real server selected Pulse
against PipeWire, reached `ready`, and published the active Qobuz playback stream

View File

@ -1,5 +1,9 @@
//! Terminal user interface for fader_master.
mod theme;
pub use theme::ThemeName;
use std::{
collections::{BTreeMap, VecDeque},
io,
@ -13,7 +17,7 @@ use ratatui::{
buffer::Buffer,
crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind},
layout::{Alignment, Constraint, Direction, Layout, Rect},
style::{Color, Style, Stylize},
style::{Style, Stylize},
symbols::border,
text::Line,
widgets::{Block, Gauge, Paragraph, Widget},
@ -356,10 +360,18 @@ fn discard_failed_action(state: &mut BufferedState, action: &BufferedAction) {
/// Runs the live terminal client and restores terminal state on every return.
pub fn run_live(client: impl MixerClient + Send + 'static) -> io::Result<()> {
run_live_with_theme(client, ThemeName::Default)
}
/// Runs the live terminal client with a selected built-in color theme.
pub fn run_live_with_theme(
client: impl MixerClient + Send + 'static,
theme: ThemeName,
) -> io::Result<()> {
let client = BufferedMixerClient::spawn(client)?;
let mut terminal = ratatui::init();
let _guard = RestoreTerminal;
LiveTui::new(client)?.run(&mut terminal)
LiveTui::with_theme(client, theme)?.run(&mut terminal)
}
/// Retains the original preview example without opening audio or IPC.
@ -379,22 +391,33 @@ pub struct LiveTui<C> {
client: C,
snapshot: MixerSnapshot,
selected: usize,
theme: ThemeName,
exit: bool,
client_error: Option<String>,
}
impl<C: MixerClient> LiveTui<C> {
pub fn new(mut client: C) -> io::Result<Self> {
pub fn new(client: C) -> io::Result<Self> {
Self::with_theme(client, ThemeName::Default)
}
pub fn with_theme(mut client: C, theme: ThemeName) -> io::Result<Self> {
let snapshot = client.snapshot()?;
Ok(Self {
client,
snapshot,
selected: 0,
theme,
exit: false,
client_error: None,
})
}
#[must_use]
pub const fn theme(&self) -> ThemeName {
self.theme
}
pub fn run(&mut self, terminal: &mut DefaultTerminal) -> io::Result<()> {
while !self.exit {
self.refresh();
@ -452,6 +475,7 @@ impl<C: MixerClient> LiveTui<C> {
KeyCode::Home => self.set_selected_volume(0.0),
KeyCode::End => self.set_selected_volume(1.0),
KeyCode::Char('m') => self.toggle_selected_mute(),
KeyCode::Char('t') => self.theme = self.theme.next(),
KeyCode::Esc | KeyCode::Char('q') => self.exit = true,
_ => {}
}
@ -502,6 +526,11 @@ impl<C: MixerClient> LiveTui<C> {
impl<C> Widget for &LiveTui<C> {
fn render(self, area: Rect, buf: &mut Buffer) {
let theme = self.theme.palette();
buf.set_style(
area,
Style::default().fg(theme.foreground).bg(theme.background),
);
let [header, body, footer] = Layout::default()
.direction(Direction::Vertical)
.constraints([
@ -512,53 +541,70 @@ impl<C> Widget for &LiveTui<C> {
.areas(area);
Paragraph::new(Line::from(vec![
" FADER ".fg(Color::Black).bg(Color::Cyan).bold(),
" MASTER ".bold(),
" FADER "
.fg(theme.header_foreground)
.bg(theme.accent)
.bold(),
" MASTER ".fg(theme.foreground).bold(),
format!(
" {} · {} · rev {} ",
self.snapshot.backend, self.snapshot.status, self.snapshot.revision
" {} · {} · rev {} · {} ",
self.snapshot.backend,
self.snapshot.status,
self.snapshot.revision,
self.theme.label()
)
.dark_gray(),
.fg(theme.muted),
]))
.alignment(Alignment::Center)
.block(Block::bordered().border_set(border::ROUNDED))
.block(
Block::bordered()
.border_set(border::ROUNDED)
.border_style(Style::default().fg(theme.muted)),
)
.render(header, buf);
let mixer = Block::bordered()
.title(" Live mixer objects ".bold())
.title_bottom(
self.client_error
.as_deref()
.unwrap_or("confirmed server state")
.dark_gray(),
)
.title(" Live mixer objects ".fg(theme.accent).bold())
.title_bottom(match self.client_error.as_deref() {
Some(error) => error.fg(theme.error),
None => "confirmed server state".fg(theme.muted),
})
.border_style(Style::default().fg(theme.muted))
.border_set(border::THICK);
let inner = mixer.inner(body);
mixer.render(body, buf);
self.render_streams(inner, buf);
Paragraph::new(Line::from(vec![
" ↑/↓ or j/k ".into(),
"select".cyan(),
" ←/→ ".into(),
"volume".cyan(),
" M ".into(),
"mute".cyan(),
" Home/End ".into(),
"0/100%".cyan(),
" Q/Esc ".into(),
"quit".cyan(),
" ↑/↓ or j/k ".fg(theme.foreground),
"select".fg(theme.secondary),
" ←/→ ".fg(theme.foreground),
"volume".fg(theme.secondary),
" M ".fg(theme.foreground),
"mute".fg(theme.secondary),
" Home/End ".fg(theme.foreground),
"0/100%".fg(theme.secondary),
" T ".fg(theme.foreground),
"theme".fg(theme.secondary),
" Q/Esc ".fg(theme.foreground),
"quit".fg(theme.secondary),
]))
.alignment(Alignment::Center)
.block(Block::bordered().border_set(border::ROUNDED))
.block(
Block::bordered()
.border_set(border::ROUNDED)
.border_style(Style::default().fg(theme.muted)),
)
.render(footer, buf);
}
}
impl<C> LiveTui<C> {
fn render_streams(&self, area: Rect, buf: &mut Buffer) {
let theme = self.theme.palette();
if self.snapshot.items.is_empty() {
Paragraph::new("No mixer objects are currently visible.")
.style(Style::default().fg(theme.muted))
.alignment(Alignment::Center)
.render(area, buf);
return;
@ -600,9 +646,9 @@ impl<C> LiveTui<C> {
if item.pending { " … pending" } else { "" }
);
let block = Block::bordered().title(title).border_style(if selected {
Style::default().fg(Color::Cyan)
Style::default().fg(theme.accent)
} else {
Style::default().fg(Color::DarkGray)
Style::default().fg(theme.muted)
});
let meter = block.inner(row_area);
block.render(row_area, buf);
@ -625,11 +671,17 @@ impl<C> LiveTui<C> {
|error| format!("ERROR: {error}"),
);
Gauge::default()
.gauge_style(Style::default().fg(if item.muted == Some(true) {
Color::Yellow
} else {
Color::Cyan
}))
.gauge_style(
Style::default()
.bg(theme.meter_track)
.fg(if item.error.is_some() {
theme.error
} else if item.muted == Some(true) {
theme.warning
} else {
theme.secondary
}),
)
.percent(percent)
.label(label)
.render(meter, buf);
@ -724,6 +776,42 @@ mod tests {
assert!(app.exit);
}
#[test]
fn theme_key_cycles_known_palettes_and_wraps() {
let mut app = LiveTui::new(DemoClient::default()).unwrap();
assert_eq!(app.theme(), ThemeName::Default);
for expected in [
ThemeName::Dracula,
ThemeName::Nord,
ThemeName::GruvboxDark,
ThemeName::CatppuccinMocha,
ThemeName::SolarizedDark,
ThemeName::Default,
] {
app.handle_key_event(press(KeyCode::Char('t')));
assert_eq!(app.theme(), expected);
}
}
#[test]
fn selected_theme_is_visible_and_changes_the_render_palette() {
let app = LiveTui::with_theme(DemoClient::default(), ThemeName::Dracula).unwrap();
let area = Rect::new(0, 0, 100, 20);
let mut buffer = Buffer::empty(area);
(&app).render(area, &mut buffer);
let rendered = buffer
.content
.iter()
.map(|cell| cell.symbol())
.collect::<String>();
assert!(rendered.contains("Dracula"));
assert!(buffer.content.iter().any(|cell| {
cell.fg == ratatui::style::Color::Rgb(189, 147, 249)
|| cell.bg == ratatui::style::Color::Rgb(40, 42, 54)
}));
}
#[test]
fn live_mixer_renders_status_and_stream_at_typical_size() {
let app = LiveTui::new(DemoClient::default()).unwrap();

130
tui/src/theme.rs Normal file
View File

@ -0,0 +1,130 @@
use ratatui::style::Color;
/// Built-in terminal color themes.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum ThemeName {
/// Terminal-native colors with the original cyan accent.
#[default]
Default,
Dracula,
Nord,
GruvboxDark,
CatppuccinMocha,
SolarizedDark,
}
impl ThemeName {
/// Human-readable theme name displayed by the TUI.
#[must_use]
pub const fn label(self) -> &'static str {
match self {
Self::Default => "Default",
Self::Dracula => "Dracula",
Self::Nord => "Nord",
Self::GruvboxDark => "Gruvbox Dark",
Self::CatppuccinMocha => "Catppuccin Mocha",
Self::SolarizedDark => "Solarized Dark",
}
}
/// Returns the next built-in theme, wrapping to the default.
#[must_use]
pub const fn next(self) -> Self {
match self {
Self::Default => Self::Dracula,
Self::Dracula => Self::Nord,
Self::Nord => Self::GruvboxDark,
Self::GruvboxDark => Self::CatppuccinMocha,
Self::CatppuccinMocha => Self::SolarizedDark,
Self::SolarizedDark => Self::Default,
}
}
pub(crate) const fn palette(self) -> ThemePalette {
match self {
Self::Default => ThemePalette {
background: Color::Reset,
foreground: Color::Reset,
accent: Color::Cyan,
secondary: Color::LightCyan,
muted: Color::DarkGray,
warning: Color::Yellow,
error: Color::LightRed,
header_foreground: Color::Black,
meter_track: Color::Black,
},
Self::Dracula => ThemePalette {
background: rgb(40, 42, 54),
foreground: rgb(248, 248, 242),
accent: rgb(189, 147, 249),
secondary: rgb(139, 233, 253),
muted: rgb(98, 114, 164),
warning: rgb(241, 250, 140),
error: rgb(255, 85, 85),
header_foreground: rgb(40, 42, 54),
meter_track: rgb(68, 71, 90),
},
Self::Nord => ThemePalette {
background: rgb(46, 52, 64),
foreground: rgb(216, 222, 233),
accent: rgb(136, 192, 208),
secondary: rgb(129, 161, 193),
muted: rgb(76, 86, 106),
warning: rgb(235, 203, 139),
error: rgb(191, 97, 106),
header_foreground: rgb(46, 52, 64),
meter_track: rgb(59, 66, 82),
},
Self::GruvboxDark => ThemePalette {
background: rgb(40, 40, 40),
foreground: rgb(235, 219, 178),
accent: rgb(215, 153, 33),
secondary: rgb(131, 165, 152),
muted: rgb(102, 92, 84),
warning: rgb(250, 189, 47),
error: rgb(251, 73, 52),
header_foreground: rgb(40, 40, 40),
meter_track: rgb(60, 56, 54),
},
Self::CatppuccinMocha => ThemePalette {
background: rgb(30, 30, 46),
foreground: rgb(205, 214, 244),
accent: rgb(203, 166, 247),
secondary: rgb(137, 180, 250),
muted: rgb(108, 112, 134),
warning: rgb(249, 226, 175),
error: rgb(243, 139, 168),
header_foreground: rgb(30, 30, 46),
meter_track: rgb(49, 50, 68),
},
Self::SolarizedDark => ThemePalette {
background: rgb(0, 43, 54),
foreground: rgb(131, 148, 150),
accent: rgb(42, 161, 152),
secondary: rgb(38, 139, 210),
muted: rgb(88, 110, 117),
warning: rgb(181, 137, 0),
error: rgb(220, 50, 47),
header_foreground: rgb(0, 43, 54),
meter_track: rgb(7, 54, 66),
},
}
}
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct ThemePalette {
pub background: Color,
pub foreground: Color,
pub accent: Color,
pub secondary: Color,
pub muted: Color,
pub warning: Color,
pub error: Color,
pub header_foreground: Color,
pub meter_track: Color,
}
const fn rgb(red: u8, green: u8, blue: u8) -> Color {
Color::Rgb(red, green, blue)
}