etui/style

Types

Terminal color. Default defers to the terminal theme. Indexed(n) covers the whole 256-color space: 0 to 15 are the themeable ANSI colors, 16 to 255 the extended palette (the 6x6x6 cube and the grayscale ramp). Rgb(r, g, b) uses 24-bit true color and needs a truecolor terminal.

pub type Color {
  Default
  Indexed(Int)
  Rgb(Int, Int, Int)
}

Constructors

  • Default
  • Indexed(Int)
  • Rgb(Int, Int, Int)

Opaque bitfield for text modifiers. Use constants + add/remove/has.

pub opaque type Modifier

Combined foreground color, background color, and text modifiers.

pub type Style {
  Style(fg: Color, bg: Color, modifier: Modifier)
}

Constructors

Values

pub fn add(a: Modifier, b: Modifier) -> Modifier

Combine two modifiers (bitwise OR).

pub fn add_modifier(s: Style, m: Modifier) -> Style

Add a modifier to a Style (bitwise OR).

pub fn ansi_bg(color: Color) -> String

Background color escape sequence.

pub fn ansi_fg(color: Color) -> String

Foreground color escape sequence.

pub fn ansi_modifier(m: Modifier) -> String

Text modifier escape sequence. Emits all active modifier bits.

pub fn ansi_reset() -> String

Reset all styles.

pub fn blink() -> Modifier

Blinking text (terminal support varies).

pub fn bold() -> Modifier

Bold / increased intensity.

pub fn bold_style() -> Style

Default colors with bold modifier.

pub fn color_from_hex(hex: String) -> Result(Color, Nil)

Parse an RGB color from a hex string ("#RRGGBB" or "RRGGBB"). Returns Error(Nil) for malformed input.

style.color_from_hex("#1e1e2e")  // Ok(Rgb(30, 30, 46))
style.color_from_hex("ff5555")   // Ok(Rgb(255, 85, 85))
pub fn default_style() -> Style

Default style: terminal colors, no modifiers.

pub fn dim() -> Modifier

Dim / decreased intensity.

pub fn dim_style() -> Style

Default colors with dim modifier.

pub fn has(m: Modifier, flag: Modifier) -> Bool

Check if flag bits are set in m.

pub fn is_none(m: Modifier) -> Bool

True when no modifier bits are set.

pub fn italic() -> Modifier

Italic text.

pub fn italic_style() -> Style

Default colors with italic modifier.

pub fn modifier_equal(a: Modifier, b: Modifier) -> Bool

Structural equality for modifiers.

pub fn none() -> Modifier

No modifiers active.

pub fn patch(base: Style, over: Style) -> Style

Apply over on top of base. Default fg/bg fall back to base. Modifier: if over has any bits set, they are OR’d into base; none() in over means “no modifier override” (keep base).

pub fn remove(a: Modifier, b: Modifier) -> Modifier

Remove modifier bits from a that are set in b.

pub fn remove_modifier(s: Style, m: Modifier) -> Style

Remove modifier bits from a Style.

pub fn reverse() -> Modifier

Swap foreground and background colors.

pub fn reversed() -> Style

Default colors with reverse modifier (swap fg/bg).

pub fn strikethrough() -> Modifier

Strikethrough.

pub fn underline() -> Modifier

Underline.

pub fn underline_style() -> Style

Default colors with underline modifier.

pub fn with_bg(s: Style, bg: Color) -> Style

Set background color on a style.

pub fn with_fg(s: Style, fg: Color) -> Style

Set foreground color on a style.

pub fn with_modifier(s: Style, m: Modifier) -> Style

Set modifier on a style.

Search Document