Merge pull request #3 from philippdieter/main
Port some of my previous commits
This commit is contained in:
commit
54e997e88f
8
index.js
8
index.js
@ -6,6 +6,11 @@ const configure = (conn, defaultConsole) => {
|
|||||||
if (console._tsconsole_configured) return;
|
if (console._tsconsole_configured) return;
|
||||||
console._tsconsole_configured = true;
|
console._tsconsole_configured = true;
|
||||||
|
|
||||||
|
console.info = (...args) => {
|
||||||
|
sendWhenConnected(conn, JSON.stringify({ type: 'info', data: Array.from(args) , }), defaultConsole);
|
||||||
|
defaultConsole.info.apply(defaultConsole, args);
|
||||||
|
};
|
||||||
|
|
||||||
console.log = (...args) => {
|
console.log = (...args) => {
|
||||||
sendWhenConnected(conn, JSON.stringify({ type: 'log', data: Array.from(args) , }), defaultConsole);
|
sendWhenConnected(conn, JSON.stringify({ type: 'log', data: Array.from(args) , }), defaultConsole);
|
||||||
defaultConsole.log.apply(defaultConsole, args);
|
defaultConsole.log.apply(defaultConsole, args);
|
||||||
@ -49,8 +54,9 @@ const termlog = (options = {}) => {
|
|||||||
|
|
||||||
const ws = new WebSocket(`${options.ssl ? "wss" : "ws"}://${options.host}:${options.port}`);
|
const ws = new WebSocket(`${options.ssl ? "wss" : "ws"}://${options.host}:${options.port}`);
|
||||||
|
|
||||||
ws.onopen = () => {
|
|
||||||
configure(ws, defaultConsole);
|
configure(ws, defaultConsole);
|
||||||
|
|
||||||
|
ws.onopen = () => {
|
||||||
console.log('[TERMLOG]: Connected');
|
console.log('[TERMLOG]: Connected');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
14
server.js
14
server.js
@ -5,13 +5,14 @@ const repl = require('repl');
|
|||||||
|
|
||||||
const DEFAULT_HOST = "localhost";
|
const DEFAULT_HOST = "localhost";
|
||||||
const DEFAULT_PORT = 3456;
|
const DEFAULT_PORT = 3456;
|
||||||
|
const DEFAULT_PROMPT = "> ";
|
||||||
|
|
||||||
const CRed = "\x1b[31m";
|
const CRed = "\x1b[31m";
|
||||||
const CYellow = "\x1b[33m";
|
const CYellow = "\x1b[33m";
|
||||||
const CWhite = "\x1b[37m";
|
const CWhite = "\x1b[37m";
|
||||||
const CBlue = "\x1b[34m";
|
const CBlue = "\x1b[34m";
|
||||||
|
|
||||||
const LOGLEVELS = ['log', 'warn', 'error', 'debug'];
|
const LOGLEVELS = ['info', 'log', 'warn', 'error', 'debug'];
|
||||||
// global var keeping track of what to display
|
// global var keeping track of what to display
|
||||||
let SHOWLEVELS = LOGLEVELS;
|
let SHOWLEVELS = LOGLEVELS;
|
||||||
|
|
||||||
@ -31,6 +32,7 @@ const out = (data, color = CWhite) => {
|
|||||||
if (!Array.isArray(data)) data = [data];
|
if (!Array.isArray(data)) data = [data];
|
||||||
process.stdout.write(color);
|
process.stdout.write(color);
|
||||||
process.stdout.write(getTime() + " ");
|
process.stdout.write(getTime() + " ");
|
||||||
|
|
||||||
console.log.apply(console, data);
|
console.log.apply(console, data);
|
||||||
process.stdout.write(CWhite);
|
process.stdout.write(CWhite);
|
||||||
}
|
}
|
||||||
@ -135,9 +137,9 @@ const startServer = (options) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Start a node repl
|
// Start a node repl
|
||||||
const r = repl.start({prompt: "> "});
|
const r = repl.start({prompt: options.prompt});
|
||||||
r.defineCommand('show', {
|
r.defineCommand('show', {
|
||||||
help: '[TERMLOG] Select log levels to display (info | warning | error | debug). Multiple levels are seperated by `,`',
|
help: '[TERMLOG] Select log levels to display (info | log | warning | error | debug). Multiple levels are seperated by `,`',
|
||||||
action(arg) {
|
action(arg) {
|
||||||
const args = arg.split(",");
|
const args = arg.split(",");
|
||||||
applyShowFilter(args);
|
applyShowFilter(args);
|
||||||
@ -171,8 +173,11 @@ Options:
|
|||||||
--out arg
|
--out arg
|
||||||
Save output to file
|
Save output to file
|
||||||
|
|
||||||
|
--primpt arg
|
||||||
|
Sets promt, "" to disable
|
||||||
|
|
||||||
--show args
|
--show args
|
||||||
Select log levels to display (info | warning | error | debug). Multiple levels are seperated by \`,\`
|
Select log levels to display (info | log | warning | error | debug). Multiple levels are seperated by \`,\`
|
||||||
|
|
||||||
`);
|
`);
|
||||||
} else {
|
} else {
|
||||||
@ -183,6 +188,7 @@ Options:
|
|||||||
port: DEFAULT_PORT,
|
port: DEFAULT_PORT,
|
||||||
host:DEFAULT_HOST,
|
host:DEFAULT_HOST,
|
||||||
show: LOGLEVELS,
|
show: LOGLEVELS,
|
||||||
|
prompt: DEFAULT_PROMPT,
|
||||||
...args
|
...args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user