pub struct Style { /* private fields */ }Expand description
A terminal text style. Mirrors rich.style.Style.
Implementations§
Source§impl Style
impl Style
Sourcepub fn from_color(color: Option<Color>, bgcolor: Option<Color>) -> Self
pub fn from_color(color: Option<Color>, bgcolor: Option<Color>) -> Self
A style carrying only a foreground and/or background color.
Port of Style.from_color.
pub fn with_color(self, color: Color) -> Self
Sourcepub fn with_link(self, url: impl Into<String>) -> Self
pub fn with_link(self, url: impl Into<String>) -> Self
Attach an OSC 8 hyperlink target. Port of Style(link=…).
Sourcepub fn update_link(&self, link: Option<String>) -> Style
pub fn update_link(&self, link: Option<String>) -> Style
Return a copy with the hyperlink target set (Some) or cleared (None),
leaving every other attribute unchanged. Port of Style.update_link.
pub fn with_bgcolor(self, color: Color) -> Self
pub fn color(&self) -> Option<&Color>
pub fn bgcolor(&self) -> Option<&Color>
Sourcepub fn without_color(&self) -> Style
pub fn without_color(&self) -> Style
A copy with the foreground and background colours removed; attributes
and link survive. Port of Style.without_color.
Sourcepub fn attr(&self, index: usize) -> Option<bool>
pub fn attr(&self, index: usize) -> Option<bool>
The tri-state value of attribute index (see the internal attrs order:
0=bold, 1=dim, 2=italic, 3=underline, 6=reverse, 8=strike, …).
Sourcepub fn is_null(&self) -> bool
pub fn is_null(&self) -> bool
True when nothing at all is set (renders as a no-op). Non-empty
metadata counts, as upstream’s _null includes meta.
Sourcepub fn with_meta(self, meta: Meta) -> Self
pub fn with_meta(self, meta: Meta) -> Self
Attach metadata. Port of Style(meta=…). An empty map leaves the style
null, but it still differs from one with no metadata at all (upstream
hashes the marshal-encoded {}).
Sourcepub fn meta(&self) -> Meta
pub fn meta(&self) -> Meta
The metadata, empty when none is set. Port of the Style.meta
property.
Sourcepub fn meta_ref(&self) -> Option<&Meta>
pub fn meta_ref(&self) -> Option<&Meta>
The metadata as stored: None when the style carries none.
Sourcepub fn from_meta(meta: Meta) -> Style
pub fn from_meta(meta: Meta) -> Style
A style carrying only meta. Port of Style.from_meta (null when
meta is empty). Upstream also gives it a random link_id, which
this port does not model (see DIVERGENCES #20).
Sourcepub fn on(meta: Option<Meta>, handlers: &[(&str, MetaValue)]) -> Style
pub fn on(meta: Option<Meta>, handlers: &[(&str, MetaValue)]) -> Style
A style with event-handler metadata. Port of Style.on: each handler
is stored as "@name" over meta (default empty).
Sourcepub fn clear_meta_and_links(&self) -> Style
pub fn clear_meta_and_links(&self) -> Style
A copy without metadata or link. Port of Style.clear_meta_and_links.
Sourcepub fn definition(&self) -> String
pub fn definition(&self) -> String
Regenerate the style definition string. Port of Style.__str__.
Attributes come first in their canonical order, then the foreground
colour, then on <bgcolour>, then link <url>. A style that sets nothing
is "none" — never the empty string, which upstream reserves for “no
style at all”.
Sourcepub fn normalize(definition: &str) -> String
pub fn normalize(definition: &str) -> String
Canonicalise a style definition so that definitions with the same effect
have the same string. Port of Style.normalize.
A definition that parses round-trips through definition,
so "b" and "BOLD" both become "bold". One that does not parse is
merely trimmed and lowercased — that is the path a theme name like
"repr.number" takes, and it is why theme lookups are effectively
case-insensitive on the markup side while Theme::get_style itself is
case-sensitive.
Sourcepub fn parse(definition: &str) -> Result<Self>
pub fn parse(definition: &str) -> Result<Self>
Parse a style definition such as "bold red on blue".
Port of Style.parse covering attributes, not <attr>, link <url>, and
<color> on <color>. (meta is deferred — see DIVERGENCES.)
Sourcepub fn combine(&self, other: &Style) -> Style
pub fn combine(&self, other: &Style) -> Style
Combine two styles, other winning wherever it sets a value.
Port of Style.__add__.
Sourcepub fn ansi_codes(&self, system: ColorSystem) -> String
pub fn ansi_codes(&self, system: ColorSystem) -> String
The SGR parameter list (e.g. "1;31;44") for a given color system.
Port of Style._make_ansi_codes.
Sourcepub fn get_html_style(&self, theme: &TerminalTheme) -> String
pub fn get_html_style(&self, theme: &TerminalTheme) -> String
The CSS declarations for this style under theme (for HTML export).
Port of Style.get_html_style.
Sourcepub fn get_svg_style(&self, theme: &TerminalTheme) -> String
pub fn get_svg_style(&self, theme: &TerminalTheme) -> String
The SVG <text> CSS declarations for this style under theme. Port of
the get_svg_style closure in Console.export_svg. Unlike
get_html_style, the colour is always resolved to
a concrete triplet (the theme fore/background stands in for a missing or
default colour), dim blends 40% toward the background (not 50%), and the
rules are joined with a bare ;.
Sourcepub fn render(&self, text: &str, system: Option<ColorSystem>) -> String
pub fn render(&self, text: &str, system: Option<ColorSystem>) -> String
Wrap text in this style’s escape sequence for system.
With system == None (no color) or a null style, text is returned
unchanged. A link additionally wraps the result in an
OSC 8 hyperlink. Port of Style.render.
Divergence: upstream tags each hyperlink with a random id= field (to
group multi-segment links for hover); we omit it so output is
deterministic. See docs/DIVERGENCES.md.
Trait Implementations§
impl Eq for Style
impl StructuralPartialEq for Style
Auto Trait Implementations§
impl Freeze for Style
impl RefUnwindSafe for Style
impl Send for Style
impl Sync for Style
impl Unpin for Style
impl UnsafeUnpin for Style
impl UnwindSafe for Style
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.