Skip to content
Advertisement

How to Create More Than One Command in a jQuery Terminal Environment

My Current Project

I am trying to make a terminal-style webpage using jQuery Terminal.

My Problem

I cannot figure out how to add more than one command to the terminal.

Here’s my code:

$('body').terminal({
      hello: function(name) {
          this.echo('Hello, ' + name +
                    '. Welcome to the Rapocrythia command line.');
      }
  }, {
      greetings: 'Rapocrythia Command Line[Version 0.0.1]n(c) Copyright Rapocrythia Systems, Inc. All Rights Reserved.'
  }
);

Advertisement

Answer

Just add more properties to the first argument.

$('body').terminal({
  hello: function(name) {
    this.echo('Hello, ' + name +
      '. Welcome to the Rapocrythia command line.');
  },
  add: function(num1, num2) {
    this.echo(parseInt(num1) + parseInt(num2));
  },
  bye: function() {
    this.echo('So long');
  }
}, {
  greetings: 'Rapocrythia Command Line[Version 0.0.1]n(c) Copyright Rapocrythia Systems, Inc. All Rights Reserved.'
});
<link href="https://unpkg.com/jquery.terminal/css/jquery.terminal.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://unpkg.com/jquery.terminal/js/jquery.terminal.min.js"></script>

If you type add 10 15 it will print 25.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement