diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9518b94..58f2e2d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,11 @@ All notable changes to cloofy. The format follows [Keep a Changelog](https://kee
## [Unreleased]
+### Added
+
+- **Your terminal's colors.** Settings has Colors now. **Terminal** takes your terminal's background and text, with the shades in between mixed from them, so cloofy looks at home in a purple Ptyxis on Ubuntu or any other theme. **Auto** stays as before: Omarchy's theme there, cloofy's own dark colors elsewhere, which **cloofy** keeps everywhere.
+- **Your own colors.** Any of cloofy's colors in `~/.config/cloofy/theme.toml`, such as `bg = "#2b0a3d"`, go over the others. cloofy follows the file as you edit it.
+
### Changed
- **Rust 1.90** or newer builds cloofy from source, for the current D-Bus library on Linux and the library that draws Sixel images.
diff --git a/README.md b/README.md
index 57403ff..7bb6746 100644
--- a/README.md
+++ b/README.md
@@ -220,13 +220,14 @@ Installed with Homebrew, mise, a system package or Nix, cloofy leaves its update
## Settings
-,, the command palette, or a click on your name in the top bar opens the Settings page: crossfade, cover art and how covers are drawn, the accent color, icons, power saving, song notifications and update checks. Changes apply at once and cloofy saves them in `~/.config/cloofy/config.toml`, so there's no need to edit the file. You still can; it's read at start:
+,, the command palette, or a click on your name in the top bar opens the Settings page: crossfade, cover art and how covers are drawn, the colors, the accent color, icons, power saving, song notifications and update checks. Changes apply at once and cloofy saves them in `~/.config/cloofy/config.toml`, so there's no need to edit the file. You still can; it's read at start:
```toml
client_id = "your client id"
services = ["ytmusic"] # "spotify", "ytmusic" or both, in the switch's order; every one built in when missing
crossfade = 6 # seconds tracks overlap, 0 to 12; off when missing
covers = false # no cover art, for slower computers; on when missing
+colors = "terminal" # "cloofy" or "terminal"; Omarchy's theme there, cloofy's own elsewhere, when missing
accent = "violet" # "theme", "green", "violet", "pink", "blue" or "orange"; follows the cover when missing
images = "blocks" # "kitty", "sixel", "iterm2" or "blocks"; detected from the terminal when missing
icons = "nerd" # "nerd" or "text"; detected from the terminal when missing
@@ -236,7 +237,9 @@ update_check = false # don't look for new releases at start; on when missi
credentials = "keychain" # macOS: sign-ins in the Keychain instead of files (only here)
```
-The installer writes `services` with what you listen to. One config file serves every build, so a build leaves out the services it doesn't have. The `"theme"` accent is the Omarchy theme's, and cloofy's green elsewhere.
+The installer writes `services` with what you listen to. One config file serves every build, so a build leaves out the services it doesn't have. The `"theme"` accent is the one of the colors in use: `theme.toml`'s when it sets one, else the Omarchy theme's with Colors on Auto, and cloofy's green otherwise, also with Terminal.
+
+cloofy draws with its own dark colors, or with Omarchy's theme. With Colors set to Terminal, it takes your terminal's background and text instead, with the shades in between. To pick colors yourself, put any of `bg`, `surface`, `player`, `raised`, `text`, `muted`, `faint`, `accent` and the [others](integrations/omarchy/cloofy.toml.tpl) in `~/.config/cloofy/theme.toml`, as `bg = "#2b0a3d"`; they go over whichever colors are set, and cloofy follows the file as you edit it.
Power saving stops animations and redraws less often. Unless set otherwise, it turns on by itself with Low Power Mode on macOS and the Power Saver profile on Linux.
diff --git a/crates/cloofy-core/src/config.rs b/crates/cloofy-core/src/config.rs
index 6d6619c..19f0520 100644
--- a/crates/cloofy-core/src/config.rs
+++ b/crates/cloofy-core/src/config.rs
@@ -28,6 +28,9 @@ pub struct Config {
pub power_saving: Option,
/// A color name such as `"violet"`; follows the playing cover when missing.
pub accent: Option,
+ /// `"cloofy"` or `"terminal"`: cloofy's own colors, or the terminal's background and text.
+ /// Omarchy's theme where there is one, cloofy's own elsewhere, when missing.
+ pub colors: Option,
/// How covers reach the terminal: `"kitty"`, `"sixel"`, `"iterm2"` or `"blocks"`; detected
/// from the terminal when missing.
pub images: Option,
diff --git a/crates/cloofy-tui/src/app/browsing.rs b/crates/cloofy-tui/src/app/browsing.rs
index 7c14fd0..3c2015b 100644
--- a/crates/cloofy-tui/src/app/browsing.rs
+++ b/crates/cloofy-tui/src/app/browsing.rs
@@ -368,7 +368,7 @@ mod tests {
Paths { config: root.join("config"), data: root.join("data"), cache: root.join("cache"), keychain: false };
let (tx, _) = mpsc::unbounded_channel();
let loader = Loader::for_tests(services, problems, tx);
- App::new(loader, Preferences::default(), Start::Restore(Box::new(state)), paths, None, None)
+ App::new(loader, Preferences::default(), Start::Restore(Box::new(state)), paths, None, None, None)
}
fn page(view: SavedView) -> Page {
diff --git a/crates/cloofy-tui/src/app/mod.rs b/crates/cloofy-tui/src/app/mod.rs
index e920ce1..b0fe24e 100644
--- a/crates/cloofy-tui/src/app/mod.rs
+++ b/crates/cloofy-tui/src/app/mod.rs
@@ -35,6 +35,7 @@ use ratatui::{
use crate::clock::Instant;
use crate::{
backend::{self, Player, Remote, Service},
+ colors::Colors,
commands::Command,
fx::{Effect, Effects},
graphics::{INLINE_CELL, ImageProtocol, InlineLayer},
@@ -483,8 +484,11 @@ pub struct App {
/// The system's settings with the user's choice for power saving applied.
pub settings: Settings,
settings_checked: Instant,
+ /// Where the palette comes from; `None` in tests, which keep cloofy's own colors.
+ colors: Option,
pub accent: Accent,
- /// The color of the playing cover, for when the accent follows it.
+ /// The dominant color of the playing cover, for when the accent follows it; tuned to the
+ /// background when shown.
cover_accent: Option,
pub me: Option,
pub playlists: Vec,
@@ -605,8 +609,13 @@ impl App {
paths: Paths,
media: Option,
notifier: Option,
+ mut colors: Option,
) -> Self {
let system_settings = system_settings();
+ // The palette from the first frame on, and the accent the app starts with.
+ if let Some(palette) = colors.as_mut().and_then(Colors::poll) {
+ theme::set_palette(palette);
+ }
let mut accent = Accent::new();
if let Some(color) = prefs.accent.fixed() {
accent.jump(color);
@@ -656,6 +665,7 @@ impl App {
slept_at: None,
system_settings,
settings_checked: Instant::now(),
+ colors,
accent,
cover_accent: None,
me: None,
@@ -1477,13 +1487,9 @@ impl App {
if let Some(old) = self.now.cover.replace(Cover { url, picture }) {
self.terminal_out.extend(old.picture.terminal_delete());
}
- self.cover_accent = Some(accent);
+ self.cover_accent = accent;
if self.prefs.accent == AccentChoice::Cover {
- if self.settings.low_power {
- self.accent.jump(accent);
- } else {
- self.accent.set(accent);
- }
+ self.show_accent();
}
}
Err(err) => tracing::warn!("cover {url}: {err}"),
diff --git a/crates/cloofy-tui/src/app/settings.rs b/crates/cloofy-tui/src/app/settings.rs
index 2b54189..0c46d62 100644
--- a/crates/cloofy-tui/src/app/settings.rs
+++ b/crates/cloofy-tui/src/app/settings.rs
@@ -8,6 +8,7 @@ use crossterm::event::{KeyCode, KeyEvent};
use super::{App, COVER_SIZE, Focus, ImageSlot};
use crate::{
backend,
+ colors::Colors,
commands::Command,
preferences::{AccentChoice, Setting},
theme,
@@ -88,6 +89,12 @@ impl App {
}
Setting::Covers => self.drop_covers(),
Setting::Images => self.set_image_protocol(self.prefs.images),
+ Setting::Colors => {
+ if let Some(colors) = &mut self.colors {
+ colors.set_choice(self.prefs.colors);
+ }
+ self.poll_colors();
+ }
Setting::Accent => self.show_accent(),
Setting::Icons => crate::icons::init(self.prefs.icons.config()),
Setting::PowerSaving => self.settings = self.prefs.apply(self.system_settings),
@@ -101,9 +108,11 @@ impl App {
self.save_setting(setting);
}
- /// Moves the accent to the color the setting, the cover or the palette gives it now.
- fn show_accent(&mut self) {
- let color = self.prefs.accent.fixed().or(self.cover_accent).unwrap_or(theme::palette().accent);
+ /// Moves the accent to the color the setting, the cover or the palette gives it now. The
+ /// cover's is tuned to the background here, so it follows a change of colors.
+ pub(super) fn show_accent(&mut self) {
+ let cover = self.cover_accent.map(theme::cover_accent);
+ let color = self.prefs.accent.fixed().or(cover).unwrap_or(theme::palette().accent);
if self.settings.low_power {
self.accent.jump(color);
} else {
@@ -111,12 +120,19 @@ impl App {
}
}
- /// Draws with the system theme's `palette` from the next frame on. The accent goes along
- /// where it comes from the palette, and the fixed ones adapt to a light background.
- #[cfg(target_os = "linux")]
- pub fn set_palette(&mut self, palette: theme::Palette) {
+ /// Draws with new colors from the next frame on when they changed, by the setting, Omarchy's
+ /// theme or `theme.toml`. The accent goes along where it comes from the palette, and the
+ /// fixed ones adapt to a light background. Returns whether the colors changed.
+ pub fn poll_colors(&mut self) -> bool {
+ let Some(palette) = self.colors.as_mut().and_then(Colors::poll) else { return false };
theme::set_palette(palette);
self.show_accent();
+ true
+ }
+
+ /// Whether the terminal told its colors, for the Terminal choice.
+ pub fn knows_terminal_colors(&self) -> bool {
+ self.colors.as_ref().is_some_and(Colors::knows_terminal)
}
/// Writes `setting` to the config file. The demo keeps changes until it closes.
diff --git a/crates/cloofy-tui/src/colors.rs b/crates/cloofy-tui/src/colors.rs
new file mode 100644
index 0000000..594abe4
--- /dev/null
+++ b/crates/cloofy-tui/src/colors.rs
@@ -0,0 +1,256 @@
+//! Where the interface's colors come from: cloofy's own, Omarchy's theme or the terminal's, as
+//! the Colors setting says, with `theme.toml` from the config folder over them. Follows
+//! Omarchy's theme and the file as they change, without a restart.
+
+use std::{
+ fs,
+ path::{Path, PathBuf},
+ time::{Duration, Instant, SystemTime},
+};
+
+use ratatui_image::picker::Capability;
+
+use crate::{
+ omarchy,
+ preferences::ColorChoice,
+ theme::{Palette, Rgb},
+};
+
+/// How often to look at `theme.toml` again.
+const CHECK_INTERVAL: Duration = Duration::from_secs(1);
+
+/// What the terminal answered at startup when asked for its colors.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub struct TerminalColors {
+ pub background: Rgb,
+ /// Some terminals tell only their background.
+ pub foreground: Option,
+}
+
+impl TerminalColors {
+ /// The colors among what the terminal answered; `None` without its background.
+ pub fn from_capabilities(capabilities: &[Capability]) -> Option {
+ let background = capabilities.iter().find_map(|capability| match capability {
+ Capability::Background(r, g, b) => Some(Rgb(*r, *g, *b)),
+ _ => None,
+ })?;
+ let foreground = capabilities.iter().find_map(|capability| match capability {
+ Capability::Foreground(r, g, b) => Some(Rgb(*r, *g, *b)),
+ _ => None,
+ });
+ Some(Self { background, foreground })
+ }
+
+ /// The palette for these colors: shades mixed like an Omarchy theme's. Without the text
+ /// color, cloofy's own text on a dark background and its background color on a light one.
+ fn palette(self) -> Palette {
+ let foreground = self.foreground.unwrap_or(if self.background.is_light() {
+ Rgb::of(Palette::DEFAULT.bg)
+ } else {
+ Rgb::of(Palette::DEFAULT.text)
+ });
+ omarchy::terminal_palette(self.background, foreground)
+ }
+}
+
+/// The palette to draw with, and when it changes.
+pub struct Colors {
+ choice: ColorChoice,
+ /// The terminal's palette, when it told its colors.
+ terminal: Option,
+ /// Omarchy's theme and its palette as last read; `None` without Omarchy.
+ omarchy: Option<(omarchy::ThemeWatch, Option)>,
+ custom: CustomFile,
+ /// Whether the palette may differ from the one [`Colors::poll`] returned last.
+ stale: bool,
+ shown: Option,
+}
+
+impl Colors {
+ /// `config` is the folder `theme.toml` is looked for in.
+ pub fn new(choice: ColorChoice, terminal: Option, config: &Path) -> Self {
+ let omarchy = if cfg!(target_os = "linux") { omarchy::ThemeWatch::new() } else { None };
+ Self {
+ choice,
+ terminal: terminal.map(TerminalColors::palette),
+ omarchy: omarchy.map(|watch| (watch, None)),
+ custom: CustomFile::new(config.join("theme.toml")),
+ stale: true,
+ shown: None,
+ }
+ }
+
+ pub fn set_choice(&mut self, choice: ColorChoice) {
+ self.stale |= choice != self.choice;
+ self.choice = choice;
+ }
+
+ /// Whether the terminal told its colors at startup.
+ pub fn knows_terminal(&self) -> bool {
+ self.terminal.is_some()
+ }
+
+ /// The palette the first time, then again whenever it changed: by the setting, Omarchy's
+ /// theme or `theme.toml`. Looks at the files at most every second, so it may be called on
+ /// every tick.
+ pub fn poll(&mut self) -> Option {
+ if let Some((watch, palette)) = &mut self.omarchy
+ && let Some(theme) = watch.poll()
+ {
+ *palette = Some(theme);
+ self.stale = true;
+ }
+ self.stale |= self.custom.poll();
+ if !std::mem::take(&mut self.stale) {
+ return None;
+ }
+ let palette = self.palette();
+ (self.shown != Some(palette)).then(|| {
+ self.shown = Some(palette);
+ palette
+ })
+ }
+
+ fn palette(&self) -> Palette {
+ let omarchy = self.omarchy.as_ref().and_then(|(_, palette)| *palette);
+ let base = match self.choice {
+ ColorChoice::Auto => omarchy,
+ ColorChoice::Cloofy => None,
+ ColorChoice::Terminal => self.terminal,
+ };
+ let base = base.unwrap_or(Palette::DEFAULT);
+ match &self.custom.text {
+ Some(text) => omarchy::apply(text, base),
+ None => base,
+ }
+ }
+}
+
+/// `theme.toml`, read again whenever it changes.
+struct CustomFile {
+ path: PathBuf,
+ checked: Option,
+ /// When the file last changed, as of the last look; `None` before the first look.
+ seen: Option