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

View Source

Handles buffer operations for the terminal, including resizing, scrolling, and cursor movement.

Summary

Functions

Clears the scrollback buffer.

Creates a new empty line with the specified number of columns.

Deletes the specified number of characters at the cursor position.

Deletes the specified number of lines at the cursor position.

Deletes the specified number of lines at the cursor position with scroll region.

Erases the entire line.

Erases characters from the cursor position to the end of the line.

Erases characters from the start of the line to the cursor position.

Erases characters in the display based on the mode.

Erases characters in the current line based on the mode.

Erases all lines after the specified row.

Erases all lines before the specified row.

Gets the content of the buffer.

Moves the cursor to the beginning of the next line.

Inserts the specified number of blank characters at the cursor position.

Inserts the specified number of blank lines at the cursor position.

Inserts the specified number of blank lines at the cursor position with scroll region.

Checks if scrolling is needed and performs it if necessary.

Checks if scrolling is needed based on buffer state.

Creates a new buffer with the specified dimensions.

Moves the cursor to the next line, scrolling if necessary.

Reads data from the buffer.

Resizes the buffer to the specified dimensions.

Moves the cursor to the previous line.

Scrolls the buffer by the specified number of lines.

Scrolls the buffer down by the specified number of lines.

Scrolls the buffer up by the specified number of lines.

Writes data to the buffer.

Writes a character to the buffer at the specified position.

Writes a string to the buffer.

Functions

clear_scrollback(buffer)

@spec clear_scrollback(ScreenBuffer.t()) :: ScreenBuffer.t()

Clears the scrollback buffer.

Parameters

  • buffer - The screen buffer to modify

Returns

The modified buffer with an empty scrollback.

Examples

iex> buffer = ScreenBuffer.new(80, 24)
iex> Operations.clear_scrollback(buffer)
%{buffer | scrollback: []}

create_empty_line(cols)

@spec create_empty_line(non_neg_integer()) :: [Raxol.Terminal.Buffer.Cell.t()]

Creates a new empty line with the specified number of columns.

Parameters

  • cols - The number of columns in the line

Returns

A list of empty cells representing a line.

Examples

iex> Operations.create_empty_line(80)
[%Cell{char: "", style: %{}}, ...]

delete_chars(buffer, count)

Deletes the specified number of characters at the cursor position.

delete_lines(buffer, count, cursor_y, cursor_x)

Deletes the specified number of lines at the cursor position.

delete_lines(buffer, count, cursor_y, cursor_x, scroll_top, scroll_bottom)

Deletes the specified number of lines at the cursor position with scroll region.

erase_entire_line(buffer, row)

@spec erase_entire_line(ScreenBuffer.t(), non_neg_integer()) :: ScreenBuffer.t()

Erases the entire line.

Parameters

  • buffer - The screen buffer to modify
  • row - The row to erase

Returns

The modified buffer with the specified line erased.

Examples

iex> buffer = ScreenBuffer.new(80, 24)
iex> Operations.erase_entire_line(buffer, 0)
[%Cell{char: "", style: %{}}, ...]

erase_from_cursor_to_line_end(buffer, row, col)

@spec erase_from_cursor_to_line_end(
  ScreenBuffer.t(),
  non_neg_integer(),
  non_neg_integer()
) :: ScreenBuffer.t()

Erases characters from the cursor position to the end of the line.

Parameters

  • buffer - The screen buffer to modify
  • row - The row to erase from
  • col - The column to start erasing from

Returns

The modified buffer with characters erased.

Examples

iex> buffer = ScreenBuffer.new(80, 24)
iex> Operations.erase_from_cursor_to_line_end(buffer, 0, 40)
[%Cell{char: "", style: %{}}, ...]

erase_from_line_start_to_cursor(buffer, row, col)

@spec erase_from_line_start_to_cursor(
  ScreenBuffer.t(),
  non_neg_integer(),
  non_neg_integer()
) :: ScreenBuffer.t()

Erases characters from the start of the line to the cursor position.

Parameters

  • buffer - The screen buffer to modify
  • row - The row to erase from
  • col - The column to erase up to

Returns

The modified buffer with characters erased.

Examples

iex> buffer = ScreenBuffer.new(80, 24)
iex> Operations.erase_from_line_start_to_cursor(buffer, 0, 40)
[%Cell{char: "", style: %{}}, ...]

erase_in_display(buffer, mode, cursor)

Erases characters in the display based on the mode.

erase_in_line(buffer, mode, cursor)

Erases characters in the current line based on the mode.

erase_lines_after(buffer, start_row)

@spec erase_lines_after(ScreenBuffer.t(), non_neg_integer()) :: ScreenBuffer.t()

Erases all lines after the specified row.

Parameters

  • buffer - The screen buffer to modify
  • start_row - The row to start erasing from

Returns

The modified buffer with all lines after start_row erased.

Examples

iex> buffer = ScreenBuffer.new(80, 24)
iex> Operations.erase_lines_after(buffer, 12)
[%Cell{char: "", style: %{}}, ...]

erase_lines_before(buffer, end_row)

@spec erase_lines_before(ScreenBuffer.t(), non_neg_integer()) :: ScreenBuffer.t()

Erases all lines before the specified row.

Parameters

  • buffer - The screen buffer to modify
  • end_row - The row to erase up to

Returns

The modified buffer with all lines before end_row erased.

Examples

iex> buffer = ScreenBuffer.new(80, 24)
iex> Operations.erase_lines_before(buffer, 12)
[%Cell{char: "", style: %{}}, ...]

get_content(buffer)

Gets the content of the buffer.

index(buffer)

Moves the cursor to the beginning of the next line.

insert_chars(buffer, count)

Inserts the specified number of blank characters at the cursor position.

insert_lines(buffer, count, cursor_y, cursor_x)

Inserts the specified number of blank lines at the cursor position.

insert_lines(buffer, count, cursor_y, cursor_x, scroll_top, scroll_bottom)

Inserts the specified number of blank lines at the cursor position with scroll region.

maybe_scroll(buffer)

Checks if scrolling is needed and performs it if necessary.

needs_scroll?(buffer)

@spec needs_scroll?(ScreenBuffer.t()) :: boolean()

Checks if scrolling is needed based on buffer state.

Parameters

  • buffer - The screen buffer to check

Returns

A boolean indicating if scrolling is needed.

Examples

iex> buffer = ScreenBuffer.new(80, 24)
iex> Operations.needs_scroll?(buffer)
false

new(opts)

Creates a new buffer with the specified dimensions.

next_line(buffer)

Moves the cursor to the next line, scrolling if necessary.

read(buffer, opts \\ [])

Reads data from the buffer.

resize(buffer, rows, cols)

Resizes the buffer to the specified dimensions.

reverse_index(buffer)

Moves the cursor to the previous line.

scroll(buffer, lines)

Scrolls the buffer by the specified number of lines.

scroll_down(buffer, lines)

scroll_down(buffer, lines, cursor_y, cursor_x)

Scrolls the buffer down by the specified number of lines.

scroll_up(buffer, lines)

scroll_up(buffer, lines, cursor_y, cursor_x)

Scrolls the buffer up by the specified number of lines.

write(buffer, data, opts \\ [])

Writes data to the buffer.

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

Writes a character to the buffer at the specified position.

write_string(buffer, x, y, string)

Writes a string to the buffer.