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

View Source

Handles writing characters and strings to the Raxol.Terminal.ScreenBuffer. Responsible for character width, bidirectional text segmentation, and cell creation.

Summary

Functions

Creates a cell style by merging the provided style with default formatting.

Logs character write operations for debugging purposes.

Updates cells in the buffer at the specified position.

Updates a row in the buffer at the specified position.

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 segment of text to the buffer.

Writes a string to the buffer at the specified position. Handles wide characters and bidirectional text.

Functions

create_cell_style(style)

Creates a cell style by merging the provided style with default formatting.

Parameters

  • style - The style to merge with default formatting, or nil for default style

Returns

A map containing the merged text formatting style.

Examples

iex> Writer.create_cell_style(%{fg: :red})
%{fg: :red, bg: :default, bold: false, ...}

log_char_write(char, x, y, cell_style)

Logs character write operations for debugging purposes.

Parameters

  • char - The character being written
  • x - The x-coordinate where the character is being written
  • y - The y-coordinate where the character is being written
  • cell_style - The style being applied to the cell

Returns

:ok

Examples

iex> Writer.log_char_write("A", 0, 0, %{fg: :red})
:ok

update_cells(buffer, x, y, char, cell_style, width)

Updates cells in the buffer at the specified position.

Parameters

  • buffer - The screen buffer to update
  • x - The x-coordinate to update
  • y - The y-coordinate to update
  • char - The character to write
  • cell_style - The style to apply
  • width - The width of the character (1 or 2 for wide characters)

Returns

The updated list of cells.

Examples

iex> buffer = ScreenBuffer.new(80, 24)
iex> Writer.update_cells(buffer, 0, 0, "A", %{fg: :red}, 1)
[%Cell{char: "A", style: %{fg: :red}}, ...]

update_row(row, x, char, cell_style, width, buffer_width)

Updates a row in the buffer at the specified position.

Parameters

  • row - The row to update
  • x - The x-coordinate to update
  • char - The character to write
  • cell_style - The style to apply
  • width - The width of the character (1 or 2 for wide characters)
  • buffer_width - The total width of the buffer

Returns

The updated row of cells.

Examples

iex> row = List.duplicate(Cell.new(), 80)
iex> Writer.update_row(row, 0, "A", %{fg: :red}, 1, 80)
[%Cell{char: "A", style: %{fg: :red}}, ...]

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

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.

write_segment(buffer, x, y, segment)

Writes a segment of text to the buffer.

Parameters

  • buffer - The screen buffer to write to
  • x - The x-coordinate to start writing at
  • y - The y-coordinate to write at
  • segment - The text segment to write

Returns

A tuple containing the updated buffer and the new x-coordinate.

Examples

iex> buffer = ScreenBuffer.new(80, 24)
iex> {new_buffer, new_x} = Writer.write_segment(buffer, 0, 0, "Hello")
iex> new_x
5

write_string(buffer, x, y, string)

Writes a string to the buffer at the specified position. Handles wide characters and bidirectional text.