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

View Source

Terminal buffer manager module.

This module handles the management of terminal buffers, including:

  • Double buffering implementation
  • Damage tracking system
  • Buffer synchronization
  • Memory management

Summary

Functions

Returns a specification to start this module under a supervisor.

Clears the current line.

Clears all damage regions.

Clears the entire display including the scrollback buffer.

Clears the scroll region, making the entire buffer scrollable.

Clears the visible portion of the display (viewport) without affecting the scrollback buffer.

Erases from the beginning of the current line to the cursor.

Erases from the beginning of the display to the cursor.

Erases from the cursor position to the end of the display.

Erases from the cursor to the end of the current line.

Gets the cursor position.

Gets all damaged regions.

Gets the text within the current selection. Returns an empty string if there is no selection.

Gets the boundaries of the current selection. Returns nil if there is no selection.

Checks if the given position is within the current selection. Returns false if there is no selection.

Marks a region of the buffer as damaged.

Creates a new buffer manager with the given dimensions.

Scrolls the buffer down by the specified number of lines. Lines are restored from the scrollback buffer if available.

Scrolls the buffer up by the specified number of lines. Lines that scroll off the top are added to the scrollback buffer.

Sets the cursor position.

Sets a scroll region in the buffer. All scrolling operations will be confined to this region. The region is specified by start and end line numbers (inclusive).

Starts a text selection at the specified coordinates.

Switches the active and back buffers.

Updates memory usage tracking.

Updates the endpoint of the current selection.

Checks if memory usage is within limits.

Types

t()

