ElixirOpentui.Buffer (ElixirOpentui v0.2.0)

Copy Markdown View Source

Cell-based terminal buffer. Each cell stores a character, fg/bg colors, and attributes.

Maps to ElixirOpentui's OptimizedBuffer. This is the "framebuffer" — layout and painting write cells into this buffer, and the renderer diffs it against the previous frame to produce minimal ANSI output.

Summary

Functions

Clear the buffer to blank cells.

Diff two buffers, returning list of {x, y, new_cell} changes.

Write a character at (x, y) with fg/bg colors and optional text attributes.

Write a string horizontally starting at (x, y) with optional text attributes.

Fill a rectangular region with a character, colors, and optional text attributes.

Get the cell at (x, y). Returns nil if out of bounds.

Get the hit_id at coordinates (x, y).

Create a new buffer with the given dimensions.

Pop the top scissor rect, restoring the previous clip region.

Push a scissor rect. Drawing is clipped to the intersection of all active scissor rects.

Set a cell at (x, y). No-op if out of bounds or outside scissor rect.

Resize the buffer. Contents are lost.

Set hit_id for a rectangular region (for mouse event targeting).

Convert the full buffer to a list of row strings (for testing/display).

Types

cell()

@type cell() :: %{
  char: String.t(),
  fg: ElixirOpentui.Color.t(),
  bg: ElixirOpentui.Color.t(),
  bold: boolean(),
  italic: boolean(),
  underline: boolean(),
  strikethrough: boolean(),
  dim: boolean(),
  inverse: boolean(),
  blink: boolean(),
  hidden: boolean(),
  hit_id: term()
}

t()

@type t() :: %ElixirOpentui.Buffer{
  cells: :array.array(cell()),
  cols: non_neg_integer(),
  default_bg: ElixirOpentui.Color.t(),
  default_fg: ElixirOpentui.Color.t(),
  rows: non_neg_integer(),
  scissor_stack: [{integer(), integer(), non_neg_integer(), non_neg_integer()}]
}

Functions

clear(buf)

@spec clear(t()) :: t()

Clear the buffer to blank cells.

diff(arg1, arg2)

@spec diff(t(), t()) :: [{non_neg_integer(), non_neg_integer(), cell()}]

Diff two buffers, returning list of {x, y, new_cell} changes.

draw_char(buf, x, y, char, fg, bg, attrs \\ [])

@spec draw_char(
  t(),
  integer(),
  integer(),
  String.t(),
  ElixirOpentui.Color.t(),
  ElixirOpentui.Color.t(),
  keyword()
) :: t()

Write a character at (x, y) with fg/bg colors and optional text attributes.

draw_text(buf, x, y, text, fg, bg, attrs \\ [])

@spec draw_text(
  t(),
  integer(),
  integer(),
  String.t(),
  ElixirOpentui.Color.t(),
  ElixirOpentui.Color.t(),
  keyword()
) :: t()

Write a string horizontally starting at (x, y) with optional text attributes.

fill_rect(buf, x, y, w, h, char, fg, bg, attrs \\ [])

Fill a rectangular region with a character, colors, and optional text attributes.

get_cell(arg1, x, y)

@spec get_cell(t(), integer(), integer()) :: cell() | nil

Get the cell at (x, y). Returns nil if out of bounds.

get_hit_id(buf, x, y)

@spec get_hit_id(t(), integer(), integer()) :: term()

Get the hit_id at coordinates (x, y).

new(cols, rows, opts \\ [])

@spec new(non_neg_integer(), non_neg_integer(), keyword()) :: t()

Create a new buffer with the given dimensions.

pop_scissor(buf)

Pop the top scissor rect, restoring the previous clip region.

push_scissor(buf, x, y, w, h)

Push a scissor rect. Drawing is clipped to the intersection of all active scissor rects.

put_cell(buf, x, y, cell)

@spec put_cell(t(), integer(), integer(), cell()) :: t()

Set a cell at (x, y). No-op if out of bounds or outside scissor rect.

resize(buffer, cols, rows)

@spec resize(t(), non_neg_integer(), non_neg_integer()) :: t()

Resize the buffer. Contents are lost.

set_hit_region(buf, x, y, w, h, hit_id)

@spec set_hit_region(
  t(),
  integer(),
  integer(),
  non_neg_integer(),
  non_neg_integer(),
  term()
) :: t()

Set hit_id for a rectangular region (for mouse event targeting).

to_strings(buf)

@spec to_strings(t()) :: [String.t()]

Convert the full buffer to a list of row strings (for testing/display).