T1: four more themes, theme picker, theme file import, editor font settings

Plum Night, River, Paper and Reed (designed by Amy, approved by Daniel)
join the brand pair. theme.list/current/select/import, a picker with
live preview (view.selectTheme) and "Import Theme…" (view.importTheme);
imported themes are validated and stored in <data_dir>/themes. Editor
font family and line height settings apply live. Docs: docs/themes.md.

Gate: fmt, clippy and the rest pass up to cargo test, where only the
unrelated lutra-terminal PTY test a_full_buffer_stops_the_shell timed
out under load; to be re-run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-11-02 19:47:58 +01:00
parent 872b5cb258
commit 086bc8a925
26 changed files with 2881 additions and 100 deletions

View file

@ -110,16 +110,22 @@ fn run(args: &args::Args) -> Result<(), String> {
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 current = current_theme(setup_host);
let css = match &current {
Some(resolved) if setting != theme::SYSTEM => theme::css_of(resolved),
_ => theme::css_for_setting(&setting),
};
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)
.focused(focus_on_start)
.initialization_script(theme::init_script(&setting));
.initialization_script(theme::init_script_for_css(&css));
if let Some(dir) = &webview_dir {
window = window.data_directory(dir.clone());
}
if let Some(color) = token_color(&theme::resolve(&setting, None), "bg") {
let first = current.unwrap_or_else(|| theme::resolve(&setting, None).resolved());
if let Some(color) = token_color(&first, "bg") {
window = window.background_color(color);
}
let window = window.build()?;
@ -281,6 +287,23 @@ fn stored_theme(host: &Host) -> String {
.unwrap_or_else(|| theme::SYSTEM.to_string())
}
/// The theme the engine resolves now (`theme.current`), imported themes
/// included; `None` if the answer cannot be read.
fn current_theme(host: &Host) -> Option<theme::ResolvedTheme> {
let value = host.run("theme.current", Value::Null).ok()?;
let tokens = value
.get("tokens")?
.as_object()?
.iter()
.filter_map(|(k, v)| Some((k.clone(), v.as_str()?.to_string())))
.collect();
Some(theme::ResolvedTheme {
id: value.get("id")?.as_str()?.to_string(),
dark: value.get("dark")?.as_bool()?,
tokens,
})
}
/// 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
@ -290,15 +313,15 @@ fn follow_system_background(window: &tauri::WebviewWindow) {
return;
};
let resolved = theme::resolve(theme::SYSTEM, Some(os == tauri::Theme::Dark));
if let Some(color) = token_color(&resolved, "bg") {
if let Some(color) = token_color(&resolved.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<Color> {
let (_, value) = theme.tokens.iter().find(|(n, _)| *n == name)?;
fn token_color(theme: &theme::ResolvedTheme, name: &str) -> Option<Color> {
let value = theme.tokens.get(&format!("--lt-{name}"))?;
let hex = value.strip_prefix('#')?;
let byte = |at: usize| u8::from_str_radix(hex.get(at..at + 2)?, 16).ok();
Some(Color(byte(0)?, byte(2)?, byte(4)?, 255))
@ -378,10 +401,14 @@ mod tests {
#[test]
fn reads_theme_colours() {
assert_eq!(
token_color(&theme::DARK, "bg"),
token_color(&theme::DARK.resolved(), "bg"),
Some(Color(0x1e, 0x1b, 0x1e, 255))
);
assert_eq!(token_color(&theme::DARK, "missing"), None);
assert_eq!(
token_color(&theme::RIVER.resolved(), "bg"),
Some(Color(0x1a, 0x21, 0x25, 255))
);
assert_eq!(token_color(&theme::DARK.resolved(), "missing"), None);
}
#[test]