Terminal System Architecture
TerminalOS Class
The main terminal controller class manages all terminal operations.
Initialization Flow
sequenceDiagram
participant User
participant TerminalOS
participant xterm
participant Filesystem
participant EcmaOS
participant BootSequence
User->>TerminalOS: new TerminalOS('terminal')
TerminalOS->>xterm: Initialize xterm.js
TerminalOS->>xterm: Load addons (Fit, WebLinks, etc.)
TerminalOS->>Filesystem: new VirtualFileSystem()
TerminalOS->>Filesystem: Load Jekyll data
TerminalOS->>EcmaOS: initEcmaOS() (async)
TerminalOS->>BootSequence: Start boot animation
BootSequence->>TerminalOS: Boot complete callback
TerminalOS->>User: Show welcome, prompt ready
Command Execution Flow
- User types command
handleCommand() parses input
- Switch statement routes to handler
- Local app or EcmaOS delegation
- Output written to terminal
- Prompt refreshed
State Management
- currentPath: Current working directory
- currentUser: Active user (guest/root)
- isRoot: Root access flag
- commandHistory: Command history array
- sessionStartTime: Uptime calculation
xterm.js Integration
Addons Loaded
- FitAddon: Auto-resize terminal to container
- WebLinksAddon: Clickable URLs
- SearchAddon: Terminal content search (Ctrl+F)
- Unicode11Addon: Enhanced Unicode support
- SerializeAddon: Terminal state serialization
- ImageAddon: Image display support
- WebglAddon/CanvasAddon: High-performance rendering
Terminal Configuration
- Font: Monaco, Menlo, Ubuntu Mono
- Font size: 12px mobile, 14px desktop
- Scrollback: 1000 lines
- Theme: Matrix green (default)
Key Events
- Enter: Execute command
- Backspace: Delete character
- Arrow Up/Down: Command history
- Tab: Command/file completion
- Ctrl+F: Search terminal content
Tab Completion
- Parse input to get command/argument
- If command: match against command list
- If argument: match against filesystem listing
- Show matches or complete if unique
Boot Sequence
Simulated computer boot process:
- BIOS: POST checks, hardware detection
- Boot Loader: GRUB-style interface
- Kernel: Loading animation
- Init: Service startup
- Ready: Welcome message, prompt
Press ESC to skip boot sequence.