Raxol.Core.Runtime.Rendering.Backends (Raxol v2.6.1)

View Source

Rendering backend implementations for different output targets.

Handles converting cells to output for terminal, VSCode, LiveView, and SSH backends. Extracted from Raxol.Core.Runtime.Rendering.Engine to keep rendering dispatch separate from the GenServer lifecycle.

Summary

Functions

Transforms raw cells and writes them into a fresh ScreenBuffer.

Normalizes bare \n row joins in a rendered frame to \r\n.

Renders cells to any io_writer-backed message surface.

Renders cells to the LiveView backend via PubSub broadcast.

Renders cells to an SSH channel via an io_writer function.

Renders cells to a Telegram chat via an io_writer function.

Renders cells to the terminal backend with ANSI output.

Renders cells to the VSCode backend via stdio interface.

Functions

apply_cells_to_buffer(cells, state)

Transforms raw cells and writes them into a fresh ScreenBuffer.

A new buffer is created each frame so stale cells from previous views don't persist.

normalize_frame(output_string)

@spec normalize_frame(String.t()) :: String.t()

Normalizes bare \n row joins in a rendered frame to \r\n.

Raxol.Terminal.Renderer.render/1 joins rows with a bare \n, relying on the terminal driver to cook LF into CRLF. The driver runs prim_tty in raw output mode (see Raxol.Terminal.Driver.start_stdin_reader/1), where a bare \n only advances the line without returning to column 0 -- every row after the first drifts one column right, and combined with DECAWM autowrap on full-width rows this doubles the frame's vertical extent. \r\n is mode-independent: raw mode gets a real CR+LF, and cooked mode's LF->CRLF translation just turns it into a harmless \r\r\n.

render_to_io_writer(cells, state, view \\ nil)

@spec render_to_io_writer(list(), map(), term()) :: {:ok, map()}

Renders cells to any io_writer-backed message surface.

Applies the cells to the buffer and delivers %{buffer: buffer, view_tree: tree} to the state's io_writer callback; the session owning the writer formats it for its platform (e.g. the Telegram session extracts Button elements into inline keyboards). Used by the :telegram and :gateway environments.

render_to_liveview(cells, state, positioned_elements \\ [], a11y_map \\ %{})

Renders cells to the LiveView backend via PubSub broadcast.

When positioned_elements carry animation hints, generates a companion <style> block with CSS transitions and broadcasts it alongside the terminal HTML. LiveView receives {:render_update, html, animation_css}.

a11y_map is an id -> accessibility_node map (from Raxol.Core.Accessibility.Projection.by_id/1) that the bridge uses to emit per-element ARIA on spans whose data-raxol-id matches an entry.

render_to_ssh(cells, state)

Renders cells to an SSH channel via an io_writer function.

render_to_telegram(cells, state, view \\ nil)

@spec render_to_telegram(list(), map(), term()) :: {:ok, map()}

Renders cells to a Telegram chat via an io_writer function.

Delegates to render_to_io_writer/3; the Telegram session formats the delivered buffer + view tree into a message and keyboard.

render_to_terminal(cells, state)

Renders cells to the terminal backend with ANSI output.

render_to_vscode(cells, state)

Renders cells to the VSCode backend via stdio interface.