Skip to main content

Style

Struct Style 

Source
pub struct Style { /* private fields */ }
Expand description

A terminal text style. Mirrors rich.style.Style.

Implementations§

Source§

impl Style

Source

pub fn new() -> Self

The empty (null) style — sets nothing.

Source

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.

Source

pub fn with_color(self, color: Color) -> Self

Attach an OSC 8 hyperlink target. Port of Style(link=…).

The hyperlink target, if set.

Return a copy with the hyperlink target set (Some) or cleared (None), leaving every other attribute unchanged. Port of Style.update_link.

Source

pub fn with_bgcolor(self, color: Color) -> Self

Source

pub fn color(&self) -> Option<&Color>

Source

pub fn bgcolor(&self) -> Option<&Color>

Source

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, …).

Source

pub fn is_null(&self) -> bool

True when nothing at all is set (renders as a no-op).

Source

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

Source

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.

Source

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

Source

pub fn combine(&self, other: &Style) -> Style

Combine two styles, other winning wherever it sets a value.

Port of Style.__add__.

Source

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.

Source

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.

Source

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

Source

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§

Source§

impl Clone for Style

Source§

fn clone(&self) -> Style

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 Style

Source§

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

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

impl Default for Style

Source§

fn default() -> Style

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

impl Eq for Style

Source§

impl From<&Style> for StyleType

Source§

fn from(style: &Style) -> Self

Converts to this type from the input type.
Source§

impl From<Style> for StyleType

Source§

fn from(style: Style) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Style

Source§

fn eq(&self, other: &Style) -> 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 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> 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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 = !

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.