@type t() :: %Raxol.Terminal.Buffer.Manager{
  active_buffer: Raxol.Terminal.ScreenBuffer.t(),
  back_buffer: Raxol.Terminal.ScreenBuffer.t(),
  cursor_position: {non_neg_integer(), non_neg_integer()},
  damage_tracker: Raxol.Terminal.Buffer.DamageTracker.t(),
  memory_limit: non_neg_integer(),
  memory_usage: non_neg_integer(),
  scrollback: Raxol.Terminal.Buffer.Scrollback.t()
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear_current_line(manager)

Clears the current line.

Examples

iex> manager = Buffer.Manager.new(80, 24)
iex> manager = Buffer.Manager.set_cursor_position(manager, 10, 5)
iex> manager = Buffer.Manager.clear_current_line(manager)
iex> manager.damage_regions
[{0, 5, 79, 5}]

clear_damage_regions(manager)

Clears all damage regions.

Examples

iex> manager = Buffer.Manager.new(80, 24)
iex> manager = Buffer.Manager.mark_damaged(manager, 0, 0, 10, 5)
iex> manager = Buffer.Manager.clear_damage_regions(manager)
iex> length(manager.damage_regions)
0

clear_entire_display_with_scrollback(manager)

Clears the entire display including the scrollback buffer.

Examples

iex> manager = Buffer.Manager.new(80, 24)
iex> manager = Buffer.Manager.clear_entire_display_with_scrollback(manager)
iex> manager.damage_regions
[{0, 0, 79, 23}]
iex> manager.scrollback_buffer
[]

clear_scroll_region(manager)

Clears the scroll region, making the entire buffer scrollable.

clear_visible_display(manager)

Clears the visible portion of the display (viewport) without affecting the scrollback buffer.

Examples

iex> manager = Buffer.Manager.new(80, 24)
# ... (write some data) ...
iex> manager = Buffer.Manager.clear_visible_display(manager)
iex> manager.damage_regions
[{0, 0, 79, 23}]
# Assert buffer contents are cleared, scrollback remains

erase_from_beginning_of_line_to_cursor(manager)

Erases from the beginning of the current line to the cursor.

Examples

iex> manager = Buffer.Manager.new(80, 24)
iex> manager = Buffer.Manager.set_cursor_position(manager, 10, 5)
iex> manager = Buffer.Manager.erase_from_beginning_of_line_to_cursor(manager)
iex> manager.damage_regions
[{0, 5, 10, 5}]

erase_from_beginning_to_cursor(manager)

Erases from the beginning of the display to the cursor.

Examples

iex> manager = Buffer.Manager.new(80, 24)
iex> manager = Buffer.Manager.set_cursor_position(manager, 10, 5)
iex> manager = Buffer.Manager.erase_from_beginning_to_cursor(manager)
iex> manager.damage_regions
[{0, 0, 10, 5}]

erase_from_cursor_to_end(manager)

Erases from the cursor position to the end of the display.

Examples

iex> manager = Buffer.Manager.new(80, 24)
iex> manager = Buffer.Manager.set_cursor_position(manager, 10, 5)
iex> manager = Buffer.Manager.erase_from_cursor_to_end(manager)
iex> manager.damage_regions
[{10, 5, 79, 23}]

erase_from_cursor_to_end_of_line(manager)

Erases from the cursor to the end of the current line.

Examples

iex> manager = Buffer.Manager.new(80, 24)
iex> manager = Buffer.Manager.set_cursor_position(manager, 10, 5)
iex> manager = Buffer.Manager.erase_from_cursor_to_end_of_line(manager)
iex> manager.damage_regions
[{10, 5, 79, 5}]

get_cursor_position(manager)

Gets the cursor position.

Examples

iex> manager = Buffer.Manager.new(80, 24)
iex> manager = Buffer.Manager.set_cursor_position(manager, 10, 5)
iex> Buffer.Manager.get_cursor_position(manager)
{10, 5}

get_damage_regions(manager)

Gets all damaged regions.

Examples

iex> manager = Buffer.Manager.new(80, 24)
iex> manager = Buffer.Manager.mark_damaged(manager, 0, 0, 10, 5)
iex> regions = Buffer.Manager.get_damage_regions(manager)
iex> length(regions)
1

get_selection(manager)

Gets the text within the current selection. Returns an empty string if there is no selection.

get_selection_boundaries(manager)

Gets the boundaries of the current selection. Returns nil if there is no selection.

in_selection?(manager, x, y)

Checks if the given position is within the current selection. Returns false if there is no selection.

mark_damaged(manager, x1, y1, x2, y2)

Marks a region of the buffer as damaged.

Examples

iex> manager = Buffer.Manager.new(80, 24)
iex> manager = Buffer.Manager.mark_damaged(manager, 0, 0, 10, 5)
iex> length(manager.damage_regions)
1

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

Creates a new buffer manager with the given dimensions.

Examples

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

scroll_down(manager, lines)

Scrolls the buffer down by the specified number of lines. Lines are restored from the scrollback buffer if available.

scroll_up(manager, lines)

Scrolls the buffer up by the specified number of lines. Lines that scroll off the top are added to the scrollback buffer.

set_cursor_position(manager, x, y)

Sets the cursor position.

Examples

iex> manager = Buffer.Manager.new(80, 24)
iex> manager = Buffer.Manager.set_cursor_position(manager, 10, 5)
iex> manager.cursor_position
{10, 5}

set_scroll_region(manager, start_line, end_line)

Sets a scroll region in the buffer. All scrolling operations will be confined to this region. The region is specified by start and end line numbers (inclusive).

start_link(opts)

start_selection(manager, x, y)

Starts a text selection at the specified coordinates.

switch_buffers(manager)

Switches the active and back buffers.

Examples

iex> manager = Buffer.Manager.new(80, 24)
iex> manager = Buffer.Manager.switch_buffers(manager)
iex> manager.active_buffer == manager.back_buffer
false

update_memory_usage(manager)

Updates memory usage tracking.

Examples

iex> manager = Buffer.Manager.new(80, 24)
iex> manager = Buffer.Manager.update_memory_usage(manager)
iex> manager.memory_usage > 0
true

update_selection(manager, x, y)

Updates the endpoint of the current selection.

within_memory_limits?(manager)

Checks if memory usage is within limits.

Examples

iex> manager = Buffer.Manager.new(80, 24)
iex> Buffer.Manager.within_memory_limits?(manager)
true