//! theme: switch the active color theme and persist it for the next start. //! //! With no argument, prints the current theme and the available list. //! With a name, switches to that theme (also used by the REPL 'theme' command). use super::*; use crate::theme; pub fn run(app: &App, name: Option<&str>) -> Result { if let Some(name) = name { let theme = theme::find(name).ok_or_else(|| { anyhow::anyhow!( "unknown theme '{name}' — available: {}", theme::names().join(", ") ) })?; app.set_theme(theme); crate::commands::config_cmd::persist_setting(app, "settings.theme", theme.name)?; app.log.success(&format!( "theme set to {} ({})", theme.name, theme.title )); return Ok(0); } // No argument: show current and list. let current = app.theme(); if app.json() { crate::output::print_json(&serde_json::json!({ "current": current.name, "title": current.title, "available": theme::names(), })); } else { println!("current theme: {} — {}", current.name, current.title); println!("available themes: {}", theme::names().join(", ")); println!("use 'am theme ' to switch"); } Ok(0) }