Raxol.Terminal.TerminalServer (Raxol v2.0.1)
View SourceUnified terminal management system that consolidates all terminal operations.
This module serves as the central coordination point for all terminal functionality, replacing the fragmented manager pattern with a single, cohesive system that handles:
- Terminal emulation and state management
- Command processing and routing
- Session management and lifecycle
- Buffer operations and memory management
- Event handling and notifications
- Configuration and preferences
- Plugin integration and extensions
- Performance monitoring and optimization
Design Principles
- Single Responsibility: Each operation has a clear, focused purpose
- Unified Interface: All terminal operations go through this manager
- State Consistency: Centralized state management prevents conflicts
- Performance: Optimized for high-throughput terminal operations
- Extensibility: Plugin system for custom functionality
- Reliability: Comprehensive error handling and recovery
Architecture Overview
UnifiedManager
├── Command Processing (CSIHandler)
├── Session Management (SessionManager)
├── Buffer Management (AdvancedManager)
├── State Management (StateManager)
├── Event System (EventManager)
├── Plugin System (PluginManager)
└── Performance Monitor (MetricsManager)Usage
# Start the unified manager
{:ok, manager} = UnifiedManager.start_link()
# Create a terminal session
{:ok, session} = UnifiedManager.create_session(manager, user_id, config)
# Process terminal input
{:ok, updated_session} = UnifiedManager.process_input(manager, session_id, input)
# Get terminal output
{:ok, output} = UnifiedManager.get_output(manager, session_id)
# Handle terminal commands
{:ok, session} = UnifiedManager.execute_command(manager, session_id, command)
Summary
Functions
Returns a specification to start this module under a supervisor.
Performs cleanup operations (expired sessions, memory optimization).
Creates a new terminal session.
Executes a specific terminal command.
Gets overall manager statistics and health information.
Gets the current terminal output for rendering.
Gets session information and statistics.
Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_cast/2.
Lists all active sessions.
Processes terminal input (keyboard input, paste, etc.).
Resizes a terminal session.
Terminates a terminal session.
Types
@type session_config() :: %{ width: pos_integer(), height: pos_integer(), scrollback_lines: pos_integer(), color_mode: :ansi | :xterm | :truecolor, features: [atom()] }
@type session_id() :: String.t()
@type terminal_output() :: String.t()
@type user_id() :: String.t()
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec cleanup(GenServer.server()) :: :ok
Performs cleanup operations (expired sessions, memory optimization).
@spec create_session(GenServer.server(), user_id(), session_config()) :: {:ok, session_id()} | {:error, term()}
Creates a new terminal session.
@spec execute_command(GenServer.server(), session_id(), term()) :: {:ok, term()} | {:error, term()}
Executes a specific terminal command.
@spec get_manager_stats(GenServer.server()) :: {:ok, map()}
Gets overall manager statistics and health information.
@spec get_output(GenServer.server(), session_id()) :: {:ok, terminal_output()} | {:error, term()}
Gets the current terminal output for rendering.
@spec get_session_info(GenServer.server(), session_id()) :: {:ok, map()} | {:error, term()}
Gets session information and statistics.
Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_cast/2.
@spec list_sessions(GenServer.server()) :: {:ok, [map()]}
Lists all active sessions.
@spec process_input(GenServer.server(), session_id(), terminal_input()) :: {:ok, terminal_output()} | {:error, term()}
Processes terminal input (keyboard input, paste, etc.).
@spec resize_session( GenServer.server(), session_id(), pos_integer(), pos_integer() ) :: :ok | {:error, term()}
Resizes a terminal session.
@spec terminate_session(GenServer.server(), session_id()) :: :ok | {:error, term()}
Terminates a terminal session.