pseudoTerminal
a toy terminal
$3
$3
``
Terminal = PseudoTerminal(, [option]);
Terminal
.addCommand(, )
.addCommand(, )
.destroy(); // destroy the terminal
`
$3
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
$3
`
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: , b: true}
util.output("hello", param.a)
util.next();
}
})
``
$3
zjhou.github.io