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:
parent
872b5cb258
commit
086bc8a925
26 changed files with 2881 additions and 100 deletions
|
|
@ -48,6 +48,19 @@ pub enum Kind {
|
|||
/// Longest accepted value in bytes.
|
||||
max_len: usize,
|
||||
},
|
||||
/// A theme id or `system`: any well-formed id
|
||||
/// ([`crate::theme::valid_id`]), so an imported theme's id survives a
|
||||
/// restart. `settings.set` also requires the theme to exist; listed as
|
||||
/// an enum of the built-in ids and `system`, which `settings.list`
|
||||
/// extends with the imported ones.
|
||||
Theme,
|
||||
/// A font family list for CSS, such as `"Fira Code", monospace`: at
|
||||
/// most `max_len` bytes without control characters or `;{}<>\`, so it
|
||||
/// cannot leave the `font-family` value. Empty means the theme's font.
|
||||
FontFamily {
|
||||
/// Longest accepted value in bytes.
|
||||
max_len: usize,
|
||||
},
|
||||
}
|
||||
|
||||
/// Checks a path setting's text: at most `max_len` bytes, no control
|
||||
|
|
@ -162,22 +175,57 @@ impl Def {
|
|||
}
|
||||
None => Err(format!("{} must be a path string, got {value}", self.key)),
|
||||
},
|
||||
Kind::Theme => match value.as_str() {
|
||||
Some(s) if crate::theme::valid_id(s) => Ok(()),
|
||||
_ => Err(format!(
|
||||
"{} must be a theme id (lowercase letters, digits and dashes) or system, got {value}",
|
||||
self.key
|
||||
)),
|
||||
},
|
||||
Kind::FontFamily { max_len } => match value.as_str() {
|
||||
Some(s)
|
||||
if s.len() <= max_len
|
||||
&& !s.chars().any(|c| c.is_control() || ";{}<>\\".contains(c)) =>
|
||||
{
|
||||
Ok(())
|
||||
}
|
||||
_ => Err(format!(
|
||||
"{} must be a font family list of at most {max_len} bytes without control characters or ; {{ }} < > \\",
|
||||
self.key
|
||||
)),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// The description for `settings.list`.
|
||||
pub fn info(&self) -> SettingInfo {
|
||||
let (kind, enum_values, min, max) = match self.kind {
|
||||
Kind::Enum(values) => ("enum", Some(values.to_vec()), None, None),
|
||||
Kind::Enum(values) => (
|
||||
"enum",
|
||||
Some(values.iter().map(|v| (*v).to_string()).collect()),
|
||||
None,
|
||||
None,
|
||||
),
|
||||
Kind::Int { min, max } => ("int", None, Some(min), Some(max)),
|
||||
Kind::Bool => ("bool", None, None, None),
|
||||
Kind::Str { .. } | Kind::Path { .. } => ("string", None, None, None),
|
||||
Kind::Str { .. } | Kind::Path { .. } | Kind::FontFamily { .. } => {
|
||||
("string", None, None, None)
|
||||
}
|
||||
Kind::Theme => {
|
||||
let mut ids: Vec<_> = crate::theme::BUILTIN
|
||||
.iter()
|
||||
.map(|t| t.id.to_string())
|
||||
.collect();
|
||||
ids.push(crate::theme::SYSTEM.to_string());
|
||||
("enum", Some(ids), None, None)
|
||||
}
|
||||
};
|
||||
SettingInfo {
|
||||
key: self.key,
|
||||
kind,
|
||||
default: self.default.to_value(),
|
||||
enum_values,
|
||||
value_names: None,
|
||||
min,
|
||||
max,
|
||||
path: matches!(self.kind, Kind::Path { .. }),
|
||||
|
|
@ -201,7 +249,11 @@ pub struct SettingInfo {
|
|||
pub default: Value,
|
||||
/// Accepted values of an enum.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub enum_values: Option<Vec<&'static str>>,
|
||||
pub enum_values: Option<Vec<String>>,
|
||||
/// Display names of enum values that have no catalog key, such as
|
||||
/// imported themes, by value.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub value_names: Option<std::collections::BTreeMap<String, String>>,
|
||||
/// Smallest value of an int.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub min: Option<i64>,
|
||||
|
|
@ -224,7 +276,7 @@ pub struct SettingInfo {
|
|||
pub const DEFS: &[Def] = &[
|
||||
Def {
|
||||
key: "appearance.theme",
|
||||
kind: Kind::Enum(&["lutra-dark", "lutra-light", "system"]),
|
||||
kind: Kind::Theme,
|
||||
default: DefaultValue::Str("system"),
|
||||
label_key: "settings.appearance.theme.label",
|
||||
description_key: "settings.appearance.theme.description",
|
||||
|
|
@ -238,6 +290,22 @@ pub const DEFS: &[Def] = &[
|
|||
description_key: "settings.editor.fontSize.description",
|
||||
section: "editor",
|
||||
},
|
||||
Def {
|
||||
key: "editor.fontFamily",
|
||||
kind: Kind::FontFamily { max_len: 256 },
|
||||
default: DefaultValue::Str(""),
|
||||
label_key: "settings.editor.fontFamily.label",
|
||||
description_key: "settings.editor.fontFamily.description",
|
||||
section: "editor",
|
||||
},
|
||||
Def {
|
||||
key: "editor.lineHeight",
|
||||
kind: Kind::Int { min: 100, max: 300 },
|
||||
default: DefaultValue::Int(150),
|
||||
label_key: "settings.editor.lineHeight.label",
|
||||
description_key: "settings.editor.lineHeight.description",
|
||||
section: "editor",
|
||||
},
|
||||
Def {
|
||||
key: "ui.language",
|
||||
kind: Kind::Enum(&["en"]),
|
||||
|
|
@ -687,9 +755,31 @@ mod tests {
|
|||
));
|
||||
}
|
||||
assert!(matches!(
|
||||
s.set("appearance.theme", json!("dark")),
|
||||
s.set("appearance.theme", json!("Dark Mode")),
|
||||
Err(SetError::Invalid(_))
|
||||
));
|
||||
assert_eq!(s.set("appearance.theme", json!("my-import")), Ok(true));
|
||||
assert_eq!(s.get("editor.fontFamily"), Some(json!("")));
|
||||
assert_eq!(s.get("editor.lineHeight"), Some(json!(150)));
|
||||
assert_eq!(
|
||||
s.set("editor.fontFamily", json!("\"Fira Code\", monospace")),
|
||||
Ok(true)
|
||||
);
|
||||
for bad in ["a; color: red", "x{", "</style>", "a\\b", "tab\there"] {
|
||||
assert!(
|
||||
matches!(
|
||||
s.set("editor.fontFamily", json!(bad)),
|
||||
Err(SetError::Invalid(_))
|
||||
),
|
||||
"{bad}"
|
||||
);
|
||||
}
|
||||
for bad in [json!(99), json!(301), json!(1.5)] {
|
||||
assert!(matches!(
|
||||
s.set("editor.lineHeight", bad),
|
||||
Err(SetError::Invalid(_))
|
||||
));
|
||||
}
|
||||
assert!(matches!(s.set("x.y", json!(1)), Err(SetError::Invalid(_))));
|
||||
assert_eq!(s.get("editor.fontSize"), Some(json!(16)));
|
||||
assert_eq!(s.reset("editor.fontSize"), Ok(true));
|
||||
|
|
@ -812,7 +902,7 @@ mod tests {
|
|||
"key": "appearance.theme",
|
||||
"type": "enum",
|
||||
"default": "system",
|
||||
"enumValues": ["lutra-dark", "lutra-light", "system"],
|
||||
"enumValues": ["lutra-dark", "lutra-light", "lutra-plum-night", "lutra-river", "lutra-paper", "lutra-reed", "system"],
|
||||
"labelKey": "settings.appearance.theme.label",
|
||||
"descriptionKey": "settings.appearance.theme.description",
|
||||
"section": "appearance",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue