Raxol.Terminal.ScreenBuffer.DataAdapter (Raxol v2.0.1)

View Source

Data structure adapter for ScreenBuffer operations.

Provides bidirectional conversion between the two buffer formats:

  • ScreenBuffer.Core format: :cells (list of lists of Cell structs)
  • LineOperations format: :lines (map with integer keys to line lists)

This adapter allows seamless interoperability between different buffer operation layers without requiring architectural changes.

Summary

Functions

Convert buffer from cells format to lines format.

Create empty cells structure for initialization.

Create an empty line with the specified width and style.

Get a line from buffer regardless of format.

Check if buffer uses cells format (list of lists).

Check if buffer uses lines format (map).

Convert buffer from lines format back to cells format.

Set a line in buffer regardless of format.

Execute an operation function with the buffer temporarily in lines format.

Functions

cells_to_lines(buffer)

@spec cells_to_lines(map()) :: map()

Convert buffer from cells format to lines format.

Transforms buffer.cells (list of lists) into a :lines map where keys are row indices and values are cell lists.

create_empty_cells(width, height, default_style)

@spec create_empty_cells(integer(), integer(), map()) :: [list()]

Create empty cells structure for initialization.

create_empty_line(width, default_style)

@spec create_empty_line(integer(), map()) :: list()

Create an empty line with the specified width and style.

get_line(buffer, y, default)

@spec get_line(map(), integer(), list()) :: list()

Get a line from buffer regardless of format.

has_cells_format?(buffer)

@spec has_cells_format?(map()) :: boolean()

Check if buffer uses cells format (list of lists).

has_lines_format?(buffer)

@spec has_lines_format?(map()) :: boolean()

Check if buffer uses lines format (map).

lines_to_cells(buffer, lines_map)

@spec lines_to_cells(map(), map()) :: map()

Convert buffer from lines format back to cells format.

Transforms :lines map back into buffer.cells (list of lists).

set_line(buffer, y, line)

@spec set_line(map(), integer(), list()) :: map()

Set a line in buffer regardless of format.

with_lines_format(buffer, operation_fn)

@spec with_lines_format(map(), (map() -> map() | tuple())) :: map() | tuple()

Execute an operation function with the buffer temporarily in lines format.

This is the key function that allows LineOperations to work with ScreenBuffer.Core structures without permanent conversion.

The operation function can return either:

  • A modified buffer map
  • A tuple where the second element is the modified buffer map