Skip to main content

ComputedStyle

Struct ComputedStyle 

Source
pub struct ComputedStyle {
Show 19 fields pub dark: String, pub mid: String, pub symbol: String, pub head: String, pub grey: String, pub bright: String, pub margin_spaces: String, pub blockquote: String, pub codebg: String, pub link: String, pub codepad: (String, String), pub list_indent: String, pub dark_fg: String, pub dark_bg: String, pub mid_fg: String, pub symbol_fg: String, pub head_fg: String, pub grey_fg: String, pub bright_fg: String,
}
Expand description

Pre-computed ANSI color strings.

These values are computed from StyleConfig by applying HSV multipliers to the base color. Each string is formatted for ANSI escape sequences, e.g., “48;23;15m” for background colors or “255;128;64m” for foreground.

Fields§

§dark: String

Dark color (for backgrounds, code block bg). Format: “r;g;bm”

§mid: String

Mid color (for secondary elements). Format: “r;g;bm”

§symbol: String

Symbol color (for special characters, bullets). Format: “r;g;bm”

§head: String

Head color (for headers). Format: “r;g;bm”

§grey: String

Grey color (for muted text, blockquote bars). Format: “r;g;bm”

§bright: String

Bright color (for emphasis, links). Format: “r;g;bm”

§margin_spaces: String

Margin spaces string (e.g., “ “ for margin=2).

§blockquote: String

Block quote prefix string with ANSI styling.

§codebg: String

Code block background ANSI sequence.

§link: String

Link color ANSI sequence.

§codepad: (String, String)

Code block padding characters (left, right). Used for pretty padding around code blocks.

§list_indent: String

List indent string.

§dark_fg: String

Full ANSI foreground escape for dark.

§dark_bg: String

Full ANSI background escape for dark.

§mid_fg: String

Full ANSI foreground escape for mid.

§symbol_fg: String

Full ANSI foreground escape for symbol.

§head_fg: String

Full ANSI foreground escape for head.

§grey_fg: String

Full ANSI foreground escape for grey.

§bright_fg: String

Full ANSI foreground escape for bright.

Implementations§

Source§

impl ComputedStyle

Source

pub fn from_config(config: &StyleConfig) -> Self

Compute style values from a StyleConfig.

This applies the HSV multipliers to the base color to generate all derived colors, then formats them as ANSI escape sequences.

§Arguments
  • config - The style configuration to compute from
§Example
use streamdown_config::{StyleConfig, ComputedStyle};

let config = StyleConfig::default();
let computed = ComputedStyle::from_config(&config);

// Use the computed dark background
let bg_escape = format!("\x1b[48;2;{}", computed.dark);
Source

pub fn fg(&self, name: &str) -> &str

Get the foreground ANSI escape for a specific style.

Source

pub fn bg(&self, name: &str) -> &str

Get the background ANSI escape for a specific style.

Source

pub fn style_fg(&self, name: &str, text: &str) -> String

Format text with a specific foreground style.

Source

pub fn heading(&self, level: u8, text: &str) -> String

Create a heading line with the head color.

Source

pub fn code_start(&self, language: Option<&str>, width: usize) -> String

Create a code block start line.

Source

pub fn quote(&self, text: &str, depth: usize) -> String

Create a blockquote line.

Source

pub fn bullet(&self, indent: usize) -> String

Create a list bullet.

Source

pub fn list_number(&self, indent: usize, num: usize) -> String

Create an ordered list number.

Trait Implementations§

Source§

impl Clone for ComputedStyle

Source§

fn clone(&self) -> ComputedStyle

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ComputedStyle

Source§

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

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

impl Default for ComputedStyle

Source§

fn default() -> ComputedStyle

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

Auto Trait Implementations§

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<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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.