Raxol.Terminal.TerminalUtils (Raxol v0.4.0)

View Source

Utility 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

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

cursor_position()

@spec cursor_position() :: {:ok, {pos_integer(), pos_integer()}} | {:error, term()}

Returns the current cursor position, if available.

detect_dimensions()

@spec detect_dimensions() :: {pos_integer(), pos_integer()}

Detects terminal dimensions using a multi-layered approach:

  1. Uses :io.columns and :io.rows (preferred)
  2. Falls back to rrex_termbox v2.0.1 NIF if :io methods fail
  3. Falls back to stty size system command if needed
  4. Finally uses hardcoded default dimensions if all else fails

Returns a tuple of {width, height}.

get_bounds_map()

@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)

get_dimensions_map()

@spec get_dimensions_map() :: %{width: pos_integer(), height: pos_integer()}

Gets terminal dimensions and returns them in a map format.

real_tty?()

Returns true if the current process is attached to a real TTY device.