struct Termisu::RenderState

Overview

Tracks the current terminal rendering state for optimization.

Used to avoid emitting redundant escape sequences by tracking what colors, attributes, and cursor position 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)

Defined in:

termisu/render_state.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new #

[View source]

Instance Method Detail

def advance_cursor #

Advances cursor X position without emitting escape sequence. Used when writing characters (cursor moves automatically).


[View source]
def apply_style(renderer : Renderer, fg : Color, bg : Color, attr : Attribute) : Bool #

Applies style to renderer, only emitting changes.

Returns true if any escape sequences were emitted.


[View source]
def attr : Attribute #

Current text attributes


[View source]
def attr=(attr : Attribute) #

Current text attributes


[View source]
def bg : Color | Nil #

Current background color (nil = unknown/reset)


[View source]
def bg=(bg : Color | Nil) #

Current background color (nil = unknown/reset)


[View source]
def cursor_at?(x : Int32, y : Int32) : Bool #

Checks if cursor is at the expected position for a horizontal write.


[View source]
def cursor_x : Int32 | Nil #

Current cursor X position (nil = unknown)


[View source]
def cursor_x=(cursor_x : Int32 | Nil) #

Current cursor X position (nil = unknown)


[View source]
def cursor_y : Int32 | Nil #

Current cursor Y position (nil = unknown)


[View source]
def cursor_y=(cursor_y : Int32 | Nil) #

Current cursor Y position (nil = unknown)


[View source]
def fg : Color | Nil #

Current foreground color (nil = unknown/reset)


[View source]
def fg=(fg : Color | Nil) #

Current foreground color (nil = unknown/reset)


[View source]
def move_cursor(renderer : Renderer, x : Int32, y : Int32) : Bool #

Moves cursor only if position changed.

Returns true if cursor was moved.


[View source]
def reset #

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


[View source]