Console.js
Console.js
is a tiny lib for creating Console (video game cli) popups in browser.
NEW: v2.0 is out 😺
Check the Live Demo, or Basic Usage / Advance Usage / API.
Basic Usage
- To install console.js, either:
- Use npm:
npm install console.js
- Include
console.js
in html:
<script src="https://unpkg.com/console.js@2"></script>
- Create a Console:
const cnsl = hotkey: 192 cnsl
Advance Usage
Options
var cnsl = hotkey: 27 // <kbd>ESC</kbd> welcome: 'Hello User.' caseSensitive: true autoComplete: true {} {} {} {/*...*/} {/*...*/};
hotkey
: {Number|Boolean} The keyCode of hotkey.192
(the ~) by default.welcome
: {String} The welcome message.''
by default.caseSensitive
: {Boolean} If you want to.false
by default.autoComplete
: {Boolean|Function} Enable tab for auto completion.defaultHandler
: {Function} The fallback handler for all commands.noop
by default.onShow
: {Function} On show callback.noop
by default.onHide
: {Function} On hide callback.noop
by default.
Register command with extra config
.register(commandName, commandHandler, commandConfig)
var cnsl = cnsl cnsl
Custome autoComplete function
var cnsl = hotkey: 27 autoComplete: customeAutoComplete { const availableCommands = Object cnsl return inputString}
API
Create a Console
new Console()
Create a console instance (with default options)new Console(options)
Create a console with options. (see Basic Usage)
Instance Methods
Note: Console instances on https://amio.github.io/console.js/
were exposed on window. You can fiddle with them(window.cnsl
and window.smtc
) in devtools.
.register(command, handler[, config])
.register(command, handler)
Register ahandler
tocommand
.register(command, handler, config)
Register ahandler
tocmd
with a config object.register(handler)
Register adefaultHandler
.log(msg[, cmd])
.log(msg)
Write a message to console.log(msg, cmd)
Write a message with an instruction to console
.clear()
.clear()
Clear history
.toggle([switch])
.toggle()
Toggle the console.toggle("on")
Open it.toggle("off")
Close it
.destroy()
.destroy()
Suicide.
License
MIT © Amio