Raxol.Terminal.Buffer.CharOperations (Raxol v0.5.0)

View Source

Handles 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

delete_chars(buffer, count)

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.

delete_chars_from_line(line, x, count)

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 modify
  • x - The column to start deleting from
  • count - 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
" "

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

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 modify
  • row - The row to insert characters in
  • col - The column to start inserting at
  • count - The number of characters to insert
  • default_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)
" "

insert_chars(buffer, count)

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.

insert_into_line(line, col, count, default_style)

Inserts characters into a line at the specified position.

Parameters

  • line - The line to modify
  • col - The column to start inserting at
  • count - The number of characters to insert
  • default_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