• Stars
    star
    142
  • Rank 258,495 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 2 years ago

Reviews

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

Repository Details

Add an elegant command-line interface to any page

Simple Console

Simple Console is nice clean command-line interface for the web. Check out the demo!

Features

  • Light and dark styles

  • Easy rich HTML output

  • Command history accessible with up/down arrow keys, saved to localStorage

  • Command history menu for mobile accessibility

  • Doesn't create a duplicate history entry if you re-enter the last command

  • Lets you delete history entries with Shift+Delete

  • Automatically scrolls down to new entries - unless you scroll up (good in case there are a lot of messages being logged and you want to view earlier output!)

  • Includes aria attributes, although the accessibility still needs work!

  • Vanilla JavaScript and CSS with no external dependencies

  • MIT licensed

Limitations

  • Delivered as two separate files (CSS and JS).
    (It'd be nicer if it was a single JS file, and especially if it was a Web Component! Wanna help out?)

  • The CSS uses some generic selectors like error and success that are likely to conflict.

  • The console.log, and console.warn etc. methods only accept a single argument; they don't match the browser console API - which doesn't have a standard specification, by the way, it's just some de facto shared methods between browsers.

Usage

Download simple-console.css and simple-console.js, and include in the <head>:

<link rel="stylesheet" href="simple-console.css">

and anywhere before you use SimpleConsole but probably in the <body>:

<script src="simple-console.js"></script>

Example

var con = new SimpleConsole({
	placeholder: "Enter JavaScript",
	handleCommand: function(command){
		try {
			con.log(eval(command));
		} catch(error) {
			con.error(error);
		}
	},
	autofocus: true, // if the console is to be the primary interface of the page
	storageID: "app-console", // or e.g. "simple-console-#1" or "workspace-1:javascript-console"
});

// add the console to the page
document.body.appendChild(con.element);

// show any uncaught errors (errors may be unrelated to the console usage)
con.handleUncaughtErrors();

See demo.js for a more complete example (altho not that complete).

Page Setup

You should probably include a charset and viewport like in the demo.

You can position the console on the page the same way you might any div.

To make the console take up the entire page, use:

html,
body {
	height: 100%;
	margin: 0;
	display: flex;
	flex: 1;
}

For a Quake-style dropdown console, see the Tilde Dropdown Console Example.

Dark Mode

The dark styles take effect when the console element or any parent contains the class dark.

You could add a theme switcher like so:

var toggleDarkMode = function() {
	if (console.element.classList.contains("dark")) {
		console.element.classList.remove("dark");
	} else {
		console.element.classList.add("dark");
	}
};
var button = console.addButton(toggleDarkMode);
button.textContent = "โ—";
button.setAttribute("title", "Toggle dark theme");
button.setAttribute("aria-label", "Toggle dark theme");

API

new SimpleConsole(options)

Creates a console instance.

Note: The SimpleConsole object is referred to as console below, but you should probably give it a different name so it doesn't conflict with the global console object.

options.handleCommand(command) is called when the user hits Enter. You can handle the input however you want. It's recommended that you catch errors and log them with console.error. Other logging methods are documented below.

options.outputOnly specifies that there should be no input. You must specify either outputOnly or handleCommand.

options.placeholder is strongly recommended especially with the default input styling as there is very little visual indication of the input (when it's not focused).

options.autofocus should be used within an application where the console is the primary interface.

options.storageID should be used to separate the command history of different consoles. It's used as a localStorage key prefix.

console.element

You must use this to add the console to the page, e.g. document.body.appendChild(console.element)

console.input

The console's <input> element. Can be used to add controls/widgets i.e. console.input.parentElement.appendChild(widget)

console.addButton(action)

Adds a button to the right of the console's input area and returns the button element.

action should be a function.

console.addPopupButton(updatePopup)

Adds a button with a popup to the right of the console's input area and returns the button element.

updatePopup(popupElement) should update the contents of the popup.

Use addPopupMenuButton instead if the popup's contents are a standard menu.

console.addPopupMenuButton(getItems)

Adds a button with a standard popup menu to the right of the console's input area and returns the button element.

getItems() should return an array of items, with each item either of the form {label, action} or {type: "divider"}.

console.handleUncaughtErrors()

Sets up a window.onerror event listener which logs any uncaught errors to the console.

console.log(content)

Logs the given text or element to the console.

console.logHTML(html)

Logs the given HTML to the console.

console.error(content)

Logs the given error message (or element) to the console.

console.warn(content)

Logs the given warning message (or element) to the console.

console.info(content)

Logs the given info message (or element) to the console.

console.success(content)

Logs the given success message (or element) to the console.

console.getLastEntry()

Returns the last logged entry as an HTMLDivElement for further manipulation.

console.clear()

Clears the console.

TODO

  • Support multiple arguments to log, warn etc.

  • Distinguish error/success/warning messages for screen readers (maybe with cue-before from the CSS Speech Module)

  • Solarized and retro themes

  • Position menus better?

Packaging

  • Rename project because "simple-console" is taken on npm ("cute-console" maybe?)

  • This seems like it would be an ideal candidate for a Web Component!

Input

  • Multiline input (i.e. textarea)

  • Autocomplete (aria-autocomplete="inline")

  • Syntax highlighting

  • Should probably just let you use your own input component

FIXME

  • Fix duplicate reading of aria-label and placeholder by some screen readers

  • Fix input styling in Firefox with font: inherit and something else to make stuff line up perfectly

License

MIT-licensed, see LICENSE

More Repositories

1

jspaint

๐ŸŽจ Classic MS Paint, ๏ผฒ๏ผฅ๏ผถ๏ผฉ๏ผถ๏ผฅ๏ผค + โœจExtras
JavaScript
6,884
star
2

98

๐Ÿ’ฟ Web-based Windows 98 desktop recreation โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–“โ–ˆโ–“โ–“โ–’โ–“โ–’โ–’โ–‘โ–’โ–‘โ–‘โ–‘๐Ÿ—•๏ธŽ๐Ÿ——๏ธŽ๐Ÿ—™๏ธŽ
JavaScript
1,161
star
3

textual-paint

๐ŸŽจ MS Paint in your terminal.
Python
944
star
4

pipes

๐Ÿ’ฟ Classic 3D Pipes screensaver remake (web-based)
JavaScript
362
star
5

os-gui

Retro OS GUI JS/CSS library
JavaScript
179
star
6

guitar

๐ŸŽธ Online guitar toy and tablature recorder/player
JavaScript
94
star
7

mopaint

๐ŸŽจ๐Ÿฉธ๐Ÿ”ฅ๐Ÿงž Modern, modular painting program... (early stages)
JavaScript
92
star
8

wavey

An HTML5 online audio editor (BUGGY and not in development)
CoffeeScript
76
star
9

midi-recorder

๐ŸŽน The easiest way to record MIDI. No install. Automatically records.
JavaScript
76
star
10

anypalette.js

๐ŸŽจ Read/write all color palette file formats โค๐Ÿงก๐Ÿ’›๐Ÿ’š๐Ÿ’™๐Ÿ’œ
JavaScript
59
star
11

janitorial-android

Detailed LEGO Junkbot remake and fancy level editor
JavaScript
55
star
12

midiflip

๐ŸŽน MIDI music mayhem - flip, transpose, and arbitrarily remap pitches in MIDI files
JavaScript
41
star
13

node-ahk

Desktop scripting with Node.js based on IronAHK โŒจ๐Ÿ–ฑ๐Ÿ”ฅ
C#
31
star
14

rezzy-zoom-and-enhance

๐Ÿ”Žโœจ Zoom and Enhance browser extension (AI powered)
JavaScript
28
star
15

tracky-mouse

Mouse control via head tracking, as a cross platform desktop app and JS library. eViacam alternative.
JavaScript
26
star
16

postcss-gtk

Processes GTK+ CSS into browser CSS
CoffeeScript
26
star
17

card-game-generator

๐Ÿƒ๐ŸŽด A tool for making/prototyping tabletop games
CoffeeScript
25
star
18

ascii-hypercube

Make ASCII art with ๏ผจ๏ผน๏ผฐ๏ผฅ๏ผฒ๏ผฒ๏ผฅ๏ผฃ๏ผด๏ผก๏ผฎ๏ผง๏ผฌ๏ผฅ๏ผณ
JavaScript
23
star
19

true-random-movie

๐Ÿ’ซ๐Ÿ“ฝ๏ธ Pick a random movie from a VAST collection of titles (over 32K films)
JavaScript
17
star
20

slugg

๐Ÿšƒ A simple little up-going game
JavaScript
16
star
21

pbj-sandbox

2D point-based physics sandbox ๐Ÿฅœ๐Ÿ‡๐Ÿ–
JavaScript
16
star
22

retrores

A catalog of cursors and icons from Windows 98, in original and modern formats
JavaScript
16
star
23

elementary.css

elementary OS's stylesheet converted to browser CSS
CSS
16
star
24

tablature-parser

๐ŸŽธ Parse guitar tabs (part of https://github.com/1j01/guitar)
CoffeeScript
15
star
25

she-has-what

โšช Homestuck Doc Scratch text effect GIF generator
JavaScript
15
star
26

nonsensical

Generate grammatical sentences https://1j01.itch.io/nonsensical
JavaScript
14
star
27

diverge

๐Ÿ”ฑ explore textual possibilities like never before
JavaScript
14
star
28

skele2d

โ˜  A 2D game engine based around skeletal structures, with an in-game editor and animation support (pre-alpha)
CoffeeScript
13
star
29

nw-screensaver

๐ŸŒŒ Web based screensavers spanning multiple monitors, with transparency
CoffeeScript
13
star
30

tri-chromatic-keyboard

๐ŸŽน Better than a traditional piano layout
JavaScript
12
star
31

palettes

๐ŸŽจ A collection of palette files of various types ๐Ÿ’„๐ŸŽƒ๐Ÿ‹๐Ÿ๐Ÿ“—๐Ÿ“˜๐Ÿ”ฎ
HTML
12
star
32

mos

Monochrome Operating System
JavaScript
12
star
33

pixelweaver

๐ŸŽจ๐ŸŽฒ Reproducible procedural drawing tool (pre-alpha)
JavaScript
11
star
34

bookmarklets

๐Ÿ”– Fun functions, surreal when applied to websites you're familiar with
HTML
11
star
35

ascii-to-midi

Create MIDI files from text in several formats
JavaScript
10
star
36

sbahjifier

Make any page look like SWEET BRO AND HELLA JEFF
JavaScript
10
star
37

isaiahodhner.io

๐Ÿ‘จโ€๐Ÿ’ป๐ŸŒ๐ŸŒป My personal website, built with Next.js
JavaScript
7
star
38

suboptimal-research-tool

"Research" topics automatically
CoffeeScript
7
star
39

project-nexus

A hub for all your programming projects, and GUI for npm & package.json (not in development) - hey look a new thing!! https://webdash.xyz/ (solving the same sort of problem, and it looks nice!) ... ooh and another thing! https://github.com/720kb/ndm
JavaScript
7
star
40

scribble

DEPRECATED - Draws scribbly looking things. โžฐโœ
HTML
6
star
41

mind-map

๐Ÿง ๐Ÿ—บ because your mind doesn't have ugly boxes everywhere
HTML
6
star
42

multifiddle

(development inactive) Fiddle with coffee, js, css, html, and all that, in a minimalistic collaborative environment
JavaScript
6
star
43

amg

DEPRECATED PROJECT IDEA - An abstracted modular game framework with integrated pixel editor and realtime asset manager and a level editor with dynamic block type definitions and a skeletal character animator and inverse kinematics and a game. Except no game.
JavaScript
6
star
44

oregano

Game about stripping oregano leaves. Peggle-like.
JavaScript
6
star
45

fliptimer

โฑ A countdown timer with a fun flipping animation โณ
CoffeeScript
5
star
46

natter

๐Ÿ’ฌ A chat app (not in active development)
JavaScript
5
star
47

process-tree

Node library to find all the child processes
CoffeeScript
5
star
48

tiamblia-game

๐Ÿน An exploration adventure game
CoffeeScript
5
star
49

react-script

An elegant DSL for React - DEPRECATED: CoffeeScript 2 has JSX built in! http://coffeescript.org/v2/#jsx (requires a separate JSXโ†’JS conversion)
CoffeeScript
5
star
50

pesterchum

Pesterchum Chat Client, and also a Doc Scratch lightning text effect reaction GIF generator
HTML
5
star
51

board-game

โ˜–โ˜— A 2 player 3D board game of chance (and strategy)
JavaScript
5
star
52

psd-reader

(This was a fork but the original repo has moved off GitHub so it doesn't show up as one) Load Photoshopยฎ PSD files in the browser
JavaScript
5
star
53

emoji-aquarium

Emoji Aquarium
Python
5
star
54

systemocracy

A card game in which you build a vast conspiracy to take over the world
CoffeeScript
5
star
55

chess-mashup

Chess game mashup in 3D
JavaScript
5
star
56

fish-game

A fishy board game. ๐ŸŸ๐Ÿ  ๐Ÿฆˆ
JavaScript
4
star
57

audio-sponge

๐Ÿ”‰๐Ÿ’ฆ a sound machine
CoffeeScript
4
star
58

techy-playing-cards

๐Ÿ‚ก Very technical, you probably.. would understand...
CoffeeScript
4
star
59

tiamblia-original

๐ŸŒณ๐Ÿ‡ A little world experiment, precursor to Tiamblia
JavaScript
4
star
60

chiptool

(Project state: never mind) An experimental music making app (for chiptune, at least initially)
JavaScript
4
star
61

voxelite

Q: What if Minecraft but every pixel was a voxel? A: Worse performance, probably.
JavaScript
4
star
62

choon.js

๐ŸŽน Choon language interpreter in javascript with the Web Audio API.
JavaScript
3
star
63

rtttl.js

๐ŸŽน Parse and play RTTTL
JavaScript
3
star
64

polywogg

๐Ÿธโš”๐ƒ‰๐‘™ช๐Ÿ—ก๐‘™ฌ๐Ÿคบ
TypeScript
3
star
65

ansi-art-thumbnailer

Thumbnail support for ANSI art files in file browsers
Python
3
star
66

ooplie

๐Ÿ“œโœ Program in English
JavaScript
3
star
67

whitebread

๐Ÿž๐ŸŒธ A surreal text adventure (early stages)
CoffeeScript
3
star
68

hacky-game

Crazy tech demo game thing with automagical LAN multiplayer
CoffeeScript
3
star
69

precorder

๐ŸŽ™ Record audio from the past โŒšโŒ›
CoffeeScript
3
star
70

alchemy

(not in development, not playable) click click click buy distill burn mix sell sell buy click drag sell wait sell wait sell
CoffeeScript
3
star
71

pool

๐ŸŽฑ A pool table simulation... where there's not enough friction
JavaScript
3
star
72

gif-maker

A gif making application.
CSS
3
star
73

laser

What if you could grab a laser? And swing around a laser emitter with it?
JavaScript
3
star
74

pipe-strip

๐Ÿ›‹๏ธ๐Ÿ‘จ๐Ÿ“ฐ๐Ÿซณ | ๐Ÿ›‹๏ธ๐Ÿ‘จ๐Ÿ—ž๏ธ๐Ÿ’ญโ” | ๐Ÿ’ฌโ€ผ๏ธ๐Ÿฑ๐Ÿšฌ
Python
3
star
75

organeq

๐Ÿ”ขโž—๐Ÿ”ข Plant a phantasmagorical mathematical syntax tree
CoffeeScript
2
star
76

une

๐ŸŒŒ 3D starmap and misc tools for a roleplaying game
JavaScript
2
star
77

cityship

๐Ÿšข{๐Ÿญ๐Ÿข๐Ÿ›}(๐Ÿ—) Cityship Designer 2017
CoffeeScript
2
star
78

look-around-you.go

Learning Golang - and you can too!
Go
2
star
79

IDE

DEPRECATED PROJECT IDEA (also (knowingly) BROKEN) - an experimental IDE - Cloud9 is nice: https://c9.io/
JavaScript
2
star
80

ahk.js

AutoHotkey as a node module
C#
2
star
81

prosperity

A drafting game about building fantasy cities
JavaScript
2
star
82

1bpp

one bit per pixel game
C++
2
star
83

translate-great

Translate web app UI inline (just an experiment! less than a day's work!)
JavaScript
2
star
84

transpairency

Pair two screenshots together to make a transparent one.
JavaScript
2
star
85

boxart

drag and drop 3d box art creator
JavaScript
2
star
86

pruzzle

a jigsaw puzzle that's rigged โ€” a rigsaw puzzle, if you will?
JavaScript
2
star
87

realistic-bird

#flappyjam game
CoffeeScript
2
star
88

delayed-casualty

โš” Fighting game with simple controls (early stages of development)
CoffeeScript
2
star
89

nw-gtk

Psuedo-GTK in NW.js with React and postcss-gtk
2
star
90

window-switcher

Switch between windows of the same app, or between apps, on Windows
AutoHotkey
2
star
91

journal

โœ’ A programmer's journal app (with nice typography, and WYSIWYG) - I HAVEN'T TRIED USING THIS YET even tho i made it like most of the way to where it should be useable
CoffeeScript
1
star
92

hackathon

Fluid spatially structured chat concept
CoffeeScript
1
star
93

heroestube-the-game

DEPRECATED GAME PROJECT IDEA - A parody of YouTube Heroes as a game (The whole YouTube Heroes thing fell out of the news cycle and mindspace, so this isn't worth building anymore, but what I did implement is still kinda funny imo; there's nothing to it, no depth, but just the basic idea of it that you can see)
CSS
1
star
94

nxt-ultrasonic-mouser

Use the NXT's ultrasonic sensor to control the mouse and thus games and things.
Python
1
star
95

columns

A silly #badboxart jam platformer (complete game)
CoffeeScript
1
star
96

BuildGraph

DEPRECATED PROJECT IDEA - A visual node-graph-based cascading build system
CoffeeScript
1
star
97

dove-police

Dove Police
CoffeeScript
1
star
98

dat-boi

๐Ÿธ here comes dat boi
CoffeeScript
1
star
99

nw-synergy

An nw.js interface to Synergy
CoffeeScript
1
star
100

stick-mangler

A game with stick physics, called Mangy Stick or something
CoffeeScript
1
star