jQuery Terminal Emulator – web based terminal

jQuery Terminal Emulator or just command line interpreter plugin.

jQuery Terminal Emulator – terminal on the web

jQuery Terminal Emulator is a plugin for creating command line interpreters in your applications. It can automatically call JSON-RPC service when a user types commands or you can provide you own function in which you can parse user commands. It’s ideal if you want to provide additional functionality for power users. It can also be used to debug your application.

You can use this JavaScript library to create web based terminal on any website.

We can create an interpreter for your JSON-RPC service with one line of code (just use url as first argument). There is a support for authentication (you can provide functions when users enter login and password or if you use JSON-RPC it can automatically call login function on the server and pass token to all functions). And much more.

jQuery Terminal Emulator - web based terminal!
jQuery Terminal Emulator – web based terminal!

Setup

npm install jquery.terminal

Samples

This is code that uses low level function, that gives you full control of the commands, just pass anything that the user types into a function.

jQuery(function($, undefined) {
    $('#term_demo').terminal(function(command) {
        if (command !== '') {
            var result = window.eval(command);
            if (result != undefined) {
                this.echo(String(result));
            }
        }
    }, {
        greetings: 'Javascript Interpreter',
        name: 'js_demo',
        height: 200,
        width: 450,
        prompt: 'js> '
    });
});

Here is a higher level call, using an object as an interpreter, By default the terminal will parse commands that a user types and replace number like strings with real numbers regex with regexes and process escape characters in double quoted strings.

jQuery(function($, undefined) {
    $('#term_demo').terminal({
        add: function(a, b) {
            this.echo(a + b);
        },
        foo: 'foo.php',
        bar: {
            sub: function(a, b) {
                this.echo(a - b);
            }
        }
    }, {
        height: 200,
        width: 450,
        prompt: 'demo> '
    });
});

Command foo will execute json-rpc from foo.php file. You can create JSON-RPC interpreter with authentication in just one line:

$('#term_demo').terminal('service.php', {login: true});

License: MIT

Homepage

https://terminal.jcubic.pl

GitHub

https://github.com/jcubic/jquery.terminal

See also

Terminal dashboards with ASCII art and JavaScript

JavaScript format input while typing – Cleave.js

jQuery fancy input box with amazing CSS3 effects

Open MCT – a web based mission control framework. From NASA!

Enjoy!