Raxol.Terminal.Buffer.Manager (Raxol v0.2.0)
View SourceTerminal 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
@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
Returns a specification to start this module under a supervisor.
See Supervisor
.
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}]
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
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
[]
Clears the scroll region, making the entire buffer scrollable.
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
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}]
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}]
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}]
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}]
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}
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
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.
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
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
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.
Examples
iex> manager = Buffer.Manager.new(80, 24)
iex> manager = Buffer.Manager.set_cursor_position(manager, 10, 5)
iex> manager.cursor_position
{10, 5}
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.
Examples
iex> manager = Buffer.Manager.new(80, 24)
iex> manager = Buffer.Manager.switch_buffers(manager)
iex> manager.active_buffer == manager.back_buffer
false
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
Updates the endpoint of the current selection.
Checks if memory usage is within limits.
Examples
iex> manager = Buffer.Manager.new(80, 24)
iex> Buffer.Manager.within_memory_limits?(manager)
true