Raxol.Core (Raxol v2.0.1)

View Source

Raxol Core - The main entry point and coordination layer for the Raxol framework.

This module provides a unified API for:

  • Application lifecycle management
  • Runtime initialization and configuration
  • Core system coordination
  • Plugin management
  • Event system access
  • Performance monitoring
  • Configuration management

Quick Start

# Start a simple application
{:ok, pid} = Raxol.Core.start_application(MyApp)

# Start with custom options
{:ok, pid} = Raxol.Core.start_application(MyApp, [
  title: "My App",
  fps: 30,
  debug: true,
  plugins: [:accessibility, :performance]
])

# Stop the application
Raxol.Core.stop_application(pid)

Architecture

Raxol.Core coordinates several subsystems:

  • Runtime: Application lifecycle and state management
  • Events: Event dispatching and subscription system
  • Plugins: Plugin discovery, loading, and lifecycle management
  • Renderer: UI rendering and layout management
  • Terminal: Terminal interaction and input handling
  • Performance: Metrics collection and optimization

Summary

Functions

Checks if accessibility features are enabled.

Gets the current status of a Raxol application.

Gets performance statistics.

Gets a user preference value.

Gets system information about the current Raxol environment.

Gets the current theme configuration.

Gets the Raxol framework version.

Lists all loaded plugins.

Loads a plugin into the current application.

Creates a new Core instance with default configuration.

Records a performance metric.

Enables or disables accessibility features.

Sets a user preference value.

Sets the current theme.

Starts a Raxol application with the given module and options.

Stops a running Raxol application.

Unloads a plugin from the current application.

Types

app_module()

@type app_module() :: module()

app_options()

@type app_options() :: keyword()

metric_name()

@type metric_name() :: String.t()

metric_tags()

@type metric_tags() :: [{atom(), any()}]

metric_value()

@type metric_value() :: number()

plugin_id()

@type plugin_id() :: atom() | String.t()

runtime_state()

@type runtime_state() :: map()

Functions

accessibility_enabled?()

@spec accessibility_enabled?() :: boolean()

Checks if accessibility features are enabled.

Returns

  • true - Accessibility is enabled
  • false - Accessibility is disabled

Example

case Raxol.Core.accessibility_enabled?() do
  true -> # Enable screen reader support
  false -> # Use default behavior
end

get_application_status(pid_or_name)

@spec get_application_status(pid() | atom()) :: {:ok, map()} | {:error, term()}

Gets the current status of a Raxol application.

Parameters

  • pid_or_name - PID or registered name of the application

Returns

  • {:ok, status} - Application status information
  • {:error, reason} - Failed to get status

Example

{:ok, status} = Raxol.Core.get_application_status(app_pid)
# Returns: {:ok, %{state: :running, uptime: 1234, model: %{...}}}

get_performance_stats()

@spec get_performance_stats() :: {:ok, map()}

Gets performance statistics.

Returns

  • {:ok, stats} - Performance statistics
  • {:error, reason} - Failed to get statistics

Example

{:ok, stats} = Raxol.Core.get_performance_stats()

get_preference(key, default \\ nil)

@spec get_preference(atom(), any()) :: any()

Gets a user preference value.

Parameters

  • key - Preference key
  • default - Default value if not set

Returns

The preference value or default

Example

theme = Raxol.Core.get_preference(:theme, :default)

get_system_info()

@spec get_system_info() ::
  {:ok,
   %{
     accessibility: boolean(),
     colors: 0 | 256,
     performance: map(),
     terminal: binary(),
     version: binary()
   }}

Gets system information about the current Raxol environment.

Returns

  • {:ok, info} - System information
  • {:error, reason} - Failed to get system info

Example

{:ok, info} = Raxol.Core.get_system_info()
# Returns: {:ok, %{version: "1.0.0", terminal: "xterm", colors: 256}}

get_theme()

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

Gets the current theme configuration.

Returns

  • {:ok, theme} - Current theme configuration
  • {:error, reason} - Failed to get theme

Example

{:ok, theme} = Raxol.Core.get_theme()

get_version()

@spec get_version() :: String.t()

Gets the Raxol framework version.

Returns

The version string

Example

version = Raxol.Core.get_version()
# Returns: "1.0.0"

