Raxol.Terminal.Buffer.Operations (Raxol v0.2.0)
View SourceProvides 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
@spec clear(Raxol.Terminal.ScreenBuffer.t()) :: Raxol.Terminal.ScreenBuffer.t()
Clears the entire screen buffer (excluding scrollback) with empty cells.
@spec clear_region( Raxol.Terminal.ScreenBuffer.t(), non_neg_integer(), non_neg_integer(), non_neg_integer(), non_neg_integer() ) :: Raxol.Terminal.ScreenBuffer.t()
Clears a rectangular region of the buffer by replacing cells with empty cells.
@spec clear_scroll_region(Raxol.Terminal.ScreenBuffer.t()) :: Raxol.Terminal.ScreenBuffer.t()
Clears the scroll region setting in the buffer.
@spec delete_characters( Raxol.Terminal.ScreenBuffer.t(), {non_neg_integer(), non_neg_integer()}, non_neg_integer() ) :: Raxol.Terminal.ScreenBuffer.t()
Deletes characters at the cursor position {x, y}, shifting remaining chars left.
@spec delete_lines( Raxol.Terminal.ScreenBuffer.t(), non_neg_integer(), non_neg_integer(), {non_neg_integer(), non_neg_integer()} | nil ) :: Raxol.Terminal.ScreenBuffer.t()
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.
@spec diff( Raxol.Terminal.ScreenBuffer.t(), [{non_neg_integer(), non_neg_integer(), map()}] ) :: [{non_neg_integer(), non_neg_integer(), map()}]
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.
@spec erase_in_display( Raxol.Terminal.ScreenBuffer.t(), {non_neg_integer(), non_neg_integer()}, atom() ) :: Raxol.Terminal.ScreenBuffer.t()
Erases parts of the display based on cursor position (:to_end, :to_beginning, :all). Requires cursor state {x, y}.
@spec erase_in_line( Raxol.Terminal.ScreenBuffer.t(), {non_neg_integer(), non_neg_integer()}, atom() ) :: Raxol.Terminal.ScreenBuffer.t()
Erases parts of the current line based on cursor position (:to_end, :to_beginning, :all). Requires cursor state {x, y}.
@spec get_cell(Raxol.Terminal.ScreenBuffer.t(), non_neg_integer(), non_neg_integer()) :: Raxol.Terminal.Cell.t() | nil
Gets a specific Cell from the buffer at {x, y}. Returns nil if coordinates are out of bounds.
@spec get_cell_at( Raxol.Terminal.ScreenBuffer.t(), non_neg_integer(), non_neg_integer() ) :: Raxol.Terminal.Cell.t() | nil
Gets the cell at the specified coordinates {x, y}. Returns nil if coordinates are out of bounds. Alias for get_cell/3.
@spec get_content(Raxol.Terminal.ScreenBuffer.t()) :: String.t()
Converts the screen buffer content to a plain text string.
@spec get_dimensions(Raxol.Terminal.ScreenBuffer.t()) :: {non_neg_integer(), non_neg_integer()}
Gets the dimensions {width, height} of the screen buffer.
@spec get_height(Raxol.Terminal.ScreenBuffer.t()) :: non_neg_integer()
Gets the current height of the screen buffer.
@spec get_line(Raxol.Terminal.ScreenBuffer.t(), non_neg_integer()) :: [Raxol.Terminal.Cell.t()] | nil
Gets a specific line (list of Cells) from the buffer by index. Returns nil if index is out of bounds.
@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.
@spec get_width(Raxol.Terminal.ScreenBuffer.t()) :: non_neg_integer()
Gets the current width of the screen buffer.
@spec insert_characters( Raxol.Terminal.ScreenBuffer.t(), {non_neg_integer(), non_neg_integer()}, non_neg_integer(), Raxol.Terminal.ANSI.TextFormatting.text_style() | nil ) :: Raxol.Terminal.ScreenBuffer.t()
Inserts blank characters at the cursor position {x, y}, shifting existing chars right.
@spec insert_lines( Raxol.Terminal.ScreenBuffer.t(), non_neg_integer(), non_neg_integer(), {non_neg_integer(), non_neg_integer()} | nil ) :: Raxol.Terminal.ScreenBuffer.t()
Inserts n
blank lines at start_y
within the scroll region, shifting lines down.
@spec resize(Raxol.Terminal.ScreenBuffer.t(), non_neg_integer(), non_neg_integer()) :: Raxol.Terminal.ScreenBuffer.t()
Resizes the screen buffer to the new dimensions. Preserves content that fits within the new bounds. Clears selection and scroll region.
@spec scroll_down( Raxol.Terminal.ScreenBuffer.t(), [[Raxol.Terminal.Cell.t()]], non_neg_integer(), {non_neg_integer(), non_neg_integer()} | nil ) :: Raxol.Terminal.ScreenBuffer.t()
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).
@spec scroll_up( Raxol.Terminal.ScreenBuffer.t(), non_neg_integer(), {non_neg_integer(), non_neg_integer()} | nil ) :: {[[Raxol.Terminal.Cell.t()]], [[Raxol.Terminal.Cell.t()]]}
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}
.
@spec set_scroll_region( Raxol.Terminal.ScreenBuffer.t(), non_neg_integer(), non_neg_integer() ) :: Raxol.Terminal.ScreenBuffer.t()
Sets a scroll region in the buffer.
@spec update( Raxol.Terminal.ScreenBuffer.t(), [{non_neg_integer(), non_neg_integer(), Raxol.Terminal.Cell.t() | map()}] ) :: Raxol.Terminal.ScreenBuffer.t()
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.
@spec write_char( Raxol.Terminal.ScreenBuffer.t(), non_neg_integer(), non_neg_integer(), String.t(), Raxol.Terminal.ANSI.TextFormatting.text_style() | nil ) :: Raxol.Terminal.ScreenBuffer.t()
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.
@spec write_string( Raxol.Terminal.ScreenBuffer.t(), non_neg_integer(), non_neg_integer(), String.t() ) :: Raxol.Terminal.ScreenBuffer.t()
Writes a string to the buffer at the specified position. Handles wide characters and bidirectional text.