Raxol.Core (Raxol v2.0.1)
View SourceRaxol 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
Functions
@spec accessibility_enabled?() :: boolean()
Checks if accessibility features are enabled.
Returns
true- Accessibility is enabledfalse- Accessibility is disabled
Example
case Raxol.Core.accessibility_enabled?() do
true -> # Enable screen reader support
false -> # Use default behavior
end
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: %{...}}}
@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()
Gets a user preference value.
Parameters
key- Preference keydefault- Default value if not set
Returns
The preference value or default
Example
theme = Raxol.Core.get_preference(:theme, :default)
@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}}
Gets the current theme configuration.
Returns
{:ok, theme}- Current theme configuration{:error, reason}- Failed to get theme
Example
{:ok, theme} = Raxol.Core.get_theme()
@spec get_version() :: String.t()
Gets the Raxol framework version.
Returns
The version string
Example
version = Raxol.Core.get_version()
# Returns: "1.0.0"
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]}
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])
@spec new() :: %{plugins: %{}, config: %{}, state: %{}}
Creates a new Core instance with default configuration.
@spec record_metric(metric_name(), metric_value(), metric_tags()) :: :ok
Records a performance metric.
Parameters
name- Metric namevalue- Metric valuetags- Optional tags for the metric
Example
Raxol.Core.record_metric("render.time", 15.5, [component: "button"])
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)
Sets a user preference value.
Parameters
key- Preference keyvalue- Preference value
Returns
:ok- Preference set successfully{:error, reason}- Failed to set preference
Example
:ok = Raxol.Core.set_preference(:theme, :dark)
@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)
@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
app_module- The module implementingRaxol.Core.Runtime.Applicationbehaviouroptions- Configuration options for the application
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]
])
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)
@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)