Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/christianmalek/stupid-console.js
A very simplistic console-like component for websites
https://github.com/christianmalek/stupid-console.js
Last synced: about 4 hours ago
JSON representation
A very simplistic console-like component for websites
- Host: GitHub
- URL: https://github.com/christianmalek/stupid-console.js
- Owner: christianmalek
- License: mit
- Created: 2015-04-17T11:50:07.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-22T09:47:00.000Z (over 7 years ago)
- Last Synced: 2023-08-12T06:37:00.116Z (about 1 year ago)
- Language: JavaScript
- Size: 35.2 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![](stupidconsole.png)
# stupid-console.js
A very simplistic console-like component for websites e.g. to create creative about-pages.## Features
- History with *Arrow-Up* and *Arrow-Down*
- Scrollable
- Multi Instance Support
- Left-and-right Cursor Navigation
- Command register functionIf you have any wishes or ideas, let me know!
## Setup
You need to include following files:
- `stupid-console.js`
- `stupid-console.css`
- You also need [jQuery 2.X](https://jquery.com/download/)### Example
That's our `index.html` file:
```html
```
And that's the `example.js` file:
```js$(document).ready(function () {
'use strict';//pass the ID selector and instantiate a new console
var sc = new StupidConsole("#my-console");
//set default line beginning text
sc.setDefaultText("foo@bar: $ ");
//called function when no matching command got found
sc.setErrorCallback(function (args) {
sc.addNewLine("Invalid command. Type in "help" to see all commands.");
});
//registers click and key handlers, mandatory to use stupid-console.js!
sc.init();//the register function registers functions.
//the parameters are NAME, CALLBACK FN, (optional) DESCRIPTION
sc.register("help", function () {
var commands = sc.commandRegistry.commands;for (var cmd in commands) {
if (commands.hasOwnProperty(cmd)) {
var description = commands[cmd].description;
description = (description === "" ? "n/a" : description);
sc.addNewLine(cmd + ": " + description, false);
}
}
}, "Shows all registered commands");
sc.register("history", function (args) {
switch (args[0]) {
case "-show":
var history = sc.history.history;
for (var i = 0; i < history.length; i++) {
sc.addNewLine(history[i], false);
}
break;
case "-clear":
sc.history.clear();
break;
}
}, "-show: shows history, -clear: deletes history");
});```