0.0.4 • Published 8 years ago
pseudoterminal v0.0.4
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 terminaldoc
option{Object}option.width{String} (css width)option.height{String} (css height)bgColorbackground color(css color str)option.promptSign{String}fontFamily{String}fontSize{String}
addCommand{Function}cmdName{String} command namecmdBody{Object}cmdBody.handler{Function}cmdBody.shortopts{String} option letters that the command wants to recognize (i.e., the same format that Unix getopt() uses)
cmdBody.handler(util[, param]){Function}- if
cmdBody.shortoptsis leave out, thenhandleronly got one paramutil - if
cmdBody.shortoptsis set, thenhandlergot two paramsparamandutil - use
uitl.output(result)to printresulton terminal - use
util.next()to handle next command - use
util.loading(true)to show spinner - use
util.loading(false)to hide spinner
- if
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();
}
})