struct

Phosphor::Style

Inherits Struct < Value < Object

Visual style for a terminal cell: foreground/background colors and text attributes.

Style is an immutable value type. Every attribute method returns a new Style with that attribute applied — chain them freely: Style.new.fg(my_color).bold.italic.

Read boolean attributes back via ? predicates (bold?, italic?, etc.). Style.default is the zero value — no attributes set, renders as the terminal default.

ANSI escape generation is deferred to Phase 15 (buf.set_string will call it there).

Constructors

default

The zero style — no attributes set, renders as the terminal default.

Source

Instance methods

bg(color : Color | AdaptiveColor) : Style

Returns a copy with the background color set to color. Accepts an AdaptiveColor as well as a plain Color — either way, the value is stored unresolved; Buffer#set_string resolves it at render time.

Source
bold

Returns a copy with bold weight applied.

Source
bold?

Returns whether bold weight is applied.

Source
dim

Returns a copy with dim (faint) intensity applied.

Source
dim?

Returns whether dim (faint) intensity is applied.

Source
downsample(profile : ColorProfile) : Style

Downsamples fg/bg to what profile actually supports, using Euclidean distance in RGB space to find the nearest representable color. Call after #resolvefg/bg must already be concrete Color values (never AdaptiveColor) by this point; see Buffer#set_string for the full pipeline.

ColorProfile::NoColor strips every attribute, not just fg/bg — that profile has no ANSI output at all, so nothing else matters either.

Source
fg(color : Color | AdaptiveColor) : Style

Returns a copy with the foreground color set to color. Accepts an AdaptiveColor as well as a plain Color — either way, the value is stored unresolved; Buffer#set_string resolves it at render time.

Source
italic

Returns a copy with italic applied.

Source
italic?

Returns whether italic is applied.

Source
merge(other : Style) : Style

Merges two styles. other wins on any attribute it explicitly sets; unset attributes in other fall back to self. For Bool attributes "set" means true; for Color attributes "set" means non-nil.

Source
resolve(dark_background : Bool) : Style

Returns a copy with any AdaptiveColor in fg/bg resolved to a concrete Color, using dark_background to pick the right half of the pair. A plain Color (or nil) passes through unchanged.

Called once, by Buffer#set_string, at the moment a Style is actually written into a CellStyle itself stays environment-independent until then.

Source
reverse

Returns a copy with foreground and background colors inverted.

Source
reverse?

Returns whether foreground/background colors are inverted.

Source
sgr_codes

Returns the SGR (Select Graphic Rendition) parameter codes for this style, ready to join with ; and wrap in \e[...m — e.g. ["1", "38;5;208"] for bold with an indexed foreground color. Empty if nothing is set, meaning the terminal's own defaults apply.

fg/bg must already be resolved and downsampled to a concrete Color (or nil) by this point — see Buffer#set_string, which calls #resolve then #downsample before a Style ever reaches a Cell. Color::Default and nil both mean "no explicit color" and emit nothing.

Source
strikethrough

Returns a copy with strikethrough applied. Natural for completed todo items.

Source
strikethrough?

Returns whether strikethrough is applied.

Source
underline

Returns a copy with underline applied.

Source
underline?

Returns whether underline is applied.

Source