SimpleTerminal is a lightweight, TypeScript-based terminal emulator for web applications. It provides a simple and intuitive API for creating custom terminal commands and handling user input.
- Lightweight: A minimalistic terminal emulator without the overhead of larger libraries.
- TypeScript Support: Written in TypeScript for better type safety and developer experience.
- Custom Commands: Easily register and handle custom terminal commands.
- Simple API: A straightforward API that's easy to use and integrate into any web project.
Install SimpleTerminal using npm:
npm install simple-terminal
Or using yarn:
yarn add simple-terminal
Here’s a quick example to get you started with SimpleTerminal:
import SimpleTerminal from 'simple-terminal';
// Create a new terminal instance targeting the '#terminal' element
const terminal = new SimpleTerminal('#terminal');
// Register a simple 'echo' command
terminal.registerCommand('echo', (...args: string[]) => {
terminal.echo(args.join(' '));
});
// Initialize the terminal (typically done when the DOM is fully loaded)
document.addEventListener('DOMContentLoaded', () => {
terminal.init();
});
Make sure your HTML includes an element with the id terminal:
<div id="terminal"></div>
registerCommand(name: string, func: CommandFunction): void
Register a new command with the terminal.
echo(message: string): void
Display a message in the terminal.
Contributions are welcome! Please feel free to submit issues, fork the repository and send pull requests!