• Stars
    star
    115
  • Rank 305,916 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A game console (video game cli) for browsers.

Console.js npm-version

Console.js is a tiny lib for creating Console (video game cli) popups in browser.

NEW: v2.0 is out 😺

Console.js Screenshot

Check the Live Demo, or Basic Usage / Advance Usage / API.

Basic Usage

  1. 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>
  1. Create a Console:
const cnsl = new Console({ hotkey: 192 })

cnsl.register('addbots', function (num) {
    // Add some bots, then tell player:
    return num + ' bots added.'
})

Advance Usage

Options

var cnsl = new Console({
    hotkey: 27, // <kbd>ESC</kbd>
    welcome: 'Hello User.',
    caseSensitive: true,
    autoComplete: true,
    defaultHandler: function () {},
    onShow: function () {},
    onHide: function () {}
}, {
  'cmd1': function (args) {/*...*/},
  'cmd2': function (args) {/*...*/}
});
  • 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 = new Console()

cnsl.register('say', function () {
  return player.name + ': "' + Array.prototype.join.call(arguments, ' ') + '"'
}, {
  usage: 'SAY <message string>: Broadcast a message to other players in the game.'
})

cnsl.register('help', function () {
  return Object.keys(cnsl.handlers).map(function (name) {
    return ' - ' + cnsl.handlers[name].cfg.usage
  }).join('\n')
}, {
  usage: 'HELP: Show help messages.'
})

Custome autoComplete function

var cnsl = new Console({
  hotkey: 27,
  autoComplete: customeAutoComplete
})

