From cde6e119c679075f45d53dd82478578f3ded2ea3 Mon Sep 17 00:00:00 2001 From: danny Date: Fri, 16 Oct 2026 15:49:23 +0200 Subject: [PATCH] M1.10: light theme, live theme switching, editor tokens - theme::LIGHT next to DARK with the 10 new tokens (editor selection, active line, cursor, gutter, match, font size, tab active/modified, notice); light fg-muted, accent and error darkened for WCAG AA - theme.list, theme.systemPreference, themeChanged event when the resolved theme changes (settings.set/reset appearance.theme, or the OS preference in system mode) - desktop init script and window background from the stored setting; system mode uses a prefers-color-scheme media query for the first frame - ui/src/theme.ts applies tokens to :root and color-scheme live; editor, tabs and notice drop their var() fallbacks - Vitest WCAG AA contrast check against a Rust-maintained snapshot, DOM tests, headless control-channel test - docs: architecture Themes, parity rows, ui-parity, gaps, roadmaps Co-Authored-By: Claude Opus 5.5 --- ROADMAP.md | 8 +- apps/lutra-desktop/src/main.rs | 44 +++++- crates/control/tests/theme.rs | 134 ++++++++++++++++ crates/engine/src/cmd/mod.rs | 3 + crates/engine/src/cmd/settings.rs | 18 ++- crates/engine/src/cmd/theme.rs | 102 +++++++++++++ crates/engine/src/engine.rs | 2 + crates/engine/src/event.rs | 26 ++++ crates/engine/src/state.rs | 3 + crates/engine/src/theme.rs | 186 +++++++++++++++++++++-- crates/engine/tests/settings.rs | 8 +- crates/engine/tests/theme.rs | 154 +++++++++++++++++++ docs/architecture.md | 18 ++- docs/gaps.md | 5 +- docs/roadmap.md | 5 +- docs/target-app-parity.md | 4 +- docs/ui-parity.md | 4 +- ui/src/App.vue | 14 +- ui/src/components/editor/EditorArea.vue | 2 +- ui/src/components/editor/EditorTabs.vue | 4 +- ui/src/components/editor/extensions.ts | 37 ++--- ui/src/i18n/en.json | 4 +- ui/src/ipc.ts | 3 +- ui/src/styles/base.css | 3 +- ui/src/theme.ts | 109 +++++++++++++ ui/tests/i18n/catalog.test.ts | 14 +- ui/tests/theme/contrast.test.ts | 94 ++++++++++++ ui/tests/theme/theme.test.ts | 194 ++++++++++++++++++++++++ ui/tests/theme/themes.json | 62 ++++++++ 29 files changed, 1192 insertions(+), 72 deletions(-) create mode 100644 crates/control/tests/theme.rs create mode 100644 crates/engine/src/cmd/theme.rs create mode 100644 crates/engine/tests/theme.rs create mode 100644 ui/src/theme.ts create mode 100644 ui/tests/theme/contrast.test.ts create mode 100644 ui/tests/theme/theme.test.ts create mode 100644 ui/tests/theme/themes.json diff --git a/ROADMAP.md b/ROADMAP.md index 41f5d18..b89690e 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -26,7 +26,7 @@ Dimension hours overlap: language, framework and tooling hours are part of the f | Dimension | % | One agent (h) | Doc | |---|---:|---:|---| | Features (depth) | ~1.4% | ~2,920 | [target-app-parity.md](docs/target-app-parity.md) | -| UI/UX fidelity | 0% | ~150 on top of features | [ui-parity.md](docs/ui-parity.md) | +| UI/UX fidelity | 1% (est.) | ~150 on top of features | [ui-parity.md](docs/ui-parity.md) | | PHP language support | 0% | ~920 (in features) | [language-parity.md](docs/language-parity.md) | | Frameworks (Symfony, Laravel, Shopware, WordPress) | 0% | ~300 (in features) | [framework-parity.md](docs/framework-parity.md) | | Tooling (Git, terminal, debugger, tests, Composer, DB) | 0% | ~730 (in features) | [tooling-parity.md](docs/tooling-parity.md) | @@ -35,7 +35,7 @@ Dimension hours overlap: language, framework and tooling hours are part of the f | Stability | 5% | ~100 | [gaps.md › G11](docs/gaps.md) | | Agent automation | 10% | ~60 | AGENTS.md | -Stability 5%: no-panic lints, the engine guard and a fuzzed control protocol exist; the recovery journal does not. Agent automation 10%: the control channel (ping, execute, listCommands, screenshot) works; MCP and the CLI do not exist yet. Both are estimated. Localization 5% (estimated): every UI string comes from an English catalog enforced by lint; engine messages, the language switch and German are missing. +Stability 5%: no-panic lints, the engine guard and a fuzzed control protocol exist; the recovery journal does not. Agent automation 10%: the control channel (ping, execute, listCommands, screenshot) works; MCP and the CLI do not exist yet. Both are estimated. Localization 5% (estimated): every UI string comes from an English catalog enforced by lint; engine messages, the language switch and German are missing. UI/UX fidelity 1% (estimated): light and dark themes switch live and pass a WCAG AA contrast test; the rest of the ui-parity checklist is open. ## Features @@ -60,7 +60,7 @@ Stability 5%: no-panic lints, the engine guard and a fuzzed control protocol exi | HTTP client | 0% | ~60 | | Web languages (JS/TS, Vue, CSS, Twig, Blade) | 0% | ~200 | | Docker and remote | 0% | ~120 | -| Settings, keymaps, themes | 0% | ~60 | +| Settings, keymaps, themes | 4% (est.) | ~60 | | Plug-ins and ecosystem | 0% | ~120 | | AI features | 0% | ~60 | @@ -77,6 +77,7 @@ All hours estimated. Weights, evidence and the missing items per area: [target-a | Date | What landed | |---|---| +| 2026-10-16 | M1.10: Lutra Light next to Lutra Dark, switched live through the `appearance.theme` setting or following the OS (`system`); the window starts in the stored theme; the editor, tabs and notices get their own tokens; both themes pass a WCAG AA contrast test. | | 2026-10-15 | M1.11: every interface string comes from an English message catalog (`ui/src/i18n/en.json`), enforced by a lint rule and a catalog test; the groundwork for German. | | 2026-10-15 | M1.6: files open in tabs with a CodeMirror editor synced to the engine; save, save all, close with a Save / Don't Save / Cancel question, a notice when a file with unsaved changes changes on disk; a 1 MB file opens in about 90 ms. | | 2026-10-15 | M1 so far: text buffer, VFS with native watching, engine workspace (files, buffers, edit protocol, events), desktop bridge: open a folder by picker or command line, browse it in the project tree with live updates from disk. | @@ -87,6 +88,7 @@ All hours estimated. Weights, evidence and the missing items per area: [target-a | Date | Change | Summary | |---|---|---| +| 2026-10-16 | minor | M1.10: UI/UX fidelity 1%, Settings row 4% (estimates), progress log | | 2026-10-15 | minor | M1.11: localization 5% (English UI catalog), progress log | | 2026-10-15 | minor | Cycle C1 review: stage line, breadth estimate, hours recalibrated ×0.1 | | 2026-10-15 | minor | Feature depth ~1.4%: tabs and editor (M1.6) | diff --git a/apps/lutra-desktop/src/main.rs b/apps/lutra-desktop/src/main.rs index c11b33a..f6f7b5b 100644 --- a/apps/lutra-desktop/src/main.rs +++ b/apps/lutra-desktop/src/main.rs @@ -1,6 +1,7 @@ //! The Lutra desktop app (layer L6): a Tauri 2 shell around the engine. //! -//! Builds the main window with the theme tokens injected before first paint, +//! Builds the main window with the stored theme's tokens injected before +//! first paint, //! bridges frontend IPC to engine commands and engine events to the window //! (see [`host`]), opens the project given on the command line, and //! optionally serves the JSON control channel (`--control PORT`). @@ -59,7 +60,6 @@ fn main() -> ExitCode { fn run(args: &args::Args) -> Result<(), String> { let slot: Arc>> = Arc::new(OnceLock::new()); let setup_slot = slot.clone(); - let theme = theme::DARK; let initial_path = args.path.clone(); let app = tauri::Builder::default() .plugin(tauri_plugin_dialog::init()) @@ -71,15 +71,19 @@ fn run(args: &args::Args) -> Result<(), String> { .setup(move |app| { let setup_host = setup_slot.get().ok_or("the host is not ready")?; setup_host.attach(app.handle().clone()); + let setting = stored_theme(setup_host); let mut window = WebviewWindowBuilder::new(app, MAIN_WINDOW, WebviewUrl::default()) .title(WINDOW_TITLE) .inner_size(1200.0, 800.0) .min_inner_size(640.0, 400.0) - .initialization_script(theme::init_script(&theme)); - if let Some(color) = token_color(&theme, "bg") { + .initialization_script(theme::init_script(&setting)); + if let Some(color) = token_color(&theme::resolve(&setting, None), "bg") { window = window.background_color(color); } - window.build()?; + let window = window.build()?; + if setting == theme::SYSTEM { + follow_system_background(&window); + } if let Some(path) = &initial_path && let Err(e) = setup_host.open_project(path) { @@ -139,6 +143,36 @@ fn log_startup_events(events: &[Event]) { } } +/// The stored `appearance.theme` value, `system` if it cannot be read. +fn stored_theme(host: &Host) -> String { + host.run( + "settings.get", + serde_json::json!({ "keys": ["appearance.theme"] }), + ) + .ok() + .and_then(|v| { + v.get("values")? + .get("appearance.theme")? + .as_str() + .map(str::to_string) + }) + .unwrap_or_else(|| theme::SYSTEM.to_string()) +} + +/// In "system" mode, sets the window background to the theme the OS +/// prefers; the page itself follows the OS through the init script's +/// `prefers-color-scheme` query. Failures are ignored: the background only +/// shows before the first paint, and the dark default stays. +fn follow_system_background(window: &tauri::WebviewWindow) { + let Ok(os) = window.theme() else { + return; + }; + let resolved = theme::resolve(theme::SYSTEM, Some(os == tauri::Theme::Dark)); + if let Some(color) = token_color(&resolved, "bg") { + let _ = window.set_background_color(Some(color)); + } +} + /// Reads a `#rrggbb` theme token as an opaque colour for the window /// background, so that no white frame shows before the page paints. fn token_color(theme: &theme::Theme, name: &str) -> Option { diff --git a/crates/control/tests/theme.rs b/crates/control/tests/theme.rs new file mode 100644 index 0000000..76b9402 --- /dev/null +++ b/crates/control/tests/theme.rs @@ -0,0 +1,134 @@ +//! Theme switching over a real TCP socket: `settings.set appearance.theme` +//! and `theme.systemPreference` stream `themeChanged` with the theme's +//! tokens to `events.subscribe` clients, the way the desktop window gets +//! them. + +#![allow( + clippy::unwrap_used, + clippy::expect_used, + clippy::indexing_slicing, + clippy::panic +)] + +use std::io::{BufRead, BufReader, Write}; +use std::net::TcpStream; +use std::sync::Arc; +use std::time::Duration; + +use lutra_engine::theme; +use lutra_testkit::EngineBackend; +use serde_json::{Value, json}; + +/// A client that collects event lines and returns responses. +struct Client { + reader: BufReader, + writer: TcpStream, + events: Vec, +} + +impl Client { + fn connect(addr: std::net::SocketAddr) -> Self { + let stream = TcpStream::connect(addr).unwrap(); + stream + .set_read_timeout(Some(Duration::from_secs(5))) + .unwrap(); + Self { + writer: stream.try_clone().unwrap(), + reader: BufReader::new(stream), + events: Vec::new(), + } + } + + fn line(&mut self) -> Value { + let mut line = String::new(); + self.reader.read_line(&mut line).expect("line within 5 s"); + serde_json::from_str(&line).unwrap() + } + + /// Sends a request and returns its response, collecting event lines that + /// arrive before it. + fn call(&mut self, request: Value) -> Value { + self.writer + .write_all(format!("{request}\n").as_bytes()) + .unwrap(); + loop { + let line = self.line(); + if line.get("event").is_some() { + self.events.push(line["event"].clone()); + } else { + return line; + } + } + } + + /// Waits for the next `themeChanged` event (events arrive from a + /// subscriber queue, possibly after the response) and drops the events + /// before it. + fn next_theme(&mut self) -> Value { + loop { + if let Some(at) = self.events.iter().position(|e| e["kind"] == "themeChanged") { + let theme = self.events.remove(at); + self.events.drain(..at); + return theme; + } + let line = self.line(); + if line.get("event").is_some() { + self.events.push(line["event"].clone()); + } + } + } +} + +fn execute(command: &str, params: Value) -> Value { + json!({"id": 2, "method": "engine.execute", "params": {"command": command, "params": params}}) +} + +fn tokens(theme: &theme::Theme) -> Value { + serde_json::to_value(theme::token_map(theme)).unwrap() +} + +#[test] +fn switching_streams_theme_changed_with_tokens() { + let dir = tempfile::tempdir().unwrap(); + let backend = Arc::new(EngineBackend::with_config(lutra_testkit::engine_config( + dir.path(), + ))); + let server = lutra_control::start(0, backend.clone()).unwrap(); + let mut client = Client::connect(server.local_addr()); + client.call(json!({"id": 1, "method": "events.subscribe"})); + + let r = client.call(execute("theme.list", Value::Null)); + assert_eq!(r["result"][1]["id"], "lutra-light", "{r}"); + + let r = client.call(execute( + "settings.set", + json!({"key": "appearance.theme", "value": "lutra-light"}), + )); + assert_eq!(r["result"]["value"], "lutra-light", "{r}"); + let changed = client.next_theme(); + assert_eq!(changed["id"], "lutra-light"); + assert_eq!(changed["dark"], false); + assert_eq!(changed["tokens"], tokens(&theme::LIGHT)); + + client.call(execute( + "settings.set", + json!({"key": "appearance.theme", "value": "lutra-dark"}), + )); + let changed = client.next_theme(); + assert_eq!(changed["id"], "lutra-dark"); + assert_eq!(changed["dark"], true); + assert_eq!(changed["tokens"], tokens(&theme::DARK)); + + client.call(execute( + "settings.set", + json!({"key": "appearance.theme", "value": "system"}), + )); + let r = client.call(execute("theme.systemPreference", json!({"dark": false}))); + assert_eq!(r["result"]["id"], "lutra-light", "{r}"); + let changed = client.next_theme(); + assert_eq!( + changed["id"], "lutra-light", + "switching from dark to system on an unreported (dark) OS must not emit" + ); + assert_eq!(changed["tokens"]["--lt-editor-selection-bg"], "#e5d7c9"); +} diff --git a/crates/engine/src/cmd/mod.rs b/crates/engine/src/cmd/mod.rs index 34744ad..83487ce 100644 --- a/crates/engine/src/cmd/mod.rs +++ b/crates/engine/src/cmd/mod.rs @@ -6,6 +6,7 @@ mod file; mod params; mod project; mod settings; +pub mod theme; use crate::{EngineError, Registry}; @@ -30,5 +31,7 @@ pub fn register_builtins(registry: &mut Registry) -> Result<(), EngineError> { registry.register(Box::new(settings::Get))?; registry.register(Box::new(settings::Set))?; registry.register(Box::new(settings::Reset))?; + registry.register(Box::new(theme::List))?; + registry.register(Box::new(theme::SystemPreference))?; Ok(()) } diff --git a/crates/engine/src/cmd/settings.rs b/crates/engine/src/cmd/settings.rs index 1b353b3..f6a9e23 100644 --- a/crates/engine/src/cmd/settings.rs +++ b/crates/engine/src/cmd/settings.rs @@ -5,6 +5,7 @@ use serde::Deserialize; use serde_json::{Map, Value, json}; use crate::cmd::params::parse; +use crate::cmd::theme; use crate::settings::{self, DEFS, SetError}; use crate::{Command, CommandSpec, EngineError, Event, Outcome, State}; @@ -96,11 +97,12 @@ impl Command for Set { fn run(&self, state: &mut State, params: Value) -> Result { let id = self.spec().id; let p: SetParams = parse(id, params)?; + let before = theme::resolved(state); let changed = state .settings .set(&p.key, p.value) .map_err(|e| set_error(id, e))?; - finish(state, &p.key, changed) + finish(state, &p.key, changed, before) } } @@ -129,8 +131,9 @@ impl Command for Reset { fn run(&self, state: &mut State, params: Value) -> Result { let id = self.spec().id; let p: ResetParams = parse(id, params)?; + let before = theme::resolved(state); let changed = state.settings.reset(&p.key).map_err(|e| set_error(id, e))?; - finish(state, &p.key, changed) + finish(state, &p.key, changed, before) } } @@ -144,12 +147,19 @@ fn set_error(command: &str, error: SetError) -> EngineError { } } -/// Emits `settingsChanged` if the value changed and returns `{ value }`. -fn finish(state: &mut State, key: &str, changed: bool) -> Result { +/// Emits `settingsChanged` if the value changed, then `themeChanged` if the +/// resolved theme is no longer `before`, and returns `{ value }`. +fn finish( + state: &mut State, + key: &str, + changed: bool, + before: crate::theme::Theme, +) -> Result { if changed { state.emit(Event::SettingsChanged { keys: vec![key.to_string()], }); + theme::emit_if_changed(state, before); } let value = state .settings diff --git a/crates/engine/src/cmd/theme.rs b/crates/engine/src/cmd/theme.rs new file mode 100644 index 0000000..c6acc34 --- /dev/null +++ b/crates/engine/src/cmd/theme.rs @@ -0,0 +1,102 @@ +//! Theme commands: `theme.list` and `theme.systemPreference`. Switching +//! themes goes through `settings.set appearance.theme`; whenever the +//! resolved theme changes, `themeChanged` carries its tokens. + +use serde::Deserialize; +use serde_json::{Value, json}; + +use crate::cmd::params::parse; +use crate::theme::{self, BUILTIN, Theme}; +use crate::{Command, CommandSpec, EngineError, Event, Outcome, State}; + +/// The setting that selects the theme. +pub const SETTING: &str = "appearance.theme"; + +/// The theme the current settings and OS preference resolve to. +pub fn resolved(state: &State) -> Theme { + let setting = state.settings.get(SETTING); + let id = setting + .as_ref() + .and_then(Value::as_str) + .unwrap_or(theme::SYSTEM); + theme::resolve(id, state.system_dark) +} + +/// The `themeChanged` event for a theme. +pub fn changed_event(theme: &Theme) -> Event { + Event::ThemeChanged { + id: theme.id.to_string(), + dark: theme.dark, + tokens: theme::token_map(theme), + } +} + +/// Emits `themeChanged` if the resolved theme is no longer `before`. +pub fn emit_if_changed(state: &mut State, before: Theme) { + let now = resolved(state); + if now != before { + state.emit(changed_event(&now)); + } +} + +/// `theme.list`: the built-in themes. +pub struct List; + +impl Command for List { + fn spec(&self) -> &CommandSpec { + &CommandSpec { + id: "theme.list", + label: "List Themes", + menu_path: None, + default_shortcut: None, + params: "none; returns [{ id, label, dark }], label is a message-catalog key", + } + } + + fn run(&self, _state: &mut State, _params: Value) -> Result { + let list: Vec<_> = BUILTIN + .iter() + .map(|t| json!({ "id": t.id, "label": t.label_key, "dark": t.dark })) + .collect(); + Ok(Outcome::value(Value::Array(list))) + } +} + +/// Params of `theme.systemPreference`. +#[derive(Deserialize)] +#[serde(deny_unknown_fields)] +struct PreferenceParams { + /// Whether the OS prefers a dark theme. + dark: bool, +} + +/// `theme.systemPreference`: the frontend reports the OS colour preference; +/// in "system" mode a change of it switches the theme. +pub struct SystemPreference; + +impl Command for SystemPreference { + fn spec(&self) -> &CommandSpec { + &CommandSpec { + id: "theme.systemPreference", + label: "Report System Theme", + menu_path: None, + default_shortcut: None, + params: "{ dark: bool }; returns the resolved theme { id, dark, tokens }; emits themeChanged when it changes", + } + } + + fn run(&self, state: &mut State, params: Value) -> Result { + let p: PreferenceParams = parse(self.spec().id, params)?; + let before = resolved(state); + state.system_dark = Some(p.dark); + emit_if_changed(state, before); + let now = resolved(state); + let value = serde_json::to_value(changed_event(&now)) + .map_err(|e| EngineError::Internal(e.to_string()))?; + let Value::Object(mut fields) = value else { + return Err(EngineError::Internal("theme is not an object".into())); + }; + fields.remove("kind"); + Ok(Outcome::value(Value::Object(fields))) + } +} diff --git a/crates/engine/src/engine.rs b/crates/engine/src/engine.rs index 12ce917..b13de84 100644 --- a/crates/engine/src/engine.rs +++ b/crates/engine/src/engine.rs @@ -288,6 +288,8 @@ mod tests { "settings.reset", "settings.set", "test.disabled", + "theme.list", + "theme.systemPreference", ] ); let by_id = |id: &str| list.iter().find(|c| c.id == id).unwrap(); diff --git a/crates/engine/src/event.rs b/crates/engine/src/event.rs index 5bda5a8..a5a54e2 100644 --- a/crates/engine/src/event.rs +++ b/crates/engine/src/event.rs @@ -10,6 +10,8 @@ //! Serialised as `{"kind": "", ...fields in camelCase}`. //! Paths are project-relative with `/` separators, the root is `""`. +use std::collections::BTreeMap; + use serde::Serialize; use serde_json::{Map, Value}; @@ -83,6 +85,17 @@ pub enum Event { /// The changed keys. keys: Vec, }, + /// The resolved theme changed, through `appearance.theme` or, in + /// "system" mode, the OS preference. The frontend writes the tokens onto + /// `:root` and sets `color-scheme`. + ThemeChanged { + /// Theme id, e.g. `lutra-light`. + id: String, + /// Whether the theme is dark. + dark: bool, + /// Every token as `--lt-` → CSS value. + tokens: BTreeMap, + }, /// A message for the user, shown as a toast. Notification { /// Unique id of this notification, for dismissing it. @@ -166,4 +179,17 @@ mod tests { json!({"kind": "settingsChanged", "keys": ["editor.fontSize"]}) ); } + + #[test] + fn theme_changed_shape() { + let e = Event::ThemeChanged { + id: "lutra-light".into(), + dark: false, + tokens: [("--lt-bg".to_string(), "#f4f1ec".to_string())].into(), + }; + assert_eq!( + serde_json::to_value(e).unwrap(), + json!({"kind": "themeChanged", "id": "lutra-light", "dark": false, "tokens": {"--lt-bg": "#f4f1ec"}}) + ); + } } diff --git a/crates/engine/src/state.rs b/crates/engine/src/state.rs index 3af2aff..ab5b13c 100644 --- a/crates/engine/src/state.rs +++ b/crates/engine/src/state.rs @@ -18,6 +18,9 @@ pub struct State { pub buffers: Buffers, /// Settings, saved to the config directory when the engine has one. pub settings: Settings, + /// Whether the OS prefers a dark theme, as the frontend reported it with + /// `theme.systemPreference`; `None` until then. + pub system_dark: Option, /// Where the engine stores its files; `None` for an engine without /// persistence ([`crate::Engine::new`]). pub config: Option, diff --git a/crates/engine/src/theme.rs b/crates/engine/src/theme.rs index c859d12..acd01d5 100644 --- a/crates/engine/src/theme.rs +++ b/crates/engine/src/theme.rs @@ -2,21 +2,33 @@ //! //! Themes are defined here in Rust and rendered as CSS custom properties //! (`--lt-`). Frontend components use only `var(--lt-…)`. The palettes -//! are Lutra's own: warm otter browns with a copper accent. +//! are Lutra's own: warm otter browns with a copper accent. Text and +//! background pairs meet WCAG AA in both themes; `ui/tests/theme` checks it +//! against the snapshot `ui/tests/theme/themes.json`, which the test +//! `ui_snapshot_is_current` keeps in step with this file. +//! +//! The setting `appearance.theme` holds a theme id or [`SYSTEM`]. "System" +//! follows the OS: the frontend reports the OS preference and +//! [`resolve`] picks the theme. + +use std::collections::BTreeMap; /// A named set of token values. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct Theme { /// Stable id used in settings, e.g. `lutra-dark`. pub id: &'static str, - /// Display name. - pub name: &'static str, + /// Message-catalog key of the display name. + pub label_key: &'static str, /// Whether the theme is dark, for the window chrome and `color-scheme`. pub dark: bool, /// Token names (without the `--lt-` prefix) and CSS values. pub tokens: &'static [(&'static str, &'static str)], } +/// The `appearance.theme` value that follows the OS preference. +pub const SYSTEM: &str = "system"; + /// Tokens shared by every theme (fonts and sizes). const COMMON: &[(&str, &str)] = &[ ( @@ -29,12 +41,13 @@ const COMMON: &[(&str, &str)] = &[ ), ("font-size-ui", "13px"), ("font-size-small", "12px"), + ("font-size-editor", "14px"), ]; /// The default dark theme. pub const DARK: Theme = Theme { id: "lutra-dark", - name: "Lutra Dark", + label_key: "theme.lutraDark", dark: true, tokens: &[ ("bg", "#1f1d1b"), @@ -46,24 +59,42 @@ pub const DARK: Theme = Theme { ("error", "#ef7b6c"), ("statusbar-bg", "#24211f"), ("statusbar-fg", "#b8afa6"), + ("editor-selection-bg", "#513f2c"), + ("editor-active-line-bg", "#232221"), + ("editor-cursor", "#d39a5c"), + ("editor-gutter-bg", "#191817"), + ("editor-gutter-fg", "#9a928a"), + ("editor-match-bg", "#3a2f23"), + ("tab-active-bg", "#191817"), + ("tab-modified", "#d39a5c"), + ("notice-bg", "#3a3025"), ], }; /// The light theme. pub const LIGHT: Theme = Theme { id: "lutra-light", - name: "Lutra Light", + label_key: "theme.lutraLight", dark: false, tokens: &[ ("bg", "#f4f1ec"), ("editor-bg", "#fbfaf8"), ("fg", "#2a2622"), - ("fg-muted", "#7a7168"), + ("fg-muted", "#6b625a"), ("border", "#ddd6cd"), - ("accent", "#a8662a"), - ("error", "#c2412f"), + ("accent", "#965a22"), + ("error", "#b23a29"), ("statusbar-bg", "#ece7e0"), ("statusbar-fg", "#5a5149"), + ("editor-selection-bg", "#e5d7c9"), + ("editor-active-line-bg", "#f1efed"), + ("editor-cursor", "#965a22"), + ("editor-gutter-bg", "#fbfaf8"), + ("editor-gutter-fg", "#6b625a"), + ("editor-match-bg", "#ece2d8"), + ("tab-active-bg", "#fbfaf8"), + ("tab-modified", "#965a22"), + ("notice-bg", "#e9dfd4"), ], }; @@ -75,6 +106,34 @@ pub fn by_id(id: &str) -> Option { BUILTIN.iter().copied().find(|t| t.id == id) } +/// The theme for an `appearance.theme` value. +/// +/// # Parameters +/// - `setting`: a theme id or [`SYSTEM`]. +/// - `system_dark`: the OS preference; `None` while the frontend has not +/// reported it, which counts as dark. +/// +/// Returns [`DARK`] for an unknown id. +pub fn resolve(setting: &str, system_dark: Option) -> Theme { + if setting == SYSTEM { + return if system_dark.unwrap_or(true) { + DARK + } else { + LIGHT + }; + } + by_id(setting).unwrap_or(DARK) +} + +/// Every token of a theme, shared ones included, as `--lt-` → value. +pub fn token_map(theme: &Theme) -> BTreeMap { + COMMON + .iter() + .chain(theme.tokens) + .map(|(name, value)| (format!("--lt-{name}"), (*value).to_string())) + .collect() +} + /// Renders a theme as a `:root { … }` rule of CSS custom properties. pub fn css_variables(theme: &Theme) -> String { let mut css = String::from(":root {\n"); @@ -89,11 +148,26 @@ pub fn css_variables(theme: &Theme) -> String { css } -/// JavaScript that installs the theme's CSS as a `