Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jcubic/jquery.terminal
jQuery Terminal Emulator - JavaScript library for creating web-based terminals with custom commands
https://github.com/jcubic/jquery.terminal
ansi-art command-line console fake-termial-website fake-terminal fake-web-terminal hactoberfest interpreter interpreters javascript jquery-terminal json-rpc parse-commands shell terminal terminal-emulators terminal-style-website tui web-terminal
Last synced: 14 days ago
JSON representation
jQuery Terminal Emulator - JavaScript library for creating web-based terminals with custom commands
- Host: GitHub
- URL: https://github.com/jcubic/jquery.terminal
- Owner: jcubic
- License: mit
- Created: 2011-02-24T12:58:32.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2024-10-08T20:30:19.000Z (about 1 month ago)
- Last Synced: 2024-10-10T08:04:56.581Z (about 1 month ago)
- Topics: ansi-art, command-line, console, fake-termial-website, fake-terminal, fake-web-terminal, hactoberfest, interpreter, interpreters, javascript, jquery-terminal, json-rpc, parse-commands, shell, terminal, terminal-emulators, terminal-style-website, tui, web-terminal
- Language: JavaScript
- Homepage: https://terminal.jcubic.pl
- Size: 34.3 MB
- Stars: 3,115
- Watchers: 106
- Forks: 568
- Open Issues: 77
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Support: .github/support.svg
Awesome Lists containing this project
README
[JavaScript Library for Web Based Terminal Emulators](https://terminal.jcubic.pl)
[![npm](https://img.shields.io/badge/npm-2.44.1-blue.svg)](https://www.npmjs.com/package/jquery.terminal)
![bower](https://img.shields.io/badge/bower-2.44.1-yellow.svg)
[![Build and test](https://github.com/jcubic/jquery.terminal/actions/workflows/build.yaml/badge.svg?branch=master&event=push)](https://github.com/jcubic/jquery.terminal/actions/workflows/build.yaml)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=master&0f20bf6eaa4edcca15f83f8bbf243c1e)](https://coveralls.io/github/jcubic/jquery.terminal?branch=master)
![NPM Downloads](https://img.shields.io/npm/dm/jquery.terminal.svg?style=flat)
[![jsDelivr Downloads](https://data.jsdelivr.com/v1/package/npm/jquery.terminal/badge?style=rounded&n=1)](https://www.jsdelivr.com/package/npm/jquery.terminal)
[![Paid Support](https://img.shields.io/badge/paid-support-354465.svg)](https://support.jcubic.pl/)
[![LICENSE MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jcubic/jquery.terminal/blob/master/LICENSE)### Summary
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 your 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 a web based terminal on any website.
Because with this library you need to code all the commands yourself, you can call it fake terminal emulator. In contrast to library that will give you access to real terminal like online SSH. To have real online SSH I suggest to use [xterm.js](https://github.com/xtermjs/xterm.js) library.
### Features:
* You can create an interpreter for your JSON-RPC service with one line
of code (just use url as first argument).* 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).* Stack of interpreters - you can create commands that trigger additional
interpreters (eg. you can use couple of JSON-RPC service and run them
when user type command)* Command Tree - you can use nested objects. Each command will invoke a
function (own REPL), if the value is an object it will create a new
interpreter and use the function from that object as commands. You can
use as many nested object/commands as you like. If the value is a string
it will create JSON-RPC service.* Support for command line history, it uses Local Storage if possible.
* Support for tab completion.
* Includes keyboard shortcut from bash like CTRL+A, CTRL+D, CTRL+E etc.
* Bash reverse history search (CTRL+R / CTRL+G).
* You can create and overwrite existing keyboard shortcuts.
* Multiple terminals on one page (every terminal can have different
commands, its own authentication function and its own command history).* It catches all exceptions and displays error messages in the terminal
(you can see errors in your javascript and php code in terminal if they
are in the interpreter function).* Using extended commands you can change working of the terminal without
touching the front-end code (using echo method and terminal formatting
like syntax). Read more in
[docs](https://terminal.jcubic.pl/api_reference.php#extended_commands).* Easy way to change the style of the terminal (like color or cursor animation).
* Chinese and Japanese character support.
* You can use ASCII forms and collect information from users.
* Animation (including typing effect and Canvas canvas adapter).
* Support ANSI escapes codes.
* Experimental mobile support, see [open issues](https://github.com/jcubic/jquery.terminal/labels/mobile)
### Demo
You can test current version at this URL:
* [https://jcubic.github.io/jquery.terminal/](https://jcubic.github.io/jquery.terminal/)
or if it doesn't use latest version (because of jsDelivr cache) you can force it with this URL:
* [https://jcubic.github.io/jquery.terminal/?ver=2.44.1](https://jcubic.github.io/jquery.terminal/?ver=2.44.1)
And development version using:
* [https://jcubic.github.io/jquery.terminal/?ver=devel](https://jcubic.github.io/jquery.terminal/?ver=devel)
You can use any version you want, everything what [jsDelivr GH API accepts](https://www.jsdelivr.com/?docs=gh).
### Installation
Include jQuery library, you can use cdn from https://jquery.com/download/
or use jsDelivr:
```html
```
Then include js/jquery.terminal-2.44.1.min.js and css/jquery.terminal-2.44.1.min.css
You can grab the files from CDN:
```html
```
or
```html
```
If you always want latest version, you can get it from [unpkg](https://unpkg.com/) without specifying version,
it will redirect to the latest ones:```html
```
or jsDelivr that is bit faster:
```html
```
#### Bleeding Edge Version
If you want to test bleeding edge, development version of jQuery Terminal. You can use those files:
```html
```
but it's not refreshed as fast as rawgit was, because it's CDN and need to be propagated to different servers.
#### Keyboard key polyfill
**NOTE:** From version 1.0.0 if you want to support old browsers then you'll need to use [key event property polyfill](https://rawgit.com/inexorabletash/polyfill/master/keyboard.js). You can check the support for it on [can I use](https://caniuse.com/#feat=keyboardevent-key).
```html
```
or
```html
```
#### Command Line
You can also install jQuery Terminal using command line, from [bower repository](https://bower.io/):
```
bower install jquery.terminal
```or [npm registry](https://www.npmjs.com/):
```
npm install jquery.terminal
```### Example of usage
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.```javascript
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.```javascript
$('body').terminal({
cat: function(width = 200, height = 300) {
return $(``);
},
title: function() {
return fetch('https://terminal.jcubic.pl')
.then(r => r.text())
.then(html => html.match(/([^>]+)<\/title>/)[1]);
}
}, {
checkArity: false,
greetings: 'My Terminal\n'
});
```And more advanced example:
```javascript
jQuery(function($, undefined) {
$('#term_demo').terminal({
add: function(a, b) {
this.echo(a + b);
},
re: function(re, str) {
if (re instanceof RegExp && re.test(str)) {
this.echo(str + ' [[;green;]match]');
}
},
foo: 'foo.php',
bar: {
sub: function(a, b) {
this.echo(a - b);
}
}
}, {
height: 200,
width: 450,
prompt: 'demo> '
});
});
```command `add 2 2` will display `4` (not `22`).
Command `foo` will change prompt to `foo>` and each new command will execute
json-rpc method from foo.php script.command `bar` will change the prompt to `bar> ` and if you type `sub 10 2` it will display 8.
To exit from bar nested command you can type `exit` or press CTRL+D.command `re /^foo/ foo-bar` will echo: "foo-bar match" where "match" will be green.
By default arguments are required but you can disable the check like this:
```javascript
jQuery(function($, undefined) {
$('#term_demo').terminal({
add: function(...args) {
this.echo(args.reduce((a,b) => a + b));
}
}, {
checkArity: false
});
});
```And add command will accept any number of argments and it will sum them up (if they are numbers).
You can create JSON-RPC interpreter with authentication in just one line:
```javascript
$('#term_demo').terminal('service.php', {login: true});
```The rest of the code can be on the server, so you can write fully working application,
without any front-end, that can be tested in browser.First argument to terminal can also be array with objects strings and functions, with
one requirement, that only one function can be used as last fallback for commands that was
not found in RPC or in objects.```javascript
jQuery(function($, undefined) {
$('#term_demo').terminal([{
add: function(...args) {
this.echo(args.reduce((a,b) => a + b));
}
} 'foo.php', function(command) {
this.echo("You've typed " + command, {formatters: false, exec: false});
}], {
checkArity: false
});
});
```More examples [here](http://terminal.jcubic.pl/examples.php). You can also check
[Full Documentation](http://terminal.jcubic.pl/api_reference.php) or
[Getting Started Guide on Wiki](https://github.com/jcubic/jquery.terminal/wiki/Getting-Started).### Quick Start Tutorials
If you want to start with jQuery Terminal you can look at those tutorials:
* [How to create interactive terminal like website?](https://itnext.io/how-to-create-interactive-terminal-like-website-888bb0972288) (beginner level)
* [How to Create an Interactive Terminal-Based Portfolio](https://www.freecodecamp.org/news/how-to-create-interactive-terminal-based-portfolio/) (intermediate level)The first tutorial is have all the basics, even if you're new to programming and JavaScript. The
second one explain everything but it assume that you know the basics. If you pick the second and and
stuck you can reference the first one. It's worth checking the first one anyway.### Security
Because of security in version 1.20.0 links with protocols different than ftp or http(s) (it was
possible to enter javascript protocol, that could lead to XSS if author of the app echo user input
and save it in DB) was turn off by default. To enable it, you need to use `anyLinks: true` option.In version 1.21.0 executing terminal methods using extendend commands `[[ terminal::clear() ]]` was
also disabled by default because attacker (depending on your application) could execute
`terminal::echo` with raw option to enter any html and execute any javascript. To enable this
feature from this version you need to use `invokeMethods: true` option.The features are safe to enable, if you don't save user input in DB and don't echo it back to
different users (like with chat application). It's also safe if you escape formatting before you
echo stuff.If you don't save user input in DB but allow to echo back what user types and have enabled
`execHash` options, you may have reflected XSS vulnerability if you enable this features. If you
escape formatting this options are also safe.**NOTE**: To disable exec if you have `execHash` (or echo stuff from users with `invokeMethods: true`),
you can also set option `{exec: false}` to your `echo` call and use it only when you get
values from server (not from DB indireclty from users). If you do this you will be able to echo stuff
from users and execute terminal methods from server (this feature is mostly done just for that).### Contributors
If you want to contribute read [CONTRIBUTING.md](CONTRIBUTING.md) first. Here are project contributors:
| [
Jakub T. Jankiewicz](https://jakub.jankiewicz.org/)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=jcubic) | [
Riccardo Mura](https://github.com/cowuake)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=cowuake) | [
Jean-Michel Carrel](https://github.com/Neyxo)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=Neyxo) | [
kid1412z](https://github.com/kid1412z)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=kid1412z) | [
Marcel Link](https://github.com/ml1nk)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=ml1nk) | [
Sébastien Warin](http://sebastien.warin.fr)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=sebastienwarin) | [
Christopher John Ryan](https://github.com/ChrisJohnRyan)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=ChrisJohnRyan) |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| [
Johan](https://github.com/johanjordaan)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=johanjordaan) | [
Snyk bot](https://snyk.io)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=snyk-bot) | [
Florian Schäfer](https://github.com/fschaefer)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=fschaefer) | [
Tomasz Ducin](ducin.dev)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=ducin) | [
Qijia Liu](https://github.com/eagleoflqj)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=eagleoflqj) | [
Ishan Ratnapala](https://github.com/IshanRatnapala)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=IshanRatnapala) | [
David Refoua](http://www.Refoua.me)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=DRSDavidSoft) |
| [
Antoine](https://github.com/antoineol)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=antoineol) | [
youurayy](https://github.com/youurayy)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=youurayy) | [
Steve Kirkegard](https://www.linkedin.com/in/steve-kirkegard)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=stevekirks) | [
stereobooster](https://stereobooster.com)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=stereobooster) | [
Dev Kumar Gupta](https://github.com/mrkaiser)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=mrkaiser) | [
dependabot[bot]](https://github.com/dependabot[bot])
[commits](https://github.com/jcubic/jquery.terminal/commits?author=dependabot[bot]) | [
coderaiser](http://coderaiser.github.io)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=coderaiser) |
| [
Yutong Luo](https://yutongluo.com)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=yutongluo) | [
Steve Phillips](https://tryingtobeawesome.com/)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=elimisteve) | [
Robert W](https://github.com/rbw)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=rbw) | [
exit1](https://github.com/exit1)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=exit1) | [
Mateusz Paprocki](https://github.com/mattpap)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=mattpap) | [
Martin v. Löwis](https://github.com/loewis)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=loewis) | [
KiddoV](https://github.com/KiddoV)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=KiddoV) |
| [
Jon Steinich](https://github.com/jsteinich)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=jsteinich) | [
John Jarvis](http://www.jarv.org)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=jarv) | [
Jarry Shaw](https://jarryshaw.me)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=JarryShaw) | [
jpaye](https://github.com/jpaye)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=jpaye) | [
Hraban](https://br0g.0brg.net)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=hraban) | [
Hasan](juanpota.to)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=JuanPotato) | [
finlob](https://github.com/finlob)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=finlob) |
| [
Ezinne Anne Emilia](https://github.com/ezinneanne)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=ezinneanne) | [
Anton Vasilev](https://github.com/avdes)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=avdes) | [
Abdelrahman Omran](https://omranic.com)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=Omranic) | [
7twin](https://github.com/7twin)
[commits](https://github.com/jcubic/jquery.terminal/commits?author=7twin) |[jQuery Terminal Website](https://github.com/jcubic/jquery.terminal-www) contributors:
| [
Jakub T. Jankiewicz](https://jcu.bi)
[commits](https://github.com/jcubic/jquery.terminal-www/commits?author=jcubic) | [
Ezinne Anne Emilia](https://github.com/ezinneanne)
[commits](https://github.com/jcubic/jquery.terminal-www/commits?author=ezinneanne) | [
Marc Laporte](https://wikisuite.org)
[commits](https://github.com/jcubic/jquery.terminal-www/commits?author=marclaporte) | [
Rich Morin](https://github.com/RichMorin)
[commits](https://github.com/jcubic/jquery.terminal-www/commits?author=RichMorin) | [
4s3ti](https://4s3ti.net)
[commits](https://github.com/jcubic/jquery.terminal-www/commits?author=4s3ti) | [
DInesh51297](https://github.com/DInesh51297)
[commits](https://github.com/jcubic/jquery.terminal-www/commits?author=DInesh51297) | [
Logan Rosen](https://www.loganrosen.com/)
[commits](https://github.com/jcubic/jquery.terminal-www/commits?author=loganrosen) |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |### Acknowledge
Projects include with the source code:
* [Storage plugin](https://sites.google.com/site/daveschindler/jquery-html5-storage-plugin) by Dave Schindler (MIT)
* [jQuery Timers](http://jquery.offput.ca/every/) (WTFPL)
* [Cross-Browser Split](http://blog.stevenlevithan.com/archives/cross-browser-split) by [Steven Levithan](http://stevenlevithan.com/) (MIT)
* [jQuery Caret](https://github.com/accursoft/caret) by Gideon Sireling (3-BSD)
* [sprintf.js](https://github.com/alexei/sprintf.js) by [Alexandru Mărășteanu](http://alexei.ro/) (3-BSD)
* [node-ansiparser](https://github.com/netzkolchose/node-ansiparser) by Joerg Breitbart (MIT)
* [emoji regex](https://github.com/mathiasbynens/emoji-regex) by Mathias Bynens (MIT)Other code used inside the project or inspired by:
* [How to detect iPad and iPad OS version in iOS 13 and Up?](https://stackoverflow.com/a/57924983/387194s) (StackOverflow)
* [How do I scroll to an element within an overflowed Div?](https://stackoverflow.com/a/18927969/387194) (StackOverflow)
* [isInViewport](https://github.com/zeusdeux/isInViewport) by Mudit Ameta (MIT)
* [Detecting and generating CSS animations in JavaScript](https://hacks.mozilla.org/2011/09/detecting-and-generating-css-animations-in-javascript/) by Chris Heilmann
* [polyfill for `KeyboardEvent.prototype.key`](https://github.com/cvan/keyboardevent-key-polyfill/) by Christopher Robert Van Wiemeersch (CC0)
* [wheel event detection](https://web.archive.org/web/20180523065743/https://developer.mozilla.org/en-US/docs/Web/Events/wheel) by MDN
* [CodeMirror](https://codemirror.net/) by Marijn Haverbeke, was inspiration for some clipboard handling solutions.Personal thanks:
* [T.J. Crowder](https://stackoverflow.com/users/157247/t-j-crowder) for helping with tracking_replace on [StackOveflow](https://stackoverflow.com/a/46756077/387194)
* [@jerch](https://github.com/jerch) for helping with ANSI Parsing
* [@cviejo](https://stackoverflow.com/users/1551349/cviejo) for [ASCII table algorithm fix](https://stackoverflow.com/a/35115703/387194)Also thanks to:
[![BrowserStack](https://user-images.githubusercontent.com/587740/39730261-9c65c4d8-522e-11e8-9f12-16b349377a35.png)](http://browserstack.com/)
for cross-device testing opportunity.
### Paid Support
You can request paid support, you can find details at [support.jcubic.pl](https://support.jcubic.pl/).### Star History
[![Star History Chart](https://api.star-history.com/svg?repos=jcubic/jquery.terminal&type=Date&branch=master)](https://star-history.com/#jcubic/jquery.terminal&Date)
### License
Licensed under [MIT](http://opensource.org/licenses/MIT) license
Copyright (c) 2011-2024 [Jakub T. Jankiewicz](https://jcubic.pl/me)