Skip to main content

Theme

Struct Theme 

Source
pub struct Theme { /* private fields */ }
Available on crate feature render only.
Expand description

Maps each Role, and the label of each NoticeLevel, to an anstyle::Style.

Theme::default is ctl-core’s palette. It uses only the 16 named colours and bold, so it looks the same at every colour depth:

RoleStyle
Role::Plainnone
Role::Headingbold cyan
Role::Successbold green
Role::Warningbold yellow
Role::Errorbold red
Role::Valuebold yellow
Role::Mutedbright black
Role::Tokenbold green
Role::Idbold, in the terminal’s own foreground

A notice label takes the style of the role of the same name until Theme::notice_style replaces it.

Equality compares the choices a theme holds, including which notice labels were given their own style. It does not compare the output they draw. A label set to its role’s style draws the same as an unset one, yet the two themes differ.

A theme replaces the default through RenderOptions::theme, View::theme, and App::theme. It only says how a role looks: whether colour is written is the colour mode’s decision, so ColorMode::Never writes none whatever the theme holds.

use ctl_core::Theme;
use ctl_core::document::Role;
use ctl_core::text::anstyle::{AnsiColor, Style};

let magenta = Style::new().fg_color(Some(AnsiColor::Magenta.into()));
let theme = Theme::default().style(Role::Id, magenta);
assert_eq!(theme.role_style(Role::Id), magenta);
assert_eq!(
    theme.role_style(Role::Heading),
    Theme::default().role_style(Role::Heading)
);

Implementations§

Source§

impl Theme

Source

pub const fn new() -> Self

ctl-core’s palette, the table in the type docs.

The same as Theme::default, usable in a const.

Source

pub const fn role_style(self, role: Role) -> Style

The style role is drawn in.

Source

pub const fn style(self, role: Role, style: Style) -> Self

This theme with role drawn in style.

Source

pub const fn label_style(self, level: NoticeLevel) -> Style

The style the label of a level notice (success, warning, or error) is drawn in: the style Theme::notice_style set, or else the style of the role of the same name.

Source

pub const fn notice_style(self, level: NoticeLevel, style: Style) -> Self

This theme with the label of a level notice drawn in style.

Trait Implementations§

Source§

impl Clone for Theme

Source§

fn clone(&self) -> Self

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 Copy for Theme

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

ctl-core’s palette; see Theme::new.

Source§

impl Eq for Theme

Source§

impl Hash for Theme

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Theme

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Theme

Auto Trait Implementations§

§

impl Forget for Theme

§

impl Freeze for Theme

§

impl Move 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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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, O> Matches<O> for T
where T: PartialEq<O>,

Source§

fn validate_matches(&self, other: &O) -> bool

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.