0.0.4 • Published 6 years ago

pseudoterminal v0.0.4

Weekly downloads
4
License
ISC
Repository
github
Last release
6 years ago

pseudoTerminal

a toy terminal

install

<script src="path/to/pseudoterminal.umd.js"></script>

usage

Terminal = PseudoTerminal(<wrappid>, [option]);
Terminal
    .addCommand(<cmdName>, <cmdBody>)
    .addCommand(<cmdName1>, <cmdBody>)
    .destroy(); // destroy the terminal

doc

  1. option {Object}

    • option.width {String} (css width)
    • option.height {String} (css height)
    • bgColor background color(css color str)
    • option.promptSign {String}
    • fontFamily {String}
    • fontSize {String}
  2. addCommand {Function}

    • cmdName {String} command name
    • cmdBody {Object}
    • cmdBody.handler {Function}
    • cmdBody.shortopts {String} option letters that the command wants to recognize (i.e., the same format that Unix getopt() uses)
  3. cmdBody.handler(util[, param]) {Function}

    • if cmdBody.shortopts is leave out, then handler only got one param util
    • if cmdBody.shortopts is set, then handler got two params param and util
    • use uitl.output(result) to print result on terminal
    • use util.next() to handle next command
    • use util.loading(true) to show spinner
    • use util.loading(false) to hide spinner

exapmles

const Terminal = PseudoTerminal('cmd_wrapper', {
    bgColor: 'rgba(0, 0, 0, .8)',
    color: '#fff',
    promptSign: '$'
});

Terminal.addCommand('hello', {
    shortopts: "a:b",
    handler: function(util, param) {
        // param => {a: <value>, b: true}
        util.output("hello", param.a)
        util.next();
    }
})

demo

zjhou.github.io

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago