Speed up development with full-stack environments for every branch.

Learn More

Console menu for your cool REPL Application [shell and cli]

Forked from Hello World for Node.js.

1472 Runs 2490 Views 170 Copies
Saved

Saved

nbu 1

nbu
published 2 years ago

var menu = require('node-menu');

var TestObject = function() {
    var self = this;
    self.fieldA = 'FieldA';
    self.fieldB = 'FieldB';
}

TestObject.prototype.printFieldA = function() {
    console.log(this.fieldA);
}

TestObject.prototype.printFieldB = function(arg) {
    console.log(this.fieldB + arg);
}

var testObject = new TestObject();

menu.addDelimiter('-', 40, 'Main Menu')
    .addItem(
        'No parameters', 
        function() {
            console.log('No parameters is invoked');
        })
    .addItem(
        "Print Field A",
        testObject.printFieldA,
        testObject)
    .addItem(
        'Print Field B concatenated with arg1',
        testObject.printFieldB,
        testObject,
        [{'name': 'arg1', 'type': 'string'}])
    .addItem(
        'Sum', 
        function(op1, op2) {
            var sum = op1 + op2;
            console.log('Sum ' + op1 + '+' + op2 + '=' + sum);
        },
        null, 
        [{'name': 'op1', 'type': 'numeric'}, {'name': 'op2', 'type': 'numeric'}])
    .addItem(
        'String and Bool parameters', 
        function(str, b) {
            console.log("String is: " + str);
            console.log("Bool is: " + b);
        },
        null,
        [{'name': 'str', 'type': 'string'}, {'name': 'bool', 'type': 'bool'}])
    .addDelimiter('*', 40)
    // .customHeader(function() {
    //     process.stdout.write("Hello\n");
    // })
    // .disableDefaultHeader()
    .start();
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).