pub struct ThemeFile {
pub theme: Theme,
pub widgets: Option<WidgetTheme>,
}serde only.Expand description
A parsed theme document: a base Theme plus optional WidgetTheme slots.
Use ThemeFile::from_toml_str / ThemeFile::load to construct one, then
feed theme into crate::Context::set_theme and widgets into
crate::RunConfig::widget_theme.
§Example
use slt::ThemeFile;
let tf = ThemeFile::from_toml_str(r##"
[theme]
primary = "#ff0000"
[widgets.button]
fg = "#ffffff"
"##).unwrap();
assert_eq!(tf.theme.primary, slt::Color::Rgb(255, 0, 0));
assert!(tf.widgets.is_some());Fields§
§theme: ThemeThe base theme (the [theme] table). Missing fields fall back to
Theme::dark().
widgets: Option<WidgetTheme>Optional per-widget color overrides (the [widgets] table).
Implementations§
Source§impl ThemeFile
impl ThemeFile
Sourcepub fn from_toml_str(src: &str) -> Result<ThemeFile, ThemeLoadError>
pub fn from_toml_str(src: &str) -> Result<ThemeFile, ThemeLoadError>
Parse a ThemeFile from a TOML string.
§Errors
Returns ThemeLoadError::Parse for malformed TOML or a shape that
does not match the expected [theme] / [widgets] layout.
§Example
use slt::ThemeFile;
let tf = ThemeFile::from_toml_str("[theme]\nprimary = \"#00ff00\"\n").unwrap();
assert_eq!(tf.theme.primary, slt::Color::Rgb(0, 255, 0));Sourcepub fn to_toml_string(&self) -> Result<String, ThemeLoadError>
pub fn to_toml_string(&self) -> Result<String, ThemeLoadError>
Serialize this ThemeFile back to a TOML string.
The output round-trips through ThemeFile::from_toml_str. Colors are
emitted as human-friendly tokens (#rrggbb, named, or indexed:N).
§Errors
Returns ThemeLoadError::Parse if serialization fails (e.g. a value
that TOML cannot represent).
§Example
use slt::{Theme, ThemeFile};
let tf = ThemeFile { theme: Theme::dracula(), widgets: None };
let toml = tf.to_toml_string().unwrap();
assert!(toml.contains("[theme]"));Sourcepub fn load(path: impl AsRef<Path>) -> Result<ThemeFile, ThemeLoadError>
pub fn load(path: impl AsRef<Path>) -> Result<ThemeFile, ThemeLoadError>
Read and parse a ThemeFile from a TOML file at path.
§Errors
Returns ThemeLoadError::Io if the file cannot be read, or
ThemeLoadError::Parse if its contents are not valid TOML.
§Example
use slt::ThemeFile;
let tf = ThemeFile::load("theme.toml").unwrap();
println!("primary = {:?}", tf.theme.primary);