Raxol.Terminal.Buffer.Manager (Raxol v0.3.0)

View Source

Manages terminal buffers and their operations. Coordinates between different buffer-related modules.

Summary

Functions

Returns a specification to start this module under a supervisor.

Clears all damage regions.

Returns the default tab stop positions for a given width.

Gets a cell from the active buffer.

Gets the current cursor position.

Gets the damaged regions in the buffer.

Gets the current memory usage.

Gets the number of lines in the scrollback buffer.

Gets the current state of the buffer manager.

Initializes main and alternate screen buffers with the specified dimensions.

Marks a region of the buffer as damaged (needs redraw).

Creates a new buffer manager with the specified dimensions.

Resizes the buffer.

Sets a cell in the active buffer.

Sets the cursor position.

Sets the cursor position in the buffer manager.

Starts a new buffer manager process.

Updates the memory usage for the buffer manager.

Types

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear_damage(pid)

Clears all damage regions.

Examples

iex> {:ok, pid} = Buffer.Manager.start_link()
iex> :ok = Buffer.Manager.clear_damage(pid)
iex> Buffer.Manager.get_damage(pid)
[]

default_tab_stops(width)

Returns the default tab stop positions for a given width.

Examples

iex> Manager.default_tab_stops(8)
[0, 8, 16, 24, 32, 40, 48, 56]

get_cell(pid, x, y)

Gets a cell from the active buffer.

Examples

iex> {:ok, pid} = Buffer.Manager.start_link()
iex> Buffer.Manager.get_cell(pid, 0, 0)
%Cell{char: " ", fg: :default, bg: :default}

get_cursor(pid)

Gets the current cursor position.

Examples

iex> {:ok, pid} = Buffer.Manager.start_link()
iex> Buffer.Manager.get_cursor(pid)
{0, 0}

get_damage(pid)

Gets the damaged regions in the buffer.

Examples

iex> {:ok, pid} = Buffer.Manager.start_link()
iex> Buffer.Manager.get_damage(pid)
[]

get_memory_usage(pid)

Gets the current memory usage.

Examples

iex> {:ok, pid} = Buffer.Manager.start_link()
iex> Buffer.Manager.get_memory_usage(pid)
0

get_scrollback_count(pid)

Gets the number of lines in the scrollback buffer.

Examples

iex> {:ok, pid} = Buffer.Manager.start_link()
iex> Buffer.Manager.get_scrollback_count(pid)
0

get_state(pid)

Gets the current state of the buffer manager.

Examples

iex> {:ok, pid} = Buffer.Manager.start_link()
iex> state = Buffer.Manager.get_state(pid)
iex> state.active_buffer.width
80

initialize_buffers(width, height, scrollback_limit)

Initializes main and alternate screen buffers with the specified dimensions.

Examples

iex> {main_buffer, alt_buffer} = Manager.initialize_buffers(80, 24, 1000)
iex> main_buffer.width
80
iex> alt_buffer.height
24

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

Marks a region of the buffer as damaged (needs redraw).

new(width, height, scrollback_limit \\ 1000, memory_limit \\ 10_000_000)

Creates a new buffer manager with the specified dimensions.

Examples

iex> {:ok, manager} = Manager.new(80, 24)
iex> manager.active_buffer.width
80
iex> manager.active_buffer.height
24

resize(pid, width, height)

Resizes the buffer.

Examples

iex> {:ok, pid} = Buffer.Manager.start_link()
iex> :ok = Buffer.Manager.resize(pid, 100, 30)
iex> state = Buffer.Manager.get_state(pid)
iex> state.active_buffer.width
100
iex> state.active_buffer.height
30

set_cell(pid, x, y, cell)

Sets a cell in the active buffer.

Examples

iex> {:ok, pid} = Buffer.Manager.start_link()
iex> cell = %Cell{char: "A", fg: :red, bg: :blue}
iex> :ok = Buffer.Manager.set_cell(pid, 0, 0, cell)
iex> state = Buffer.Manager.get_state(pid)
iex> Buffer.get_cell(state, 0, 0)
%Cell{char: "A", fg: :red, bg: :blue}

set_cursor(pid, x, y)

Sets the cursor position.

Examples

iex> {:ok, pid} = Buffer.Manager.start_link()
iex> :ok = Buffer.Manager.set_cursor(pid, 10, 5)
iex> state = Buffer.Manager.get_state(pid)
iex> Cursor.get_position(state)
{10, 5}

set_cursor_position(state, x, y)

Sets the cursor position in the buffer manager.

start_link(opts \\ [])

Starts a new buffer manager process.

Options

  • :width - The width of the buffer (default: 80)
  • :height - The height of the buffer (default: 24)
  • :scrollback_height - The maximum number of scrollback lines (default: 1000)
  • :memory_limit - The maximum memory usage in bytes (default: 10_000_000)

Examples

iex> {:ok, pid} = Buffer.Manager.start_link(width: 100, height: 30)
iex> Process.alive?(pid)
true

update_memory_usage(state)

Updates the memory usage for the buffer manager.