Lightweight Terminal Emulator In Pure JavaScript – terminal.js

Category: Javascript | March 18, 2020
Author:Apthox
Views Total:2,387 views
Official Page:Go to website
Last Update:March 18, 2020
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);
});

Changelog:

03/18/2020

  • updated default user title

You Might Be Interested In:


Leave a Reply