Raxol.Terminal.Integration.Renderer (Raxol Terminal v2.8.0)

Copy Markdown View Source

Handles terminal output rendering and display management using Termbox2.

:termbox2_nif.tb_set_cursor/2, tb_clear/0 and tb_present/0 discard termbox's status and always return :ok, so the calls built on them (clear_screen/1, move_cursor/3, showing the cursor with set_cursor_visibility/2, and the cursor and present steps of render/1) cannot report a termbox failure: they return :ok even when termbox rejected the call, for example before init_terminal/0.

Hiding the cursor uses :termbox2_nif.tb_hide_cursor/0, which does return termbox's status, so a rejected hide is reported. While the cursor is hidden, render/1 leaves it hidden instead of placing it.

Summary

Functions

Clears the terminal screen (specifically, the back buffer) and presents it. Returns :ok; termbox failures are not reported (see the moduledoc).

Gets the current terminal dimensions. Returns {:ok, {width, height}} or {:error, :dimensions_unavailable}. Note: termbox2 width/height C functions return int, not status codes. A negative value might indicate an error (e.g., not initialized).

Gets the terminal title.

Initializes the underlying terminal system. Must be called before other rendering functions. Returns :ok or {:error, reason}.

Moves the hardware cursor to a specific position on the screen and presents it. Returns :ok; termbox failures are not reported (see the moduledoc). Coordinates that are not 32-bit integers raise ArgumentError.

Creates a new renderer with the given options.

Renders the current terminal state to the screen. Returns :ok or {:error, reason}.

Resets the renderer configuration to defaults.

Resizes the renderer to the given dimensions.

Sets a specific configuration value.

Shows or hides the cursor and records :cursor_visible in the config.

Sets the terminal title.

Shuts down the underlying terminal system. Must be called to restore terminal state. Returns :ok or {:error, reason}.

Updates the renderer configuration.

Functions

clear_screen(state)

Clears the terminal screen (specifically, the back buffer) and presents it. Returns :ok; termbox failures are not reported (see the moduledoc).

get_dimensions()

Gets the current terminal dimensions. Returns {:ok, {width, height}} or {:error, :dimensions_unavailable}. Note: termbox2 width/height C functions return int, not status codes. A negative value might indicate an error (e.g., not initialized).

get_title(state)

Gets the terminal title.

init_terminal()

Initializes the underlying terminal system. Must be called before other rendering functions. Returns :ok or {:error, reason}.

move_cursor(state, x, y)

Moves the hardware cursor to a specific position on the screen and presents it. Returns :ok; termbox failures are not reported (see the moduledoc). Coordinates that are not 32-bit integers raise ArgumentError.

new(opts \\ [])

Creates a new renderer with the given options.

render(state)

Renders the current terminal state to the screen. Returns :ok or {:error, reason}.

reset_config(state)

Resets the renderer configuration to defaults.

resize(state, width, height)

Resizes the renderer to the given dimensions.

set_config_value(state, key, value)

Sets a specific configuration value.

set_cursor_visibility(state, visible)

Shows or hides the cursor and records :cursor_visible in the config.

Showing places the cursor at the cursor manager's position. If termbox rejects a hide, the error is logged and the state is returned unchanged.

set_title(state, title)

Sets the terminal title.

shutdown_terminal()

Shuts down the underlying terminal system. Must be called to restore terminal state. Returns :ok or {:error, reason}.

update_config(state, config)

Updates the renderer configuration.