Raxol.UI.Terminal (Raxol v0.5.0)
View SourceA 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
@spec clear() :: :ok
Clear the terminal screen.
Examples
iex> Terminal.clear()
: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 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
Print a box with content.
Parameters
content
- The text content to display inside the boxopts
- Styling options
Options
:width
- Box width (default: content width + 4):height
- Box height (default: content lines + 2):border_color
- Color for the border:title
- Optional title for the box:title_color
- Color for the title:centered
- Whether to center the box horizontally (default: false)
Examples
iex> Terminal.print_box("Hello
World", title: "Greeting", border_color: "#0000FF")
:ok
Print centered text.
Options
Takes the same options as print/2
.
Examples
iex> Terminal.print_centered("Title", color: "#FF0000", bold: true)
:ok
@spec print_horizontal_line(keyword()) :: :ok
Print a horizontal line spanning the terminal width.
Options
:char
- The character to use for the line (default: "─")- Other options are passed to
print/2
Examples
iex> Terminal.print_horizontal_line(char: "-", color: "#CCCCCC")
: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 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