pub struct Theme { /* private fields */ }Expand description
A container for style information.
Themes map style names (like “repr.number”) to Style objects.
They can optionally inherit from the default styles.
Implementations§
Source§impl Theme
impl Theme
Sourcepub fn with_styles(styles: HashMap<String, Style>, inherit: bool) -> Self
pub fn with_styles(styles: HashMap<String, Style>, inherit: bool) -> Self
Create a theme with custom styles, optionally inheriting defaults.
Sourcepub fn read<P: AsRef<Path>>(path: P, inherit: bool) -> Result<Self, ThemeError>
pub fn read<P: AsRef<Path>>(path: P, inherit: bool) -> Result<Self, ThemeError>
Read a theme from an INI-like config file.
§Format
[styles]
repr.number = bold cyan
repr.string = greenSourcepub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self, ThemeError>
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self, ThemeError>
Read a theme from a file (convenience wrapper for read).
Sourcepub fn from_reader<R: BufRead>(
reader: R,
inherit: bool,
) -> Result<Self, ThemeError>
pub fn from_reader<R: BufRead>( reader: R, inherit: bool, ) -> Result<Self, ThemeError>
Parse a theme from a reader.
Sourcepub fn remove_style(&mut self, name: &str) -> Option<Style>
pub fn remove_style(&mut self, name: &str) -> Option<Style>
Remove a style by name.
Sourcepub fn style_names(&self) -> impl Iterator<Item = &str>
pub fn style_names(&self) -> impl Iterator<Item = &str>
Get all style names.
Sourcepub fn from_name(name: &str) -> Option<Self>
pub fn from_name(name: &str) -> Option<Self>
Load a theme by name.
Available themes:
"default"- The default rich-rs theme"dracula"- Dark theme with purple accents"gruvbox-dark"- Retro groove dark theme"nord"- Arctic, north-bluish color palette
§Example
use rich_rs::Theme;
let theme = Theme::from_name("dracula").unwrap();
assert!(theme.get_style("repr.number").is_some());Sourcepub fn available_themes() -> Vec<&'static str>
pub fn available_themes() -> Vec<&'static str>
List available theme names.
§Example
use rich_rs::Theme;
let themes = Theme::available_themes();
assert!(themes.contains(&"dracula"));Trait Implementations§
Auto Trait Implementations§
impl Freeze for Theme
impl RefUnwindSafe for Theme
impl Send for Theme
impl Sync for Theme
impl Unpin for Theme
impl UnsafeUnpin for Theme
impl UnwindSafe for Theme
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more