Raxol.Terminal.Buffer (Raxol v2.0.1)

View Source

Manages the terminal buffer state and operations.

Summary

Functions

Adds content to the buffer at the current cursor position.

Clears the buffer.

Clear a rectangular region in the buffer.

Draw a box in the buffer with the specified style.

Fills a region of the buffer with a specified cell. Delegates to ScreenBuffer.fill_region/6.

Gets a cell from the buffer at the specified coordinates. Delegates to ScreenBuffer.get_cell/3.

Gets the current cursor position.

Gets all damaged regions in the buffer.

Marks a region of the buffer as damaged.

Move the cursor to the specified position.

Creates a new buffer with default dimensions (80x24).

Creates a new buffer with the specified dimensions. Raises ArgumentError if dimensions are invalid.

Reads data from the buffer.

Resizes the buffer to the specified width and height. Delegates to ScreenBuffer.resize/3.

Scrolls the buffer by the specified number of lines.

Updates the scroll state without moving content. This is a fast operation that only updates scroll position.

Sets a cell in the buffer at the specified coordinates. Raises ArgumentError if coordinates or cell data are invalid.

Sets the cursor position.

Sets the scroll region.

Writes data to the buffer at the current cursor position.

Writes text to the buffer at the current position.

Types

t()

@type t() :: %Raxol.Terminal.Buffer{
  cells: [[Raxol.Terminal.Buffer.Cell.t()]],
  cursor_x: non_neg_integer(),
  cursor_y: non_neg_integer(),
  damage_regions: [
    {non_neg_integer(), non_neg_integer(), non_neg_integer(), non_neg_integer()}
  ],
  height: non_neg_integer(),
  scroll_region_bottom: non_neg_integer(),
  scroll_region_top: non_neg_integer(),
  width: non_neg_integer()
}

Functions

add(buffer, content)

@spec add(t(), String.t()) :: t()

Adds content to the buffer at the current cursor position.

Examples

iex> buffer = Buffer.new({80, 24})
iex> buffer = Buffer.add(buffer, "Hello, World!")
iex> {content, _} = Buffer.read(buffer)
iex> content
"Hello, World!"

clear(buffer, opts \\ [])

@spec clear(
  t(),
  keyword()
) :: t()

Clears the buffer.

clear_region(buffer, x, y, width, height)

Clear a rectangular region in the buffer.

draw_box(buffer, x, y, width, height, style \\ nil)

Draw a box in the buffer with the specified style.

fill_region(buffer, x, y, width, height, cell)

Fills a region of the buffer with a specified cell. Delegates to ScreenBuffer.fill_region/6.

get_cell(buffer, x, y)

Gets a cell from the buffer at the specified coordinates. Delegates to ScreenBuffer.get_cell/3.

get_cursor_position(buffer)

@spec get_cursor_position(t()) :: {non_neg_integer(), non_neg_integer()}

Gets the current cursor position.

get_damage_regions(buffer)

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

Gets all damaged regions in the buffer.

mark_damaged(buffer, x, y, width, height)

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

Marks a region of the buffer as damaged.

move_cursor(buffer, x, y)

Move the cursor to the specified position.

new()

@spec new() :: t()

Creates a new buffer with default dimensions (80x24).

new(invalid)

@spec new({non_neg_integer(), non_neg_integer()}) :: t()

Creates a new buffer with the specified dimensions. Raises ArgumentError if dimensions are invalid.

read(buffer, opts \\ [])

@spec read(
  t(),
  keyword()
) :: {String.t(), t()}

Reads data from the buffer.

resize(buffer, width, height)

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

Resizes the buffer to the specified width and height. Delegates to ScreenBuffer.resize/3.

scroll(buffer, lines)

@spec scroll(t(), integer()) :: t()

Scrolls the buffer by the specified number of lines.

scroll_state(buffer, lines)

@spec scroll_state(t(), integer()) :: t()

Updates the scroll state without moving content. This is a fast operation that only updates scroll position.

set_cell(buffer, x, y, cell)

@spec set_cell(
  t(),
  non_neg_integer(),
  non_neg_integer(),
  Raxol.Terminal.Buffer.Cell.t()
) :: t()

Sets a cell in the buffer at the specified coordinates. Raises ArgumentError if coordinates or cell data are invalid.

set_cursor_position(buffer, x, y)

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

Sets the cursor position.

set_scroll_region(buffer, top, bottom)

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

Sets the scroll region.

write(buffer, data, opts \\ [])

@spec write(t(), String.t(), keyword()) :: t()

Writes data to the buffer at the current cursor position.

write_text(buffer, text)

@spec write_text(t(), String.t()) :: t()

Writes text to the buffer at the current position.