Raxol.Terminal.ScreenBuffer (Raxol v2.0.1)

View Source

Manages the terminal's screen buffer state (grid, scrollback, selection). This module serves as the main interface for terminal buffer operations, delegating specific operations to specialized modules in Raxol.Terminal.Buffer.*.

Structure

The buffer consists of:

  • A main grid of cells (the visible screen)
  • A scrollback buffer for history
  • Selection state
  • Scroll region settings
  • Dimensions (width and height)

Operations

The module delegates operations to specialized modules:

  • Content - Writing and content management
  • ScrollRegion - Scroll region and scrolling operations
  • LineOperations - Line manipulation
  • CharEditor - Character editing
  • LineEditor - Line editing
  • Eraser - Clearing operations
  • Selection - Text selection
  • Scrollback - History management
  • Queries - State querying
  • Initializer - Buffer creation and validation
  • Cursor - Cursor state management
  • Charset - Character set management
  • Formatting - Text formatting and styling

Summary

Functions

Clears the scroll region, resetting to full screen.

Deletes a specified number of characters starting from the given position in the buffer. Delegates to CharEditor.delete_characters/5.

Deletes lines at a specific position.

Checks if the buffer is empty.

Erases the entire screen.

Gets a specific cell from the buffer.

Gets the cell at the specified position in the buffer.

Gets the content of the buffer as a string representation.

Gets the dimensions of the buffer.

Gets the height of the buffer.

Gets a specific line from the buffer.

Gets all lines from the buffer as a list of lines.

Gets the estimated memory usage of the screen buffer.

Gets the bottom boundary of the scroll region.

Gets the current scroll position within the scrollback.

Gets the current scroll region boundaries. Returns {0, height-1} if no region is set.

Gets the top boundary of the scroll region.

Gets the width of the buffer.

Inserts blank lines at a specific position with style.

Inserts lines at a specific position within a scroll region.

Creates a new buffer with default dimensions.

Creates a new buffer with a single dimension parameter. Creates a square buffer.

Creates a new screen buffer with the specified dimensions. Validates and normalizes the input dimensions to ensure they are valid.

Puts a line of cells at the specified y position.

Scrolls the buffer content. Returns {buffer, scrolled_lines}.

Scrolls the buffer content down by the specified number of lines.

Scrolls the buffer down by the specified number of lines with additional parameters.

Scrolls the buffer content up by the specified number of lines. Returns {buffer, scrolled_lines} where scrolled_lines are the lines that were scrolled out.

Sets the scroll region with individual top and bottom parameters.

Writes content to the buffer at the specified position. This is a convenience function for write_string.

Writes a character at the specified position with optional styling.

Writes a string starting at the specified position.

Types

t()

@type t() :: %Raxol.Terminal.ScreenBuffer{
  alternate_screen: boolean(),
  cells: [[Raxol.Terminal.Cell.t()]],
  cursor_blink: boolean(),
  cursor_position: {non_neg_integer(), non_neg_integer()},
  cursor_style: atom(),
  cursor_visible: boolean(),
  damage_regions: [
    {non_neg_integer(), non_neg_integer(), non_neg_integer(), non_neg_integer()}
  ],
  default_style: Raxol.Terminal.ANSI.TextFormatting.text_style(),
  height: non_neg_integer(),
  scroll_position: non_neg_integer(),
  scroll_region: {integer(), integer()} | nil,
  scrollback: [[Raxol.Terminal.Cell.t()]],
  scrollback_limit: non_neg_integer(),
  selection: {integer(), integer(), integer(), integer()} | nil,
  width: non_neg_integer()
}

Functions

cleanup(buffer)

clear(buffer, style \\ nil)

clear_damaged_regions(buffer)

clear_line(buffer, line, style)

See Raxol.Terminal.ScreenBuffer.Operations.clear_line/3.

clear_region(buffer, x, y, width, height)

clear_scroll_region(buffer)

@spec clear_scroll_region(t()) :: t()

Clears the scroll region, resetting to full screen.

clear_selection(buffer)

See Raxol.Terminal.ScreenBuffer.Selection.clear_selection/1.

cursor_blinking?(buffer)

See Raxol.Terminal.ScreenBuffer.Attributes.cursor_blinking?/1.

cursor_visible?(buffer)

See Raxol.Terminal.ScreenBuffer.Attributes.cursor_visible?/1.

