pub struct Style {Show 15 fields
pub color: Option<SimpleColor>,
pub bgcolor: Option<SimpleColor>,
pub bold: Option<bool>,
pub dim: Option<bool>,
pub italic: Option<bool>,
pub underline: Option<bool>,
pub blink: Option<bool>,
pub blink2: Option<bool>,
pub reverse: Option<bool>,
pub conceal: Option<bool>,
pub strike: Option<bool>,
pub underline2: Option<bool>,
pub frame: Option<bool>,
pub encircle: Option<bool>,
pub overline: Option<bool>,
}Expand description
Text style with color and attributes.
Uses Option<bool> for attributes to support three states:
None: inherit from parentSome(true): enableSome(false): disable
Fields§
§color: Option<SimpleColor>Foreground color.
bgcolor: Option<SimpleColor>Background color.
bold: Option<bool>Bold text.
dim: Option<bool>Dim/faint text.
italic: Option<bool>Italic text.
underline: Option<bool>Underlined text.
blink: Option<bool>Blinking text.
blink2: Option<bool>Rapid blinking text (SGR 6).
reverse: Option<bool>Reverse video (swap fg/bg).
conceal: Option<bool>Concealed text (SGR 8).
strike: Option<bool>Strikethrough text.
underline2: Option<bool>Double underline (SGR 21).
frame: Option<bool>Framed text (SGR 51).
encircle: Option<bool>Encircled text (SGR 52).
overline: Option<bool>Overlined text (SGR 53).
Implementations§
Source§impl Style
impl Style
Sourcepub fn with_color(self, color: Color) -> Self
pub fn with_color(self, color: Color) -> Self
Builder: set foreground color.
Sourcepub fn with_bgcolor(self, color: Color) -> Self
pub fn with_bgcolor(self, color: Color) -> Self
Builder: set background color.
Sourcepub fn with_italic(self, italic: bool) -> Self
pub fn with_italic(self, italic: bool) -> Self
Builder: set italic.
Sourcepub fn with_underline(self, underline: bool) -> Self
pub fn with_underline(self, underline: bool) -> Self
Builder: set underline.
Sourcepub fn with_reverse(self, reverse: bool) -> Self
pub fn with_reverse(self, reverse: bool) -> Self
Builder: set reverse video.
Sourcepub fn with_strike(self, strike: bool) -> Self
pub fn with_strike(self, strike: bool) -> Self
Builder: set strike.
Sourcepub fn with_blink2(self, blink2: bool) -> Self
pub fn with_blink2(self, blink2: bool) -> Self
Builder: set blink2 (rapid blink).
Sourcepub fn with_conceal(self, conceal: bool) -> Self
pub fn with_conceal(self, conceal: bool) -> Self
Builder: set conceal.
Sourcepub fn with_underline2(self, underline2: bool) -> Self
pub fn with_underline2(self, underline2: bool) -> Self
Builder: set underline2 (double underline).
Sourcepub fn with_frame(self, frame: bool) -> Self
pub fn with_frame(self, frame: bool) -> Self
Builder: set frame.
Sourcepub fn with_encircle(self, encircle: bool) -> Self
pub fn with_encircle(self, encircle: bool) -> Self
Builder: set encircle.
Sourcepub fn with_overline(self, overline: bool) -> Self
pub fn with_overline(self, overline: bool) -> Self
Builder: set overline.
Sourcepub fn combine(&self, other: &Style) -> Self
pub fn combine(&self, other: &Style) -> Self
Combine this style with another, with other taking precedence.
Values from other override values from self only if they are Some.
Sourcepub fn parse(s: &str) -> Option<Self>
pub fn parse(s: &str) -> Option<Self>
Parse a style from a string.
Supports space-separated style definitions like:
- “bold red on blue”
- “italic #ff0000”
- “bold underline”
- “not bold” (negation)
Sourcepub fn render(&self, text: &str, color_system: ColorSystem) -> String
pub fn render(&self, text: &str, color_system: ColorSystem) -> String
Render text with this style using ANSI escape codes.
§Arguments
text- The text to style.color_system- The color system to render to.
§Returns
A string containing the text wrapped in ANSI escape codes. If text is empty, returns empty string.
§Examples
use rich_rs::{Style, ColorSystem, SimpleColor};
let style = Style::new().with_bold(true).with_color(SimpleColor::Standard(1));
let rendered = style.render("Hello", ColorSystem::TrueColor);
assert!(rendered.contains("\x1b["));
assert!(rendered.contains("Hello"));
assert!(rendered.ends_with("\x1b[0m"));Sourcepub fn render_open(&self, text: &str, color_system: ColorSystem) -> String
pub fn render_open(&self, text: &str, color_system: ColorSystem) -> String
Render styled text WITHOUT a trailing reset.
This is used for streaming output where we want to minimize SGR resets to avoid visual artifacts (like black hairlines between colored lines). The caller is responsible for emitting a reset at the end.
Sourcepub fn get_html_style(&self) -> String
pub fn get_html_style(&self) -> String
Get a CSS style string for this style.
§Returns
A semicolon-separated CSS string suitable for use in a style attribute.
§Examples
use rich_rs::{Style, SimpleColor};
let style = Style::new()
.with_bold(true)
.with_color(SimpleColor::Rgb { r: 255, g: 0, b: 0 });
let css = style.get_html_style();
assert!(css.contains("font-weight: bold"));
assert!(css.contains("color:"));Sourcepub fn chain(styles: &[Style]) -> Self
pub fn chain(styles: &[Style]) -> Self
Chain multiple styles together. Like combine but applied left-to-right.
This is equivalent to Python Rich’s Style.chain(*styles).
Sourcepub fn from_color(color: Option<Color>, bgcolor: Option<Color>) -> Self
pub fn from_color(color: Option<Color>, bgcolor: Option<Color>) -> Self
Create a style with only foreground/background colors.
This is equivalent to Python Rich’s Style.from_color.
Sourcepub fn on<I, K>(
meta: Option<BTreeMap<String, MetaValue>>,
handlers: I,
) -> StyleMeta
pub fn on<I, K>( meta: Option<BTreeMap<String, MetaValue>>, handlers: I, ) -> StyleMeta
Create blank style metadata with optional event handlers.
In Python Rich, Style.on(...) returns a Style with metadata attached.
In this crate, metadata is represented separately as StyleMeta.
Sourcepub fn normalize(style: &str) -> String
pub fn normalize(style: &str) -> String
Normalize a style definition to a canonical representation.
This is equivalent to Python Rich’s Style.normalize.
Returns lowercased/trimmed input for syntactically invalid definitions.
Sourcepub fn pick_first(values: &[Option<Style>]) -> Style
pub fn pick_first(values: &[Option<Style>]) -> Style
Return the first non-None style from a sequence.
Panics if all styles are None, matching Python Rich’s ValueError behavior.
Sourcepub fn test(&self, text: &str, color_system: ColorSystem) -> String
pub fn test(&self, text: &str, color_system: ColorSystem) -> String
Apply the style to text and return the ANSI string.
This is equivalent to Python Rich’s Style.test().
Sourcepub fn background_style(&self) -> Self
pub fn background_style(&self) -> Self
Return a new Style with only the background color.
This is equivalent to Python Rich’s Style.background_style.
Sourcepub fn without_color(&self) -> Self
pub fn without_color(&self) -> Self
Return a new Style with colors stripped but attributes preserved.
This is equivalent to Python Rich’s Style.without_color.
Sourcepub fn has_transparent_background(&self) -> bool
pub fn has_transparent_background(&self) -> bool
Check if the style has a transparent (unset or default) background.
This is equivalent to Python Rich’s Style.transparent_background.
Sourcepub fn to_markup_string(&self) -> String
pub fn to_markup_string(&self) -> String
Convert this style to its markup-compatible string representation.
Returns a string like "bold red on blue" that can be used in Rich markup tags.
This is the canonical way to serialize a Style for markup — all consumers
(Text::to_markup, Theme serialization, etc.) should use this method.
Trait Implementations§
impl Copy for Style
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 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.