function customeAutoComplete (inputString) {
  const availableCommands = Object.keys(cnsl.handlers)
  cnsl.log(availableCommands.join(' '))

  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 a handler to command
  • .register(command, handler, config) Register a handler to cmd with a config object
  • .register(handler) Register a defaultHandler

.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

More Repositories

1

awesome-micro

A collection of awesome things regarding zeit's micro.
1,071
star
2

emoji.json

Just an emoji.json
JavaScript
290
star
3

re-carousel

Minimal carousel component for React.
JavaScript
272
star
4

npm-why

Identifies why a package has been installed. Equivalent to `yarn why` for npm packages.
JavaScript
171
star
5

now-go

Create tinyurl/redirection service with ease.
JavaScript
112
star
6

embedded-google-fonts

Embed (base64 encoded) google fonts into css.
JavaScript
105
star
7

micro-fork

Fast and functional router
JavaScript
97
star
8

eloc

A CLI for presentations in markdown
TypeScript
59
star
9

nls

Missing inspector for npm packages.
JavaScript
54
star
10

pageshot

Pageshot as a service.
JavaScript
47
star
11

hyper-blink

Let Hyper's cursor blink.
JavaScript
42
star
12

git-cheatsheet-chs

Git Cheatsheet δΈ­ζ–‡η‰ˆ
JavaScript
36
star
13

font-mess

Obscure text with messed font.
JavaScript
34
star
14

flaming-disk-usage

Find out who's burning my precious disk
JavaScript
26
star
15

alfred-emoji-finder

Find relevant emoji from text
23
star
16

marked

Markdown rendering as a service.
JavaScript
21
star
17

serverless-zhcn

ζ— ζœεŠ‘ε™¨ζžΆζž„οΌˆServerless ArchitecturesοΌ‰
CSS
20
star
18

markdown-deck

A web component for presenters
TypeScript
17
star
19

measurement-protocol

Human friendly tracking with Google's Universal Analytics via Measurement Protocol.
TypeScript
15
star
20

node-submod

A subtitle(ass/srt) toolkit for modifing synchronization, encoding, etc.
JavaScript
15
star
21

youtube-screenshot-button

Add screenshot button to youtube.com
JavaScript
15
star
22

fish-theme-eden

A customizable theme for fish shell.
Shell
12
star
23

docdock

App launcher for devdocs.io.
JavaScript
11
star
24

userscript-parser

Userscript metadata parser.
JavaScript
10
star
25

gh-index

A directory index for gh-pages.
JavaScript
10
star
26

docker-node-chrome

Dockerfile for nodejs + chrome.
Dockerfile
10
star
27

pull-request-guide

ε›’ι˜Ÿεδ½œ Pull-Request δΉ¦ε†™ζŒ‡ε—
10
star
28

my-way

Robust path matcher in 738 bytes.
TypeScript
9
star
29

node-pingrace

A ping race program.
JavaScript
9
star
30

serve-marked

Serve README.md at ease
TypeScript
9
star
31

hyper-final-say

Allows local config override any plugin or theme settings applied on top of the defaults `./.hyper.js`.
JavaScript
9
star
32

fe-lenses

Full-frame E-mount lenses catalog.
JavaScript
8
star
33

pug-playground

Pug Playground
JavaScript
7
star
34

node-orn

Oh Rename, rename files like JavaScript String.replace()
JavaScript
6
star
35

cron

Amio's cron jobs with GitHub Actions
JavaScript
6
star
36

now-deploy-badge

"Deploy to Now" badge for GitHub READMEs
6
star
37

amio.github.com

Amio on Github
CSS
5
star
38

gulp-all

Promise.all for gulp streams, so you can compose a bunch of "private" subtasks.
JavaScript
5
star
39

npm-mirrors

A list for npm registry mirrors.
JavaScript
4
star
40

qr-cli

Minimal viable QR code generator in terminal.
JavaScript
3
star
41

timeout

An endpoint for timeout testing
JavaScript
3
star
42

yarn-why

Identifies why a package has been installed (by yarn.lock)
JavaScript
3
star
43

b-decks

Amio's presentations at bytedance
HTML
2
star
44

require-cjs-string

Load commonjs module from string in Node & Browser.
JavaScript
2
star
45

dev-splash

HTML
2
star
46

otwlist

ζŽε€΄εŽ»ε°Ύηš„η§‘ε­¦δΈŠη½‘ζΈ…ε•
2
star
47

bbdemo

Backbone demo with Require.js
JavaScript
2
star
48

send-beacon

Beacon API for Node.js
JavaScript
2
star
49

metalmonkey

Modern userjs manager.
JavaScript
2
star
50

comets

Create a one-off server for testing http request listener
TypeScript
2
star
51

base64

Encodes and decodes base64 within browser.
JavaScript
1
star
52

uuid.now.sh

TypeScript
1
star
53

now-firestore

JavaScript
1
star
54

tba

A minimal placeholder page for domains just bought.
HTML
1
star
55

tm-i2

Tampermonkey interface redesigned.
CSS
1
star
56

chrome-daemon

Manage Google Chrome instance with Node.js.
JavaScript
1
star
57

vue-examples

JavaScript
1
star
58

shu.now.sh

ι˜Ώζ‹‰δΌ―ζ•°ε­—θ½¬δΈ­ζ–‡ζ•°ε­—
JavaScript
1
star
59

mrrobot-comments

Mr Robot post-episode comments
1
star
60

userscript-cli

Cli for making userscript
JavaScript
1
star
61

cli

Automatically exported from code.google.com/p/amio
JavaScript
1
star
62

koa-mustache

Serve mustache with data (optional)
JavaScript
1
star
63

multi-ghost

A setup for multiple ghost blogs.
JavaScript
1
star
64

echo-path.vercel.app

TypeScript
1
star
65

docker-node-chrome-cjk

Dockerfile for nodejs + chrome + cjk fonts.
1
star
66

attempts

Try function with different args.
JavaScript
1
star
67

atom-jsdoc-preview

JSDoc preview in Atom.
1
star
68

nrm

Minimal npm registry manager. (Like `nrm` but without bundling a huge `npm`.)
JavaScript
1
star
69

holmes

A dock for homes.
JavaScript
1
star
70

yo

Begin app
JavaScript
1
star
71

webpack2-example

JavaScript
1
star
72

alfred-addons

Amio's alfred addons
CSS
1
star