delete_characters(buffer, row, col, count, default_style)

Deletes a specified number of characters starting from the given position in the buffer. Delegates to CharEditor.delete_characters/5.

delete_chars(buffer, count)

See Raxol.Terminal.ScreenBuffer.Operations.delete_chars/2.

delete_chars(buffer, count, cursor, max_col)

delete_lines(buffer, count)

See Raxol.Terminal.ScreenBuffer.Operations.delete_lines/2.

delete_lines(buffer, y, count, style, bottom)

Deletes lines at a specific position.

Parameters

  • For command handlers: y, count, style, and region boundaries
  • For region operations: lines, y, top, and bottom positions

delete_lines_in_region(buffer, lines, y, top, bottom)

See Raxol.Terminal.Buffer.LineOperations.delete_lines_in_region/5.

empty?(buffer)

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

Checks if the buffer is empty.

erase_chars(buffer, count)

See Raxol.Terminal.ScreenBuffer.Operations.erase_chars/2.

erase_chars(buffer, x, y, count)

See Raxol.Terminal.ScreenBuffer.Operations.erase_chars/4.

erase_display(buffer, mode)

See Raxol.Terminal.ScreenBuffer.Operations.erase_display/2.

erase_display(buffer, mode, cursor, min_row, max_row)

erase_from_cursor_to_end(buffer, x, y, top, bottom)

erase_from_start_to_cursor(buffer, x, y, top, bottom)

erase_in_display(buffer, position, type)

erase_in_line(buffer, position, type)

erase_line(buffer, mode)

See Raxol.Terminal.ScreenBuffer.Operations.erase_line/2.

erase_line(buffer, line, mode)

See Raxol.Terminal.ScreenBuffer.Operations.erase_line/3.

erase_line(buffer, mode, cursor, min_col, max_col)

erase_screen(buffer)

@spec erase_screen(t()) :: t()

Erases the entire screen.

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

See Raxol.Terminal.ScreenBuffer.RegionOperations.fill_region/6.

get_cell(buffer, x, y)

@spec get_cell(t(), non_neg_integer(), non_neg_integer()) :: map()

Gets a specific cell from the buffer.

get_cell_at(buffer, x, y)

@spec get_cell_at(t(), non_neg_integer(), non_neg_integer()) :: map()

Gets the cell at the specified position in the buffer.

get_content(buffer)

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

Gets the content of the buffer as a string representation.

get_cursor_position(buffer)

See Raxol.Terminal.ScreenBuffer.Attributes.get_cursor_position/1.

get_cursor_style(buffer)

See Raxol.Terminal.ScreenBuffer.Attributes.get_cursor_style/1.

get_damaged_regions(buffer)

get_dimensions(buffer)

@spec get_dimensions(t()) :: {non_neg_integer(), non_neg_integer()}

Gets the dimensions of the buffer.

get_height(buffer)

@spec get_height(t()) :: non_neg_integer()

Gets the height of the buffer.

get_line(buffer, y)

@spec get_line(t(), non_neg_integer()) :: [Raxol.Terminal.Cell.t()]

Gets a specific line from the buffer.

get_lines(arg1)

@spec get_lines(t()) :: [[Raxol.Terminal.Cell.t()]]

Gets all lines from the buffer as a list of lines.

get_memory_usage(buffer)

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

Gets the estimated memory usage of the screen buffer.

get_scroll_bottom(buffer)

@spec get_scroll_bottom(t()) :: non_neg_integer()

Gets the bottom boundary of the scroll region.

get_scroll_position(buffer)

@spec get_scroll_position(t()) :: non_neg_integer()

Gets the current scroll position within the scrollback.

get_scroll_region(buffer)

get_scroll_region_boundaries(buffer)

@spec get_scroll_region_boundaries(t()) :: {non_neg_integer(), non_neg_integer()}

Gets the current scroll region boundaries. Returns {0, height-1} if no region is set.

get_scroll_top(buffer)

@spec get_scroll_top(t()) :: non_neg_integer()

Gets the top boundary of the scroll region.

get_scrollback(buffer)

get_selected_text(buffer)

See Raxol.Terminal.ScreenBuffer.Selection.get_selected_text/1.

get_selection(buffer)

get_selection_boundaries(buffer)

get_selection_end(buffer)

get_selection_start(buffer)

