command-box

0.1.0 • Public • Published

command-box

A console widget. This differs from echo-chamber by using an <input> tag instead of handling user input manually.

Usage

var CommandBox = require('command-box');

// #console should be a div element
var widget = new CommandBox(document.querySelector('#console'), {
    
    // example of an async evaluator
    evaluate: function(command, console) {
        console.notReady(); // hide input box

        // now evaluate the submitted command
        doWork(function(result) {

            // print output to console
            console.print(result);

            // and set up the console for the next command
            console.newCommand(true);
            console.focus();
        
        });

    },

    prompt: function(console) {
        return { text: '> ' }
    },

    // submitted commands should be echoed to the output
    echo: true
});

// tell the widget to prepare itself for new input by clearing any existing
// input and setting a new prompt. the true paramater indicates that the console
// should also be 'made ready' meaning that the input box will be revealed.
widget.newCommand(true);
widget.focus();

Default styles are in default.css; you can substitute the base command-box class for whatever you wish.

Copyright & License

© 2014 Jason Frame [ @jaz303 / jason@onehackoranother.com ]

Released under the ISC license.

Readme

Keywords

Package Sidebar

Install

npm i command-box

Weekly Downloads

1

Version

0.1.0

License

ISC

Last publish

Collaborators

  • jaz303