Raxol.Terminal.ScreenBuffer.Manager (Raxol v2.0.1)

View Source

Manages buffer lifecycle, memory tracking, damage regions, and buffer switching. Consolidates: Manager, UnifiedManager, SafeManager, EnhancedManager, DamageTracker.

Summary

Functions

Adds a damage region to the active buffer.

Clears the active buffer.

Clears damage regions (stub).

Clears all damage regions from the active buffer.

Constrains a position to buffer bounds (stub).

Gets the currently active buffer.

Gets all damage regions from the active buffer.

Gets memory usage statistics.

Gets current memory usage in bytes.

Gets all metrics.

Gets current cursor position (stub).

Gets total lines in buffer including scrollback (stub).

Gets visible content as string (stub).

Gets visible lines count (stub).

Initializes buffers (stub for test compatibility).

Marks the entire buffer as damaged.

Moves cursor to position (stub).

Creates a new buffer manager with main and alternate buffers.

Reads data from the active buffer (stub for test compatibility).

Increments a clear operation metric.

Increments a scroll operation metric.

Increments a write operation metric.

Resets metrics.

Resets cursor position to origin (stub).

Starts a GenServer for the manager (stub for test compatibility).

Switches between main and alternate buffers.

Switches to alternate buffer (convenience function).

Switches to main buffer (convenience function).

Toggles between main and alternate buffers.

Trims scrollback if exceeding memory limits.

Updates the active buffer.

Updates memory usage calculation.

Updates cursor position with delta (stub).

Updates visible region for scrolling (stub).

Checks if within memory limits.

Writes data to the active buffer (stub for test compatibility).

Types

t()

@type t() :: %Raxol.Terminal.ScreenBuffer.Manager{
  active_buffer_type: :main | :alternate,
  alternate_buffer: Raxol.Terminal.ScreenBuffer.Core.t(),
  main_buffer: Raxol.Terminal.ScreenBuffer.Core.t(),
  memory_limit: non_neg_integer(),
  memory_usage: non_neg_integer(),
  metrics: map()
}

Functions

add_damage(manager, x, y, width, height)

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

Adds a damage region to the active buffer.

clear(manager)

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

Clears the active buffer.

clear_damage(manager)

@spec clear_damage(t()) :: t()

Clears damage regions (stub).

clear_damage_regions(manager)

@spec clear_damage_regions(t()) :: t()

Clears all damage regions from the active buffer.

constrain_position(manager, x, y)

@spec constrain_position(t(), integer(), integer()) :: {integer(), integer()}

Constrains a position to buffer bounds (stub).

get_active_buffer(manager)

@spec get_active_buffer(t()) :: Raxol.Terminal.ScreenBuffer.Core.t()

Gets the currently active buffer.

get_damage_regions(manager)

@spec get_damage_regions(t()) :: [tuple()]

Gets all damage regions from the active buffer.

get_memory_stats(manager)

@spec get_memory_stats(t()) :: map()

Gets memory usage statistics.

get_memory_usage(manager)

@spec get_memory_usage(t()) :: non_neg_integer()

Gets current memory usage in bytes.

get_metrics(manager)

@spec get_metrics(t()) :: map()

Gets all metrics.

get_position(manager)

@spec get_position(t()) :: {integer(), integer()}

Gets current cursor position (stub).

get_total_lines(manager)

@spec get_total_lines(t()) :: non_neg_integer()

Gets total lines in buffer including scrollback (stub).

get_visible_content(manager)

@spec get_visible_content(t()) :: String.t()

Gets visible content as string (stub).

get_visible_lines(manager)

@spec get_visible_lines(t()) :: non_neg_integer()

Gets visible lines count (stub).

initialize_buffers(width, height, scrollback_limit \\ 1000)

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

Initializes buffers (stub for test compatibility).

mark_all_damaged(manager)

@spec mark_all_damaged(t()) :: t()

Marks the entire buffer as damaged.

move_to(manager, x, y)

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

Moves cursor to position (stub).

new(width, height, opts \\ [])

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

Creates a new buffer manager with main and alternate buffers.

read(manager, opts \\ [])

@spec read(
  t(),
  keyword()
) :: binary() | list()

Reads data from the active buffer (stub for test compatibility).

record_clear(manager)

@spec record_clear(t()) :: t()

Increments a clear operation metric.

record_scroll(manager)

@spec record_scroll(t()) :: t()

Increments a scroll operation metric.

record_write(manager)

@spec record_write(t()) :: t()

Increments a write operation metric.

reset_metrics(manager)

@spec reset_metrics(t()) :: t()

Resets metrics.

reset_position(manager)

@spec reset_position(t()) :: t()

Resets cursor position to origin (stub).

resize(manager, new_width, new_height)

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

Resizes both buffers.

start_link(opts \\ [])

@spec start_link(keyword()) :: {:ok, pid()} | {:error, term()}

Starts a GenServer for the manager (stub for test compatibility).

switch_buffer(manager, atom)

@spec switch_buffer(t(), :main | :alternate) :: t()

Switches between main and alternate buffers.

switch_to_alternate(manager)

@spec switch_to_alternate(t()) :: t()

Switches to alternate buffer (convenience function).

switch_to_main(manager)

@spec switch_to_main(t()) :: t()

Switches to main buffer (convenience function).

toggle_buffer(manager)

@spec toggle_buffer(t()) :: t()

Toggles between main and alternate buffers.

trim_if_needed(manager)

@spec trim_if_needed(t()) :: t()

Trims scrollback if exceeding memory limits.

update_active_buffer(manager, fun)

@spec update_active_buffer(t(), (Raxol.Terminal.ScreenBuffer.Core.t() ->
                             Raxol.Terminal.ScreenBuffer.Core.t())) :: t()
@spec update_active_buffer(t(), Raxol.Terminal.ScreenBuffer.Core.t()) :: t()

Updates the active buffer.

Can accept either:

  • A function that transforms the current buffer
  • A new buffer to replace the current one

update_memory_usage(manager)

@spec update_memory_usage(t()) :: t()

Updates memory usage calculation.

update_position(manager, arg)

@spec update_position(
  t(),
  {integer(), integer()}
) :: t()

Updates cursor position with delta (stub).

update_visible_region(manager, scroll_offset)

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

Updates visible region for scrolling (stub).

within_memory_limits?(manager)

@spec within_memory_limits?(t()) :: boolean()

Checks if within memory limits.

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

@spec write(t(), binary(), keyword()) :: {:ok, t()} | t()

Writes data to the active buffer (stub for test compatibility).