Raxol.UI.Terminal (Raxol v0.4.0)

View Source

A terminal UI rendering module for Raxol.

This module provides basic terminal rendering capabilities for Raxol applications, with support for accessibility features, internationalization, and color system integration.

Features

  • Terminal screen management (clearing, cursor positioning)
  • Text rendering with colors and styles
  • Input handling with support for keyboard shortcuts
  • Basic UI elements (boxes, lines, progress bars)
  • RTL rendering support
  • Accessibility-friendly output formatting

Summary

Functions

Clear the terminal screen.

Move the cursor to a specific position.

Print text with optional styling.

Print a box with content.

Print centered text.

Print a horizontal line spanning the terminal width.

Print text followed by a newline.

Read a keypress from the user.

Functions

clear()

@spec clear() :: :ok

Clear the terminal screen.

Examples

iex> Terminal.clear()
:ok

move_cursor(row, col)

@spec move_cursor(integer(), integer()) :: :ok

Move the cursor to a specific position.

Parameters

  • row - The row (1-indexed)
  • col - The column (1-indexed)

Examples

iex> Terminal.move_cursor(1, 1)
:ok

print(text, opts \\ [])

@spec print(
  String.t(),
  keyword()
) :: :ok

Print text with optional styling.

Options

  • :color - The text color (hex string or color name)
  • :background - The background color (hex string or color name)
  • :bold - Whether to display the text in bold (default: false)
  • :italic - Whether to display the text in italic (default: false)
  • :underline - Whether to underline the text (default: false)
  • :dim - Whether to display the text dimmed (default: false)
  • :blink - Whether to make the text blink (default: false)
  • :rtl - Whether to render the text right-to-left (default: from I18n)

Examples

iex> Terminal.print("Hello", color: "#FF0000", bold: true)
:ok

println(text \\ "", opts \\ [])

@spec println(
  String.t(),
  keyword()
) :: :ok

Print text followed by a newline.

Takes the same options as print/2.

Examples

iex> Terminal.println("Hello", color: "#FF0000", bold: true)
:ok

read_key(opts \\ [])

@spec read_key(keyword()) :: {:ok, term()} | :timeout | {:error, term()}

Read a keypress from the user.

Options

  • :timeout - Timeout in milliseconds (default: :infinity)

Returns

  • {:ok, key} - Where key is the key pressed
  • :timeout - If no key was pressed within the timeout
  • {:error, reason} - If an error occurred

Examples

iex> Terminal.read_key()
{:ok, :enter}

iex> Terminal.read_key(timeout: 1000)
:timeout