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

View Source

Provides functions for manipulating the Raxol.Terminal.ScreenBuffer grid and state. Includes writing, clearing, deleting, inserting, resizing, and other operations.

Summary

Functions

Clears the entire screen buffer (excluding scrollback) with empty cells.

Clears a rectangular region of the buffer by replacing cells with empty cells.

Clears the scroll region setting in the buffer.

Deletes characters at the cursor position {x, y}, shifting remaining chars left.

Deletes n lines starting from start_y within the scroll region. Lines below are shifted up, blank lines added at the bottom of the region.

Calculates the difference between the current buffer state and a list of desired cell changes. Returns a list of {x, y, cell_map} tuples representing only the cells that need to be updated. Input changes must be a list of {x, y, map} tuples.

Erases parts of the display based on cursor position (:to_end, :to_beginning, :all). Requires cursor state {x, y}.

Erases parts of the current line based on cursor position (:to_end, :to_beginning, :all). Requires cursor state {x, y}.

Gets a specific Cell from the buffer at {x, y}. Returns nil if coordinates are out of bounds.

Gets the cell at the specified coordinates {x, y}. Returns nil if coordinates are out of bounds. Alias for get_cell/3.

Converts the screen buffer content to a plain text string.

Gets the dimensions {width, height} of the screen buffer.

Gets the current height of the screen buffer.

Gets a specific line (list of Cells) from the buffer by index. Returns nil if index is out of bounds.

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

Gets the current width of the screen buffer.

Inserts blank characters at the cursor position {x, y}, shifting existing chars right.

Inserts n blank lines at start_y within the scroll region, shifting lines down.

Resizes the screen buffer to the new dimensions. Preserves content that fits within the new bounds. Clears selection and scroll region.

Scrolls the buffer down by the specified number of lines, optionally within a specified scroll region. Handles cell manipulation using provided lines from scrollback. Expects lines_to_insert from the caller (e.g., Buffer.Manager via Buffer.Scrollback).

Scrolls the buffer up by the specified number of lines, optionally within a specified scroll region. Handles cell manipulation. Returns {updated_cells, scrolled_off_lines}.

Sets a scroll region in the buffer.

Updates the buffer state by applying a list of cell changes. Changes must be in the format {x, y, Cell.t() | map()}. Returns the updated buffer.

Writes a character to the buffer at the specified position. Handles wide characters by taking up two cells when necessary. Accepts an optional style to apply to the cell.

Writes a string to the buffer at the specified position. Handles wide characters and bidirectional text.

Functions

clear(buffer)

Clears the entire screen buffer (excluding scrollback) with empty cells.

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

Clears a rectangular region of the buffer by replacing cells with empty cells.

clear_scroll_region(buffer)

Clears the scroll region setting in the buffer.

delete_characters(buffer, arg2, count)

Deletes characters at the cursor position {x, y}, shifting remaining chars left.

delete_lines(buffer, start_y, n, scroll_region)

Deletes n lines starting from start_y within the scroll region. Lines below are shifted up, blank lines added at the bottom of the region.

diff(buffer, changes)

Calculates the difference between the current buffer state and a list of desired cell changes. Returns a list of {x, y, cell_map} tuples representing only the cells that need to be updated. Input changes must be a list of {x, y, map} tuples.

erase_in_display(buffer, arg, type)

Erases parts of the display based on cursor position (:to_end, :to_beginning, :all). Requires cursor state {x, y}.

erase_in_line(buffer, arg, type)

Erases parts of the current line based on cursor position (:to_end, :to_beginning, :all). Requires cursor state {x, y}.

get_cell(buffer, x, y)

Gets a specific Cell from the buffer at {x, y}. Returns nil if coordinates are out of bounds.

get_cell_at(buffer, x, y)

Gets the cell at the specified coordinates {x, y}. Returns nil if coordinates are out of bounds. Alias for get_cell/3.

get_content(buffer)

@spec get_content(Raxol.Terminal.ScreenBuffer.t()) :: String.t()

Converts the screen buffer content to a plain text string.

get_dimensions(buffer)

Gets the dimensions {width, height} of the screen buffer.

get_height(buffer)

Gets the current height of the screen buffer.

get_line(buffer, line_index)

Gets a specific line (list of Cells) from the buffer by index. Returns nil if index is out of bounds.

get_scroll_region_boundaries(buffer)

@spec get_scroll_region_boundaries(Raxol.Terminal.ScreenBuffer.t()) ::
  {non_neg_integer(), non_neg_integer()}

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

get_width(buffer)

Gets the current width of the screen buffer.

insert_characters(buffer, pos, count, style \\ nil)

Inserts blank characters at the cursor position {x, y}, shifting existing chars right.

insert_lines(buffer, start_y, n, scroll_region)

Inserts n blank lines at start_y within the scroll region, shifting lines down.

resize(buffer, new_width, new_height)

Resizes the screen buffer to the new dimensions. Preserves content that fits within the new bounds. Clears selection and scroll region.

scroll_down(buffer, lines_to_insert, lines, scroll_region \\ nil)

Scrolls the buffer down by the specified number of lines, optionally within a specified scroll region. Handles cell manipulation using provided lines from scrollback. Expects lines_to_insert from the caller (e.g., Buffer.Manager via Buffer.Scrollback).

scroll_up(buffer, lines, scroll_region \\ nil)

Scrolls the buffer up by the specified number of lines, optionally within a specified scroll region. Handles cell manipulation. Returns {updated_cells, scrolled_off_lines}.

set_scroll_region(buffer, start_line, end_line)

Sets a scroll region in the buffer.

update(buffer, changes)

Updates the buffer state by applying a list of cell changes. Changes must be in the format {x, y, Cell.t() | map()}. Returns the updated buffer.

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

Writes a character to the buffer at the specified position. Handles wide characters by taking up two cells when necessary. Accepts an optional style to apply to the cell.

write_string(buffer, x, y, string)

Writes a string to the buffer at the specified position. Handles wide characters and bidirectional text.