All Projects → 1j01 → Simple Console

1j01 / Simple Console

Licence: mit
Add an elegant command-line interface to any page

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Simple Console

Jquery.terminal
jQuery Terminal Emulator - JavaScript library for creating web-based terminals with custom commands
Stars: ✭ 2,623 (+2351.4%)
Mutual labels:  cli, command-line, command, console
Terjira
Terjira is a very interactive and easy to use CLI tool for Jira.
Stars: ✭ 713 (+566.36%)
Mutual labels:  command-line-app, cli, command-line
Cobra
A Commander for modern Go CLI interactions
Stars: ✭ 24,437 (+22738.32%)
Mutual labels:  cli, command-line, command
Tooling
Advancing Node.js as a framework for writing great tools
Stars: ✭ 98 (-8.41%)
Mutual labels:  cli, command-line, console
Php Console
🖥 PHP CLI application library, provide console argument parse, console controller/command run, color style, user interactive, format information show and more. 功能全面的PHP命令行应用库。提供控制台参数解析, 命令运行,颜色风格输出, 用户信息交互, 特殊格式信息显示
Stars: ✭ 310 (+189.72%)
Mutual labels:  cli, command-line, console
Tsukae
🧑‍💻📊 Show off your most used shell commands
Stars: ✭ 345 (+222.43%)
Mutual labels:  cli, command-line, command
Mprislyrics
Small command-line utility that displays lyrics in sync with the currently playing song in a MPRIS2 capable player.
Stars: ✭ 24 (-77.57%)
Mutual labels:  command-line-app, cli, command-line
Cliffy
NodeJS Framework for Interactive CLIs
Stars: ✭ 263 (+145.79%)
Mutual labels:  cli, command-line, command
Wonders
🌈 Declarative JavaScript framework to build command-line applications.
Stars: ✭ 34 (-68.22%)
Mutual labels:  cli, command-line, console
Crossline
A small, self-contained, zero-config, MIT licensed, cross-platform, readline and libedit replacement.
Stars: ✭ 53 (-50.47%)
Mutual labels:  cli, command-line, console
Rang
A Minimal, Header only Modern c++ library for terminal goodies 💄✨
Stars: ✭ 1,080 (+909.35%)
Mutual labels:  cli, command-line, console
Whatspup
🔳 WhatsApp chat from commandline/console/cli using GoogleChrome puppeteer
Stars: ✭ 310 (+189.72%)
Mutual labels:  cli, command-line, console
Consola
Elegant Console Logger for Node.js and Browser 🐨
Stars: ✭ 3,461 (+3134.58%)
Mutual labels:  cli, console, log
Cocona
Micro-framework for .NET Core console application. Cocona makes it easy and fast to build console applications on .NET Core.
Stars: ✭ 398 (+271.96%)
Mutual labels:  cli, command-line, console
Nestjs Console
A nestjs module that provide a cli to your application.
Stars: ✭ 284 (+165.42%)
Mutual labels:  cli, console, command
Aruba
Test command-line applications with Cucumber-Ruby, RSpec or Minitest. The most up to date documentation can be found on Cucumber.Pro (https://app.cucumber.pro/projects/aruba)
Stars: ✭ 900 (+741.12%)
Mutual labels:  cli, command-line, command
Pyinquirer
A Python module for common interactive command line user interfaces
Stars: ✭ 1,151 (+975.7%)
Mutual labels:  command-line-app, cli, command-line
Laravel Zero
A PHP framework for console artisans
Stars: ✭ 2,821 (+2536.45%)
Mutual labels:  cli, command-line, console
Executor
Watch for file changes and then execute command. Very nice for test driven development.
Stars: ✭ 14 (-86.92%)
Mutual labels:  cli, command-line, command
Signale
Highly configurable logging utility
Stars: ✭ 8,575 (+7914.02%)
Mutual labels:  cli, console, log

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].