Raxol.Terminal.Buffer.CharOperations (Raxol v0.5.0)
View SourceHandles character-based operations in the terminal buffer.
Summary
Functions
Deletes a specified number of characters starting from the current cursor position. Characters to the right of the deleted characters are shifted left, and blank characters are added at the end.
Helper function that handles the line manipulation logic for deleting characters. Splits the line at the cursor position, removes characters, and adds blanks at the end.
Inserts a specified number of blank characters at the given position. Characters to the right of the insertion point are shifted right. Characters shifted off the end of the line are discarded.
Inserts a specified number of blank characters at the current cursor position. Characters to the right of the cursor are shifted right, and characters shifted off the end are discarded.
Inserts characters into a line at the specified position.
Functions
@spec delete_chars(Raxol.Terminal.ScreenBuffer.t(), non_neg_integer()) :: Raxol.Terminal.ScreenBuffer.t()
Deletes a specified number of characters starting from the current cursor position. Characters to the right of the deleted characters are shifted left, and blank characters are added at the end.
@spec delete_chars_from_line( [Raxol.Terminal.Buffer.Cell.t()], non_neg_integer(), non_neg_integer() ) :: [Raxol.Terminal.Buffer.Cell.t()]
Helper function that handles the line manipulation logic for deleting characters. Splits the line at the cursor position, removes characters, and adds blanks at the end.
Parameters
line
- The line to modifyx
- The column to start deleting fromcount
- The number of characters to delete
Returns
The updated line with characters deleted and blanks added at the end.
Examples
iex> line = List.duplicate(%Cell{char: "A"}, 10)
iex> new_line = CharOperations.delete_chars_from_line(line, 5, 3)
iex> length(new_line)
10
iex> Enum.at(new_line, 5).char
" "
@spec insert_characters( Raxol.Terminal.ScreenBuffer.t(), non_neg_integer(), non_neg_integer(), non_neg_integer(), Raxol.Terminal.ANSI.TextFormatting.text_style() ) :: Raxol.Terminal.ScreenBuffer.t()
Inserts a specified number of blank characters at the given position. Characters to the right of the insertion point are shifted right. Characters shifted off the end of the line are discarded.
Parameters
buffer
- The screen buffer to modifyrow
- The row to insert characters incol
- The column to start inserting atcount
- The number of characters to insertdefault_style
- The style to apply to new characters
Returns
The updated screen buffer.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> style = %{fg: :red, bg: :blue}
iex> buffer = CharOperations.insert_characters(buffer, 0, 0, 5, style)
iex> CharOperations.get_char(buffer, 0, 0)
" "
@spec insert_chars(Raxol.Terminal.ScreenBuffer.t(), non_neg_integer()) :: Raxol.Terminal.ScreenBuffer.t()
Inserts a specified number of blank characters at the current cursor position. Characters to the right of the cursor are shifted right, and characters shifted off the end are discarded.
@spec insert_into_line( [Raxol.Terminal.Buffer.Cell.t()], non_neg_integer(), non_neg_integer(), Raxol.Terminal.ANSI.TextFormatting.text_style() ) :: [Raxol.Terminal.Buffer.Cell.t()]
Inserts characters into a line at the specified position.
Parameters
line
- The line to modifycol
- The column to start inserting atcount
- The number of characters to insertdefault_style
- The style to apply to new characters
Returns
The updated line with inserted characters.
Examples
iex> line = List.duplicate(%Cell{}, 10)
iex> style = %{fg: :red, bg: :blue}
iex> new_line = CharOperations.insert_into_line(line, 5, 3, style)
iex> length(new_line)
10