get_text_in_region(buffer, start_x, start_y, end_x, end_y)

See Raxol.Terminal.ScreenBuffer.Attributes.get_text_in_region/5.

get_width(buffer)

@spec get_width(t()) :: non_neg_integer()

Gets the width of the buffer.

handle_single_line_replacement(lines_list, row, start_col, end_col, replacement)

See Raxol.Terminal.ScreenBuffer.RegionOperations.handle_single_line_replacement/5.

in_selection?(buffer, x, y)

insert_chars(buffer, count)

See Raxol.Terminal.ScreenBuffer.Operations.insert_chars/2.

insert_chars(buffer, count, cursor, max_col)

insert_lines(buffer, count)

See Raxol.Terminal.ScreenBuffer.Operations.insert_lines/2.

insert_lines(buffer, y, count, style)

Inserts blank lines at a specific position with style.

insert_lines(buffer, y, count, style, bottom)

Inserts lines at a specific position within a scroll region.

Parameters

  • y: position to insert at
  • count: number of lines to insert
  • style: style for the blank lines
  • {top, bottom}: scroll region boundaries

mark_damaged(buffer, x, y, width, height, reason)

new()

Creates a new buffer with default dimensions.

new(size)

Creates a new buffer with a single dimension parameter. Creates a square buffer.

new(width, height, scrollback_limit \\ 1000)

Creates a new screen buffer with the specified dimensions. Validates and normalizes the input dimensions to ensure they are valid.

pop_bottom_lines(buffer, count)

prepend_lines(buffer, lines)

See Raxol.Terminal.ScreenBuffer.Operations.prepend_lines/2.

put_line(buffer, y, line)

@spec put_line(t(), non_neg_integer(), [Raxol.Terminal.Cell.t()]) :: t()

Puts a line of cells at the specified y position.

reset_charset_state(buffer)

See Raxol.Terminal.ScreenBuffer.Attributes.reset_charset_state/1.

reset_scroll_region(buffer)

resize(buffer, new_width, new_height)

scroll(buffer, lines)

Scrolls the buffer content. Returns {buffer, scrolled_lines}.

scroll_down(buffer, lines)

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

Scrolls the buffer content down by the specified number of lines.

scroll_down(buffer, lines, count)

Scrolls the buffer down by the specified number of lines with additional parameters.

scroll_down(buffer, top, bottom, lines)

scroll_to(buffer, top, bottom, line)

scroll_up(buffer, lines)

@spec scroll_up(t(), non_neg_integer()) :: {t(), [[Raxol.Terminal.Cell.t()]]}

Scrolls the buffer content up by the specified number of lines. Returns {buffer, scrolled_lines} where scrolled_lines are the lines that were scrolled out.

scroll_up(buffer, top, bottom, lines)

selection_active?(buffer)

set_cursor_blink(buffer, blink)

See Raxol.Terminal.ScreenBuffer.Attributes.set_cursor_blink/2.

set_cursor_position(buffer, x, y)

See Raxol.Terminal.ScreenBuffer.Attributes.set_cursor_position/3.

set_cursor_style(buffer, style)

See Raxol.Terminal.ScreenBuffer.Attributes.set_cursor_style/2.

set_cursor_visibility(buffer, visible)

See Raxol.Terminal.ScreenBuffer.Attributes.set_cursor_visibility/2.

set_dimensions(buffer, width, height)

set_scroll_region(buffer, arg)

set_scroll_region(buffer, top, bottom)

Sets the scroll region with individual top and bottom parameters.

set_scrollback(buffer, scrollback)

shift_region_to_line(buffer, region, target_line)

start_selection(buffer, x, y)

See Raxol.Terminal.ScreenBuffer.Selection.start_selection/3.

update(buffer, changes)

update_selection(buffer, x, y)

write(buffer, string, opts)

write(buffer, x, y, content)

Writes content to the buffer at the specified position. This is a convenience function for write_string.

write_char(buffer, x, y, char)

@spec write_char(t(), non_neg_integer(), non_neg_integer(), String.t()) :: t()

write_char(buffer, x, y, char, style)

Writes a character at the specified position with optional styling.

write_string(buffer, x, y, string)

@spec write_string(t(), non_neg_integer(), non_neg_integer(), String.t()) :: t()

write_string(buffer, x, y, string, style)

Writes a string starting at the specified position.