Lightweight Terminal Emulator In Pure JavaScript – terminal.js

Category: Javascript | January 24, 2019
Author: Apthox
Views Total: 525
Official Page: Go to website
Last Update: January 24, 2019
License: MIT

Preview:

Lightweight Terminal Emulator In Pure JavaScript – terminal.js

Description:

An ultra-light and easy-to-extend bash terminal emulator written in pure vanilla JavaScript.

How to use it:

Import the stylesheet terminal.css and JavaScript terminal.js into the document.

<link rel="stylesheet" href="terminal.css">
<script src="terminal.js"></script>

Build the HTML structure for the terminal.

<div id="screen">

  <div id="Container">
    <div id="input">
      <p id="input_title"></p>
      <input id="input_source" type="command" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" autofocus>
    </div>
    <div id="logger">
      <div id="wrapper">
      </div>
    </div>
  </div>
  
</div>

Add your own commands to the terminal.

log("Welcome to a new online simulated terminal!");

// Example Command - Hey

register_cmd("hey", function (cmd) {
    var parameters = cmd.split(" ").slice(1);
    for (var i = 0; i < parameters.length; i++) {
        block_log("Hello " + parameters[i]);
    }
});

// Example Command - Sum

register_cmd("sum", function(cmd){
	var parameters = cmd.split(" ").slice(1);
	var sum = 0;
    for (var i = 0; i < parameters.length; i++) {
        sum += parseInt(parameters[i]);
    }
    block_log("Sum: " + sum);
});

You Might Be Interested In:


Leave a Reply