Raxol.Terminal.Buffer (Raxol v0.5.0)

View Source

Manages the terminal buffer state and operations.

Summary

Functions

Adds content to the buffer at the current cursor position.

Clears the buffer.

Gets the current cursor position.

Gets all damaged regions in the buffer.

Marks a region of the buffer as damaged.

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

Reads data from the buffer.

Scrolls the buffer by the specified number of lines.

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.

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.

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.

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.

scroll(buffer, lines)

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

Scrolls the buffer by the specified number of lines.

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.