abstract class Termisu::Renderer

Overview

Abstract renderer interface for terminal output.

Separates rendering logic from I/O operations, enabling different renderer implementations (terminal, in-memory, etc.).

This interface defines all methods that Buffer requires for rendering cells to the screen, including cursor control, colors, and attributes.

Note: Methods with _seq suffix write escape sequences immediately. This distinguishes them from buffer state management methods.

Direct Known Subclasses

Defined in:

termisu/renderer.cr

Instance Method Summary

Instance Method Detail

def apply_sgr(fg : Color, bg : Color, attr : Attribute, old_fg : Color | Nil, old_bg : Color | Nil, old_attr : Attribute) : Nil #

Applies a complete style transition (attributes + colors) in one call.

fg, bg, and attr are the target style. The old_ parameters carry the caller's view of the current terminal style (nil = unknown, which forces emission).

This default implementation decomposes the transition into the granular color/attribute methods above with the legacy emission semantics (reset-then-reapply when any attribute is removed), so existing renderer implementations need no changes. Terminal overrides this to emit a single combined SGR sequence per transition instead.

The branch count is a flat per-attribute dispatch table, not nested logic. ameba:disable Metrics/CyclomaticComplexity


[View source]
abstract def background=(color : Color) #

Sets the background color (writes escape sequence).


[View source]
abstract def close #

Closes the renderer and releases resources.


[View source]
abstract def enable_blink #

Enables blink text (writes escape sequence).


[View source]
abstract def enable_bold #

Enables bold text (writes escape sequence).


[View source]
abstract def enable_cursive #

Enables italic/cursive text (writes escape sequence).


[View source]
abstract def enable_dim #

Enables dim/faint text (writes escape sequence).


[View source]
abstract def enable_hidden #

Enables hidden/invisible text (writes escape sequence).


[View source]
abstract def enable_reverse #

Enables reverse video (writes escape sequence).


[View source]
abstract def enable_strikethrough #

Enables strikethrough text (writes escape sequence).


[View source]
abstract def enable_underline #

Enables underline text (writes escape sequence).


[View source]
abstract def flush #

Flushes any buffered output.


[View source]
abstract def foreground=(color : Color) #

Sets the foreground color (writes escape sequence).


[View source]
abstract def hide_cursor #

Writes hide cursor escape sequence.


[View source]
abstract def move_cursor(x : Int32, y : Int32) #

Moves cursor to the specified position (writes escape sequence).


[View source]
abstract def reset_attributes #

Resets all text attributes to default (writes escape sequence).


[View source]
abstract def show_cursor #

Writes show cursor escape sequence.


[View source]
abstract def size : Tuple(Int32, Int32) #

Returns the renderer dimensions as {width, height}.


[View source]
abstract def write(data : String, columns_advanced = 0) #

Writes data to the renderer.


[View source]
def write(data : Bytes, columns_advanced = 0) #

Writes raw bytes to the renderer.

Default implementation delegates to the String overload so existing renderer implementations work unchanged. Terminal overrides this to stream the bytes to the backend without materializing a String.


[View source]