TermUI.Backend.Config (TermUI v1.0.0)
View SourceConfiguration handling for terminal backends.
This legacy backend-specific helper provides an interface for reading backend configuration
from the application environment. All configuration options have sensible
defaults. The primary TermUI.Runtime reads TermUI.Config instead; use that
module and runtime options for normal applications.
Configuration Options
Configure TermUI in your config/config.exs:
config :term_ui,
backend: :auto,
character_set: :unicode,
fallback_character_set: :ascii,
tty_opts: [line_mode: :full_redraw],
raw_opts: [alternate_screen: true]Backend Selection
The :backend option controls how the terminal backend is selected:
:auto(default) - Automatically detect the best backend using the selectorTermUI.Backend.Raw- Force raw mode backendTermUI.Backend.TTY- Force TTY mode backend
This legacy validator accepts only the three values above. The primary
TermUI.Runtime also accepts a custom backend module implementing
TermUI.Backend.
Character Set
The :character_set option specifies the preferred character set for
rendering box-drawing characters and other UI elements:
:unicode(default) - Use Unicode box-drawing characters:ascii- Use ASCII-only characters
The :fallback_character_set option specifies what to use when the
preferred character set is not available:
:ascii(default) - Fall back to ASCII:unicode- Fall back to Unicode (rarely useful)
Backend Options
The :tty_opts and :raw_opts options pass backend-specific configuration:
TTY Options:
:line_mode- Rendering mode (:full_redrawor:incremental)
Raw Options:
:alternate_screen- Whether to use alternate screen buffer (boolean)
Usage
# Get individual configuration values
backend = Config.get_backend()
char_set = Config.get_character_set()
# Get backend-specific options
tty_opts = Config.get_tty_opts()
raw_opts = Config.get_raw_opts()Validation
Use validate!/0 to check configuration at application startup:
# In your Application.start/2
TermUI.Backend.Config.validate!()Or use valid?/0 to check without raising:
if Config.valid?() do
# proceed
else
# handle invalid config
end
Summary
Functions
Returns the configured backend selection mode.
Returns the configured character set for UI rendering.
Returns the configured fallback character set.
Returns the configured raw backend options.
Returns the configured TTY backend options.
Returns the complete runtime configuration as a map.
Checks if the current configuration is valid.
Validates the current configuration, raising on errors.
Types
Functions
@spec get_backend() :: :auto | module()
Returns the configured backend selection mode.
Returns
:auto- Use automatic backend detection (default)- A module atom - Use the specified backend module
Examples
iex> Config.get_backend()
:auto
# With config: [backend: TermUI.Backend.Raw]
iex> Config.get_backend()
TermUI.Backend.Raw
@spec get_character_set() :: :unicode | :ascii
Returns the configured character set for UI rendering.
Returns
:unicode- Use Unicode characters (default):ascii- Use ASCII-only characters
Examples
iex> Config.get_character_set()
:unicode
# With config: [character_set: :ascii]
iex> Config.get_character_set()
:ascii
@spec get_fallback_character_set() :: :unicode | :ascii
Returns the configured fallback character set.
Used when the preferred character set is not available on the terminal.
Returns
:ascii- Fall back to ASCII (default):unicode- Fall back to Unicode
Examples
iex> Config.get_fallback_character_set()
:ascii
# With config: [fallback_character_set: :unicode]
iex> Config.get_fallback_character_set()
:unicode
@spec get_raw_opts() :: keyword()
Returns the configured raw backend options.
Returns
A keyword list of raw mode-specific options. Defaults to [alternate_screen: true].
Options
:alternate_screen- Whether to use the alternate screen buffertrue- Use alternate screen, restoring original on exit (default)false- Use main screen buffer
Examples
iex> Config.get_raw_opts()
[alternate_screen: true]
# With config: [raw_opts: [alternate_screen: false]]
iex> Config.get_raw_opts()
[alternate_screen: false]
@spec get_tty_opts() :: keyword()
Returns the configured TTY backend options.
Returns
A keyword list of TTY-specific options. Defaults to [line_mode: :full_redraw].
Options
:line_mode- Rendering mode:full_redraw- Redraw entire screen each frame (default):incremental- Only redraw changed lines
Examples
iex> Config.get_tty_opts()
[line_mode: :full_redraw]
# With config: [tty_opts: [line_mode: :incremental]]
iex> Config.get_tty_opts()
[line_mode: :incremental]
@spec runtime_config() :: config()
Returns the complete runtime configuration as a map.
This function validates the configuration before returning. If any
configuration value is invalid, an ArgumentError is raised.
Returns
A map containing all configuration values:
:backend- Backend selection mode:character_set- Preferred character set:fallback_character_set- Fallback character set:tty_opts- TTY backend options:raw_opts- Raw backend options
Raises
ArgumentErrorif any configuration value is invalid
Examples
iex> Config.runtime_config()
%{
backend: :auto,
character_set: :unicode,
fallback_character_set: :ascii,
tty_opts: [line_mode: :full_redraw],
raw_opts: [alternate_screen: true]
}
# With custom config
iex> Config.runtime_config()
%{
backend: TermUI.Backend.Raw,
character_set: :ascii,
fallback_character_set: :ascii,
tty_opts: [line_mode: :incremental],
raw_opts: [alternate_screen: false]
}
@spec valid?() :: boolean()
Checks if the current configuration is valid.
Returns true if all configuration values are valid, false otherwise.
Does not raise exceptions.
Returns
trueif configuration is validfalseif any configuration value is invalid
Examples
iex> Config.valid?()
true
# With invalid config: [backend: :invalid]
iex> Config.valid?()
false
@spec validate!() :: :ok
Validates the current configuration, raising on errors.
Checks that all configuration values are valid. Call this at application startup to catch configuration errors early.
Returns
:okif configuration is valid
Raises
ArgumentErrorwith a descriptive message if any configuration is invalid
Examples
iex> Config.validate!()
:ok
# With invalid config: [backend: :invalid]
iex> Config.validate!()
** (ArgumentError) invalid :backend value: :invalid