TermUI.Platform (TermUI v0.2.0)

View Source

Platform detection and abstraction for cross-platform terminal support.

Provides unified API for platform-specific operations, automatically selecting the appropriate implementation for the current OS.

Summary

Functions

Returns platform-specific information as a map.

Returns true if running on Linux (native, not WSL).

Returns true if running on macOS.

Returns the OS version as a tuple.

Returns the current platform identifier.

Returns true if the platform supports the given feature.

Returns the terminal size as {rows, cols}.

Returns true if running on Unix (Linux, macOS, FreeBSD).

Returns true if running on Windows.

Returns true if running in Windows Subsystem for Linux (WSL).

Types

platform()

@type platform() :: :linux | :macos | :windows | :freebsd | :unknown

version()

@type version() :: {non_neg_integer(), non_neg_integer(), non_neg_integer()} | nil

Functions

info()

@spec info() :: map()

Returns platform-specific information as a map.

linux?()

@spec linux?() :: boolean()

Returns true if running on Linux (native, not WSL).

macos?()

@spec macos?() :: boolean()

Returns true if running on macOS.

os_version()

@spec os_version() :: version()

Returns the OS version as a tuple.

Examples

iex> TermUI.Platform.os_version()
{5, 15, 0}

iex> TermUI.Platform.os_version()
{14, 0, 0}

platform()

@spec platform() :: platform()

Returns the current platform identifier.

Examples

iex> TermUI.Platform.platform()
:linux

iex> TermUI.Platform.platform()
:macos

supports_feature?(feature)

@spec supports_feature?(atom()) :: boolean()

Returns true if the platform supports the given feature.

Features

  • :signals - POSIX signal handling
  • :pty - Pseudo-terminal support
  • :terminfo - Terminfo database
  • :vt_sequences - VT escape sequences

terminal_size()

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

Returns the terminal size as {rows, cols}.

Falls back to default {24, 80} if unable to detect.

unix?()

@spec unix?() :: boolean()

Returns true if running on Unix (Linux, macOS, FreeBSD).

windows?()

@spec windows?() :: boolean()

Returns true if running on Windows.

wsl?()

@spec wsl?() :: boolean()

Returns true if running in Windows Subsystem for Linux (WSL).