View on GitHub

CWP Open Terminal Emulator

Official documentation for the CWP Open Terminal Emulator.

API Reference

This document provides a detailed reference for the core API of the CWP Open Terminal Emulator, designed for third-party developers looking to integrate, extend, or build upon the library.


Core Architecture

The terminal is composed of several key modules that work together:

  1. core: Contains the primary, top-level classes that orchestrate all operations. CentralTerminal is the main entry point, TerminalUI manages the DOM, and terminal.js provides core utilities.
  2. boot: Manages the boot sequence. BootHandler runs all the checks, BootCheck represents a single check, and BootCheckRegistry is where you can add your own custom checks.
  3. vfs: The Virtual File System. VOS provides the main API, while VFile and VDirectory represent files and directories.
  4. addons: The addon system. Addon is the base class for creating new addons, and AddonExecutor manages their lifecycle.

CentralTerminal

Source: src/core/central-terminal.js

The main class that you will instantiate. It binds everything together.

constructor(containerOrUI)

Creates a new terminal instance. The constructor is flexible:

Key Properties

Methods


TerminalUI

Source: src/core/terminal-ui.js

Handles all interaction with the DOM. You can let CentralTerminal create it for you or instantiate it yourself for more complex integrations.

constructor(containerSelector, onCommand, onAutocomplete, options)


VOS (Virtual Operating System)

Source: src/vfs/vos.js

Provides the API for interacting with the virtual file system. An instance is available at CentralTerminal.vOS.

File & Directory Operations

Path Manipulation


Addon System

Addons are self-contained modules that can be launched from the main terminal. When an addon is active, it takes over the input loop, allowing for a custom set of commands.

Addon (Base Class)

Source: src/addons/addon.js

All addons must extend the Addon base class.

constructor(options)

The constructor accepts an options object with two key properties:

Lifecycle Methods

Input Handling

Addon-Specific Commands

Example: Registering Different Addon Types

import { CentralTerminal } from '''@clockworksproduction-studio/cwp-open-terminal-emulator/core/central-terminal.js''';
import { Addon } from '''@clockworksproduction-studio/cwp-open-terminal-emulator/addons/addon.js''';

// 1. A standard addon launched with 'run notepad'
class NotepadAddon extends Addon {
    constructor() {
        super({ name: 'notepad' }); // isTopLevel defaults to false
    }
    // ... implementation
}

// 2. A top-level addon launched with 'myeditor'
class EditorAddon extends Addon {
    constructor() {
        super({ name: 'myeditor', isTopLevel: true });
    }
    // ... implementation
}

// Registering the addons
const term = new CentralTerminal('#terminal-container');
term.registerAddon(new NotepadAddon());
term.registerAddon(new EditorAddon());

Boot Sequence

The boot sequence runs diagnostics before the terminal starts. You can add your own checks.

BootCheck

Source: src/boot/boot-check.js

This class represents a single check.

BootCheckRegistry

Source: src/boot/boot-check-registry.js

Accessed via CentralTerminal.bootRegistry.

Example: Adding a Custom Boot Check

import { CentralTerminal } from '''@clockworksproduction-studio/cwp-open-terminal-emulator/core/central-terminal.js''';
import { BootCheck } from '''@clockworksproduction-studio/cwp-open-terminal-emulator/boot/boot-check.js''';

const term = new CentralTerminal('#terminal-container');

const myCheck = new BootCheck(
  'Checking for custom API',
  async () => {
    // Replace with a real check
    const response = await fetch('https://api.example.com/status');
    return response.ok;
  }
);

term.bootRegistry.add(myCheck);

term.boot(); // The custom check will run on boot