Skip to content
/ cli Public

A command-line interpreter (aka console, terminal) GUI element in plain JavaScript for any web application. Seamlessly integrate your own commands. Fully customizable.

License

Notifications You must be signed in to change notification settings

chzager/cli

Repository files navigation

A command line interpreter (aka console, terminal) for your web applications

The CLI (as for "command line interpreter") adds an element to your web application's GUI for text-based user interaction via a set of commands. It is lightweight, fully customizable and the integration of your own commands is a cakewalk.

FileSize Standalone License

Table of Contents

Installation

No installation required. Just link the source (i.e. from JsDelivr):

<script src="https://cdn.jsdelivr.net/gh/chzager/cli/cli.min.js"></script>

The type definitions are avaliable at https://chzager.github.io/cli/cli.d.ts.

Usage

Usage doesn't get any easier: Define your commands and instantiate a CommandLineInterpreter object.

const myCommands = {
	"hello": (cli) => {
		cli.writeLn("Hello, world!");
	},
};
new CommandLineInterpreter(myCommands);

Let's get more interactive:

const myCommands = {
	"hello": (cli) => {
		return new Promise((resolve) => {
			cli.readLn("What's your name? ").then((name) => {
				cli.writeLn(`Hello, ${name}!`);
				resolve();
			});
		});
	},
};

About

A command-line interpreter (aka console, terminal) GUI element in plain JavaScript for any web application. Seamlessly integrate your own commands. Fully customizable.

Topics

Resources

License

Stars

Watchers

Forks