console-io

14.1.0 • Public • Published

Console License NPM version

Web console used in Cloud Commander.

Console

Install

npm i console-io -g

Use as standalone

Start console, go to url http://localhost:1337

Hot keys

Key Operation
Ctrl + Z cancel input
Ctrl + L clear screen
Ctrl + C kill running task

For more details see Jq-console keyboard shortcuts.

API

Client API

Console(element [, options])

  • element - html element, or selector
  • options - (optional) {cwd}

When prefix set in server and client, you should use same prefix in html. For example, if you use prefix "any_prefix" you should connect console script in this way:

<script src="/any_prefix/console.js"></script>

addShortCuts(shortCuts)

  • shortCuts - object contain big letter and function.

Example: show alert on Ctrl + A:

async () => {
    const konsole = await Console();
    
    konsole.addShortCuts({
        A() {
            alert('hello');
        },
    });
};

getPromptText()

Get text of prompt.

setPromptText(text)

  • text - string of new text

Set new text of prompt.

focus()

Set focus on Console.

Server API

Console(options)

Could be used as middleware, or for init Console.

Console.listen(socket, {
    server, // when no socket
    online: true, // default
    prefix: '/console', // default
    prefixSocket: '/console', // default
    auth: (accept, reject) => (username, password) => {
        accept();
    },
});

Console.middle(options)

Middleware function if there is a need of init socket in another place.

Console({
    prefix: '/console', // default
    online: true, // default
});

Use as middleware

To use Console in your programs you should make local install:

npm i console-io express

And use it in your program

// server.js
const webconsole = require('console-io');
const http = require('http');
const express = require('express');

const app = express();
const server = http.createServer(app);

const port = 1337;
const ip = '0.0.0.0';

const online = true;
app
    .use(webconsole({
        server,
        online, // load jquery and socket.io from cdn
    }))
    .use(express.static(__dirname));

webconsole.listen({
    server,
});

server.listen(port, ip);
<!-- index.html -->

<div class="console"></div>
<script src="/console/console.js"></script>
<script>
    document.addEventListener('load', async () => {
        const konsole = await Console('.console', {
            prefix: 'console',
            env: {
                CURRENT_FILE: getCurrentFile(),
                CURRENT_APP: 'console-io'
            }
        });
        
        console.log('console ready')
        konsole.focus();
        
        function getCurrentFile() {
            return 'filename.txt';
        }
    });
</script>

License

MIT

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
14.1.0116latest

Version History

VersionDownloads (Last 7 Days)Published
14.1.0116
14.0.10
14.0.00
13.0.217
13.0.10
13.0.00
12.0.10
12.0.00
11.0.20
11.0.13
11.0.00
10.1.30
10.1.20
10.1.10
10.1.00
10.0.70
10.0.60
10.0.50
10.0.40
10.0.30
10.0.20
10.0.10
10.0.00
9.1.00
9.0.10
9.0.00
8.1.30
8.1.20
8.1.10
8.1.00
8.0.40
8.0.30
8.0.20
8.0.10
8.0.00
7.0.63
7.0.50
7.0.40
7.0.30
7.0.20
7.0.10
7.0.00
6.0.10
6.0.00
5.1.00
5.0.61
5.0.50
5.0.40
5.0.30
5.0.20
5.0.10
5.0.00
4.0.00
3.1.30
3.1.20
3.1.10
3.1.00
3.0.130
3.0.120
3.0.110
3.0.101
3.0.90
3.0.80
3.0.70
3.0.60
3.0.51
3.0.40
3.0.30
3.0.21
3.0.10
3.0.00
2.7.142
2.7.130
2.7.121
2.7.111
2.7.100
2.7.90
2.7.80
2.7.70
2.7.60
2.7.51
2.7.40
2.7.30
2.7.20
2.7.10
2.7.00
2.6.395
2.6.20
2.6.10
2.6.00
2.5.30
2.5.21
2.5.10
2.5.00
2.4.11
2.4.00
2.3.30
2.3.20
2.3.10
2.3.00
2.2.130
2.2.120
2.2.110
2.2.100
2.2.90
2.2.80
2.2.70
2.2.60
2.2.50
2.2.41
2.2.30
2.2.20
2.2.10
2.2.01
2.1.150
2.1.140
2.1.131
2.1.120
2.1.110
2.1.100
2.1.90
2.1.80
2.1.70
2.1.60
2.1.50
2.1.40
2.1.30
2.1.20
2.1.10
2.1.00
2.0.20
2.0.10
2.0.00
1.11.130
1.11.120
1.11.110
1.11.101
1.11.90
1.11.80
1.11.70
1.11.60
1.11.51
1.11.40
1.11.31
1.11.20
1.11.10
1.10.93
1.10.81
1.10.70
1.10.60
1.10.50
1.10.40
1.10.31
1.10.20
1.10.10
1.10.00
1.9.90
1.9.80
1.9.71
1.9.60
1.9.50
1.9.40
1.9.30
1.9.20
1.9.11
1.9.00
1.8.40
1.8.31
1.8.20
1.8.10
1.8.00
1.7.100
1.7.90
1.7.80
1.7.70
1.7.60
1.7.50
1.7.40
1.7.30
1.7.21
1.7.10
1.7.00
1.6.81
1.6.70
1.6.60
1.6.50
1.6.40
1.6.30
1.6.20
1.6.10
1.6.00
1.5.20
1.5.10
1.5.01
1.4.30
1.4.20
1.4.10
1.4.00
1.3.90
1.3.80
1.3.72
1.3.60
1.3.40
1.3.31
1.3.20
1.3.10
1.3.00
1.2.10
1.2.00
1.1.01
1.0.70
1.0.61
1.0.50
1.0.40
1.0.30
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i console-io

Weekly Downloads

267

Version

14.1.0

License

MIT

Unpacked Size

582 kB

Total Files

34

Last publish

Collaborators

  • coderaiser