Raxol.Terminal.Buffer.Operations (Raxol v0.3.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.
Delegates to CharEditor.delete_characters/5
.
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 current width of the screen buffer.
Inserts blank characters at the cursor position {x, y}, shifting existing chars right.
Delegates to CharEditor.insert_characters/5
.
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_buffer, 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.Cell.Style.t() | nil) :: 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.Cell.Style.t() | nil ) :: 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.Buffer.State.t(), row :: non_neg_integer(), col :: non_neg_integer(), count :: non_neg_integer(), style :: Raxol.Terminal.Cell.Style.t() | nil ) :: Raxol.Terminal.Buffer.State.t()
Deletes characters at the cursor position {x, y}, shifting remaining chars left.
Delegates to CharEditor.delete_characters/5
.
@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.Cell.Style.t() | nil ) :: 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.Cell.Style.t() | nil ) :: 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_width(Raxol.Terminal.ScreenBuffer.t()) :: non_neg_integer()
Gets the current width of the screen buffer.
@spec insert_characters( Raxol.Terminal.Buffer.State.t(), row :: non_neg_integer(), col :: non_neg_integer(), count :: non_neg_integer(), style :: Raxol.Terminal.Cell.Style.t() | nil ) :: Raxol.Terminal.Buffer.State.t()
Inserts blank characters at the cursor position {x, y}, shifting existing chars right.
Delegates to CharEditor.insert_characters/5
.
@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.ScreenBuffer.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_buffer, 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.
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.