Raxol.Terminal.TerminalUtils (Raxol v0.5.0)
View SourceUtility functions for terminal operations, providing cross-platform and consistent handling of terminal capabilities and dimensions.
Summary
Functions
Returns the current cursor position, if available.
Detects terminal dimensions using a multi-layered approach
Detects terminal dimensions using :io.columns and :io.rows. Returns {:ok, width, height} or {:error, reason}.
Detects terminal dimensions using the stty size command. Returns {:ok, width, height} or {:error, reason}.
Detects terminal dimensions using the termbox2 NIF. Returns {:ok, width, height} or {:error, reason}.
Creates a bounds map with dimensions, starting at origin (0,0)
Gets terminal dimensions and returns them in a map format.
Returns true if the current process is attached to a real TTY device.
Functions
@spec cursor_position() :: {:ok, {pos_integer(), pos_integer()}} | {:error, term()}
Returns the current cursor position, if available.
@spec detect_dimensions() :: {pos_integer(), pos_integer()}
Detects terminal dimensions using a multi-layered approach:
- Uses
:io.columns
and:io.rows
(preferred) - Falls back to termbox2 NIF if
:io
methods fail - Falls back to
stty size
system command if needed - Finally uses hardcoded default dimensions if all else fails
Returns a tuple of {width, height}.
@spec detect_with_io(atom()) :: {:ok, pos_integer(), pos_integer()} | {:error, term()}
Detects terminal dimensions using :io.columns and :io.rows. Returns {:ok, width, height} or {:error, reason}.
@spec detect_with_stty() :: {:ok, pos_integer(), pos_integer()} | {:error, term()}
Detects terminal dimensions using the stty size command. Returns {:ok, width, height} or {:error, reason}.
@spec detect_with_termbox() :: {:ok, pos_integer(), pos_integer()} | {:error, term()}
Detects terminal dimensions using the termbox2 NIF. Returns {:ok, width, height} or {:error, reason}.
@spec get_bounds_map() :: %{x: 0, y: 0, width: pos_integer(), height: pos_integer()}
Creates a bounds map with dimensions, starting at origin (0,0)
@spec get_dimensions_map() :: %{width: pos_integer(), height: pos_integer()}
Gets terminal dimensions and returns them in a map format.
@spec real_tty?() :: boolean()
Returns true if the current process is attached to a real TTY device.