struct

Termisu::RenderState

Inherits Struct / Value / Object

Tracks the current terminal rendering state for optimization.

Used to avoid emitting redundant escape sequences by tracking what colors and attributes are currently set. Only emits escape sequences when the state actually changes.

Example:

state = Termisu::RenderState.new

# First cell - emits all sequences
state.apply_style(renderer, fg: Color.green, bg: Color.black, attr: Attribute::Bold)

# Second cell with same style - no sequences emitted
state.apply_style(renderer, fg: Color.green, bg: Color.black, attr: Attribute::Bold)

# Third cell with different color - only color change emitted
state.apply_style(renderer, fg: Color.red, bg: Color.black, attr: Attribute::Bold)

Constructors

Instance methods

apply_style(renderer : Renderer, fg : Color, bg : Color, attr : Attribute) : Bool

Applies style to renderer, only emitting changes.

The full transition is delegated to Renderer#apply_sgr in one call so renderers can coalesce it into a single escape sequence; the default apply_sgr decomposes into the granular color/attribute methods with the same emission semantics as before.

Returns true if the style changed (i.e. the renderer was invoked).

Source
attr

Current text attributes

Source
attr=(attr : Attribute)

Current text attributes

Source
bg

Current background color (nil = unknown/reset)

Source
bg=(bg : Color | Nil)

Current background color (nil = unknown/reset)

Source
fg

Current foreground color (nil = unknown/reset)

Source
fg=(fg : Color | Nil)

Current foreground color (nil = unknown/reset)

Source
reset

Resets state to unknown (forces next render to emit all sequences).

Source