Skip to main content

Theme

Struct Theme 

Source
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

Source

pub fn new() -> Self

Create an empty theme that inherits default styles.

Source

pub fn empty() -> Self

Create an empty theme without default styles.

Source

pub fn with_styles(styles: HashMap<String, Style>, inherit: bool) -> Self

Create a theme with custom styles, optionally inheriting defaults.

Source

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 = green
Source

pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self, ThemeError>

Read a theme from a file (convenience wrapper for read).

Source

pub fn from_reader<R: BufRead>( reader: R, inherit: bool, ) -> Result<Self, ThemeError>

Parse a theme from a reader.

Source

pub fn get_style(&self, name: &str) -> Option<Style>

Get a style by name.

Source

pub fn add_style(&mut self, name: impl Into<String>, style: Style)

Add or update a style.

Source

pub fn remove_style(&mut self, name: &str) -> Option<Style>

Remove a style by name.

Source

pub fn has_style(&self, name: &str) -> bool

Check if a style exists.

Source

pub fn style_names(&self) -> impl Iterator<Item = &str>

Get all style names.

Source

pub fn len(&self) -> usize

Get the number of styles.

Source

pub fn is_empty(&self) -> bool

Check if the theme is empty.

Source

pub fn inherits(&self) -> bool

Whether this theme inherits default styles.

Source

pub fn to_config(&self) -> String

Generate INI config file contents for this theme.

Source

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());
Source

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§

Source§

impl Clone for Theme

Source§

fn clone(&self) -> Theme

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Theme

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Theme

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.