TermUI (TermUI v1.0.0)

View Source

TermUI - A direct-mode Terminal UI framework for Elixir/BEAM.

TermUI.Runtime and TermUI.App are the normal application entry points. This module exposes lower-level local terminal conveniences plus IEx-mode detection; init/0 always attempts native Raw mode.

Summary

Functions

Returns whether the application is running inside IEx.

Enables raw mode and sets up the terminal for TUI operation.

Returns the current execution mode.

Restores the terminal to its original state.

Gets the current terminal size.

Functions

iex_mode?()

@spec iex_mode?() :: boolean()

Returns whether the application is running inside IEx.

This function checks multiple indicators to determine if the code is executing within an IEx session:

  1. Whether the IEx module is loaded
  2. Whether the current process is an IEx evaluator
  3. Whether the TermUI runtime inherited IEx mode from its caller
  4. Configuration overrides (config or environment variable)

The result can be overridden by:

  • Setting config :term_ui, iex_compatible: true in config
  • Setting the TERM_UI_IEX_MODE environment variable to "true" or "false"

Examples

iex> TermUI.iex_mode?()
true

# In a standalone script:
TermUI.iex_mode?()
false

Configuration

To force IEx-compatible mode (useful for testing):

# config/config.exs
config :term_ui, iex_compatible: true

To override via environment variable:

export TERM_UI_IEX_MODE=true

init()

@spec init() :: {:ok, TermUI.Terminal.State.t()} | {:error, term()}

Enables raw mode and sets up the terminal for TUI operation.

This is a convenience function that:

  1. Starts the Terminal GenServer if needed
  2. Enables raw mode
  3. Enters the alternate screen
  4. Hides the cursor

Returns {:ok, state} on success or {:error, reason} on failure.

running_mode()

@spec running_mode() :: :iex | :standalone

Returns the current execution mode.

Returns :iex if running inside IEx, :standalone otherwise.

Examples

iex> TermUI.running_mode()
:iex

# In a standalone script:
TermUI.running_mode()
:standalone

shutdown()

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

Restores the terminal to its original state.

This is a convenience function that performs complete terminal restoration.

size()

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

Gets the current terminal size.

Returns {:ok, {rows, cols}} or {:error, reason}.