pub struct Theme { /* private fields */ }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:
| Role | Style |
|---|---|
Role::Plain | none |
Role::Heading | bold cyan |
Role::Success | bold green |
Role::Warning | bold yellow |
Role::Error | bold red |
Role::Value | bold yellow |
Role::Muted | bright black |
Role::Token | bold green |
Role::Id | bold, 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
impl Theme
Sourcepub const fn new() -> Self
pub const fn new() -> Self
ctl-core’s palette, the table in the type docs.
The same as Theme::default, usable in a const.
Sourcepub const fn role_style(self, role: Role) -> Style
pub const fn role_style(self, role: Role) -> Style
The style role is drawn in.
Sourcepub const fn style(self, role: Role, style: Style) -> Self
pub const fn style(self, role: Role, style: Style) -> Self
This theme with role drawn in style.
Sourcepub const fn label_style(self, level: NoticeLevel) -> Style
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.
Sourcepub const fn notice_style(self, level: NoticeLevel, style: Style) -> Self
pub const fn notice_style(self, level: NoticeLevel, style: Style) -> Self
This theme with the label of a level notice drawn in style.