Raxol.Terminal.Buffer.UnifiedManager (Raxol v0.5.0)

View Source

Unified buffer management system for the Raxol terminal emulator. This module combines and enhances the functionality of the previous buffer managers, providing improved memory management, caching, and performance metrics.

Summary

Functions

Returns a specification to start this module under a supervisor.

Cleans up the buffer manager.

Clears the active buffer.

Fills a region in the active buffer with a cell.

Gets the active buffer.

Gets the buffer manager state.

Gets a cell from the active buffer at the specified position.

Gets the memory usage of the buffer.

Gets the total number of lines in the buffer.

Gets the visible content of the buffer.

Gets the visible content for a specific buffer.

Gets the number of visible lines in the buffer.

Creates a new unified buffer manager with the specified dimensions.

Resizes the buffer to new dimensions.

Scrolls a region in the active buffer.

Sets a cell in the active buffer at the specified position.

Starts a new buffer manager process.

Updates the buffer with new commands.

Updates the buffer manager configuration. Delegates to update/2 for compatibility.

Updates the visible region of the buffer.

Writes data to the buffer.

Types

t()

@type t() :: %Raxol.Terminal.Buffer.UnifiedManager{
  active_buffer: Raxol.Terminal.ScreenBuffer.t(),
  back_buffer: Raxol.Terminal.ScreenBuffer.t(),
  height: non_neg_integer(),
  memory_limit: non_neg_integer(),
  memory_usage: non_neg_integer(),
  metrics: map(),
  scrollback_buffer: Raxol.Terminal.Buffer.Scroll.t(),
  scrollback_limit: non_neg_integer(),
  width: non_neg_integer()
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

cleanup(state)

Cleans up the buffer manager.

clear(state)

Clears the active buffer.

Parameters

  • state - The buffer manager state

Returns

  • {:ok, new_state} - The updated buffer manager state

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

Fills a region in the active buffer with a cell.

Parameters

  • state - The buffer manager state
  • x - The starting x coordinate
  • y - The starting y coordinate
  • width - The width of the region
  • height - The height of the region
  • cell - The cell to fill the region with

Returns

  • {:ok, new_state} - The updated buffer manager state

get_active_buffer(state)

Gets the active buffer.

get_buffer_manager(state)

Gets the buffer manager state.

get_cell(state, x, y)

Gets a cell from the active buffer at the specified position.

Parameters

  • state - The buffer manager state
  • x - The x coordinate
  • y - The y coordinate

Returns

  • {:ok, cell} - The cell at the specified position

get_memory_usage(state)

Gets the memory usage of the buffer.

get_total_lines(state)

Gets the total number of lines in the buffer.

get_visible_content(state)

Gets the visible content of the buffer.

get_visible_content(manager, buffer_id)

@spec get_visible_content(t(), String.t()) :: {:ok, [[Cell.t()]]} | {:error, term()}

Gets the visible content for a specific buffer.

get_visible_lines(state)

Gets the number of visible lines in the buffer.

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

Creates a new unified buffer manager with the specified dimensions.

Parameters

  • width - The width of the buffer
  • height - The height of the buffer
  • scrollback_limit - Maximum number of scrollback lines (default: 1000)
  • memory_limit - Maximum memory usage in bytes (default: 10_000_000)

Returns

  • {:ok, state} - The initialized buffer manager state

resize(state, width, height)

Resizes the buffer to new dimensions.

Parameters

  • state - The buffer manager state
  • width - The new width
  • height - The new height

Returns

  • {:ok, new_state} - The updated buffer manager state

scroll_region(state, x, y, width, height, amount)

Scrolls a region in the active buffer.

Parameters

  • state - The buffer manager state
  • x - The starting x coordinate
  • y - The starting y coordinate
  • width - The width of the region
  • height - The height of the region
  • amount - The number of lines to scroll (positive for down, negative for up)

Returns

  • {:ok, new_state} - The updated buffer manager state

set_cell(state, x, y, cell)

Sets a cell in the active buffer at the specified position.

Parameters

  • state - The buffer manager state
  • x - The x coordinate
  • y - The y coordinate
  • cell - The cell to set

Returns

  • {:ok, new_state} - The updated buffer manager state

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_limit - Maximum number of scrollback lines (default: 1000)
  • :memory_limit - Maximum memory usage in bytes (default: 10_000_000)

Returns

  • {:ok, pid} - The process ID of the started buffer manager

update(state, commands)

Updates the buffer with new commands.

update_config(buffer_manager, config)

Updates the buffer manager configuration. Delegates to update/2 for compatibility.

update_visible_region(state, region)

Updates the visible region of the buffer.

write(state, data)

Writes data to the buffer.