TermUI (TermUI v1.0.0)
View SourceTermUI - 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
@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:
- Whether the IEx module is loaded
- Whether the current process is an IEx evaluator
- Whether the TermUI runtime inherited IEx mode from its caller
- Configuration overrides (config or environment variable)
The result can be overridden by:
- Setting
config :term_ui, iex_compatible: truein config - Setting the
TERM_UI_IEX_MODEenvironment variable to"true"or"false"
Examples
iex> TermUI.iex_mode?()
true
# In a standalone script:
TermUI.iex_mode?()
falseConfiguration
To force IEx-compatible mode (useful for testing):
# config/config.exs
config :term_ui, iex_compatible: trueTo override via environment variable:
export TERM_UI_IEX_MODE=true
@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:
- Starts the Terminal GenServer if needed
- Enables raw mode
- Enters the alternate screen
- Hides the cursor
Returns {:ok, state} on success or {:error, reason} on failure.
@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
@spec shutdown() :: :ok | {:error, term()}
Restores the terminal to its original state.
This is a convenience function that performs complete terminal restoration.
@spec size() :: {:ok, {pos_integer(), pos_integer()}} | {:error, term()}
Gets the current terminal size.
Returns {:ok, {rows, cols}} or {:error, reason}.