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 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 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.