pub struct Theme { /* private fields */ }Expand description
A named collection of styles. Mirrors rich.theme.Theme.
Implementations§
Source§impl Theme
impl Theme
pub fn new() -> Self
Sourcepub fn insert(&mut self, name: impl Into<String>, style: Style)
pub fn insert(&mut self, name: impl Into<String>, style: Style)
Insert or replace a named style.
Sourcepub fn get_style(&self, style: &StyleType) -> Result<Style>
pub fn get_style(&self, style: &StyleType) -> Result<Style>
Resolve a StyleType against this theme. Port of Console.get_style.
An already-resolved style passes straight through. A name is looked up in
the theme first, and only then parsed as a style definition — the
order matters, because the default theme itself defines bare words like
none, bold and red, and a custom theme has to be able to shadow
them.
The lookup is case-sensitive while the parse fallback is not, which
reproduces an asymmetry upstream really has: "BOLD" misses the theme but
still parses to bold, whereas a theme key "Danger" is never found by a
span naming "danger".
Sourcepub fn get_style_or_null(&self, style: &StyleType) -> Style
pub fn get_style_or_null(&self, style: &StyleType) -> Style
As get_style, but an unresolvable name yields the
null style instead of an error. Port of upstream’s
get_style(..., default=Style.null()), which is what the render path
uses — an unknown name must not blow up a print.
Sourcepub fn default_theme() -> Self
pub fn default_theme() -> Self
The complete upstream default theme — every entry of DEFAULT_STYLES.
The shared default theme, for callers that only need to resolve a name
(e.g. the built-in highlighters) and have no Console to hand.