list_plugins()

@spec list_plugins() :: {:ok, [plugin_id()]} | {:error, term()}

Lists all loaded plugins.

Returns

  • {:ok, plugins} - List of loaded plugins
  • {:error, reason} - Failed to get plugin list

Example

{:ok, plugins} = Raxol.Core.list_plugins()
# Returns: {:ok, [:accessibility, :performance, :themes]}

load_plugin(plugin_id, options \\ [])

@spec load_plugin(
  plugin_id(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Loads a plugin into the current application.

Parameters

  • plugin_id - Plugin identifier (module name or string)
  • options - Plugin-specific options

Returns

  • {:ok, plugin_info} - Plugin loaded successfully
  • {:error, reason} - Failed to load plugin

Example

{:ok, plugin_info} = Raxol.Core.load_plugin(:accessibility, [enabled: true])

new()

@spec new() :: %{plugins: %{}, config: %{}, state: %{}}

Creates a new Core instance with default configuration.

record_metric(name, value, tags \\ [])

@spec record_metric(metric_name(), metric_value(), metric_tags()) :: :ok

Records a performance metric.

Parameters

  • name - Metric name
  • value - Metric value
  • tags - Optional tags for the metric

Example

Raxol.Core.record_metric("render.time", 15.5, [component: "button"])

set_accessibility_enabled(enabled)

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

Enables or disables accessibility features.

Parameters

  • enabled - Whether to enable accessibility

Returns

  • :ok - Accessibility setting updated
  • {:error, reason} - Failed to update setting

Example

:ok = Raxol.Core.set_accessibility_enabled(true)

set_preference(key, value)

@spec set_preference(atom(), any()) :: :ok | {:error, term()}

Sets a user preference value.

Parameters

  • key - Preference key
  • value - Preference value

Returns

  • :ok - Preference set successfully
  • {:error, reason} - Failed to set preference

Example

:ok = Raxol.Core.set_preference(:theme, :dark)

set_theme(theme_id)

@spec set_theme(atom()) :: :ok | {:error, :theme_not_found}

Sets the current theme.

Parameters

  • theme_id - Theme identifier

Returns

  • :ok - Theme set successfully
  • {:error, reason} - Failed to set theme

Example

:ok = Raxol.Core.set_theme(:dark)

start_application(app_module, options \\ [])

@spec start_application(app_module(), app_options()) ::
  {:ok, pid()} | {:error, term()}

Starts a Raxol application with the given module and options.

This is the primary entry point for starting Raxol applications. It handles the complete initialization process including runtime setup, plugin loading, and application startup.

Parameters

Options

  • :title - Application title (default: derived from module name)
  • :fps - Target frames per second (default: 60)
  • :debug - Enable debug mode (default: false)
  • :width - Terminal width (default: auto-detected)
  • :height - Terminal height (default: auto-detected)
  • :plugins - List of plugins to load (default: [])
  • :theme - Theme configuration (default: :default)
  • :accessibility - Accessibility options (default: enabled)
  • :performance - Performance monitoring options (default: enabled)

Returns

  • {:ok, pid} - Application started successfully
  • {:error, reason} - Failed to start application

Example

defmodule MyApp do
  use Raxol.Core.Runtime.Application

  def init(_opts), do: %{count: 0}
  def update(:increment, model), do: {%{model | count: model.count + 1}, []}
  def view(model), do: view(do: text("Count: #{model.count}"))
end

{:ok, pid} = Raxol.Core.start_application(MyApp, [
  title: "Counter App",
  fps: 30,
  plugins: [:accessibility]
])

stop_application(pid_or_name)

@spec stop_application(pid() | atom()) :: :ok

Stops a running Raxol application.

Parameters

  • pid_or_name - PID or registered name of the application

Returns

  • :ok - Application stopped successfully
  • {:error, reason} - Failed to stop application

Example

Raxol.Core.stop_application(app_pid)

unload_plugin(plugin_id)

@spec unload_plugin(plugin_id()) :: :ok

Unloads a plugin from the current application.

Parameters

  • plugin_id - Plugin identifier

Returns

  • :ok - Plugin unloaded successfully
  • {:error, reason} - Failed to unload plugin

Example

:ok = Raxol.Core.unload_plugin(:accessibility)