fix(cockpit/console): fix cockpit's console outputting "console >"

This commit is contained in:
Jonathan Rainville 2019-03-13 15:20:06 -04:00 committed by Iuri Matias
parent 785edf4c9d
commit 22e771bbda
7 changed files with 22 additions and 10 deletions

View File

@ -346,7 +346,9 @@ class EmbarkController {
new REPL({
events: engine.events,
env: engine.env,
ipc: engine.ipc
ipc: engine.ipc,
useDashboard: false,
logger: engine.logger
}).start(callback);
}
], function (err, _result) {

View File

@ -25,7 +25,7 @@ class Dashboard {
start(done) {
let monitor;
monitor = new Monitor({env: this.env, events: this.events, version: this.version, ipc: this.ipc});
monitor = new Monitor({env: this.env, events: this.events, version: this.version, ipc: this.ipc, logger: this.logger});
this.logger.logFunction = monitor.logEntry;
let plugin = this.plugins.createPlugin('dashboard', {});
plugin.registerAPICall(

View File

@ -9,6 +9,7 @@ class Monitor {
this.env = options.env;
this.console = options.console;
this.events = options.events;
this.logger = options.logger;
this.color = options.color || "green";
this.minimal = options.minimal || false;
this.ipc = options.ipc;
@ -56,7 +57,9 @@ class Monitor {
inputStream: this.terminalReadableStream,
outputStream: terminalWritableStream,
logText: this.logText,
ipc: this.ipc
ipc: this.ipc,
useDashboard: true,
logger: this.logger
}).start(() => {
this.terminal.focus();
});

View File

@ -9,6 +9,8 @@ class REPL {
this.outputStream = options.outputStream || process.stdout;
this.logText = options.logText;
this.ipc = options.ipc;
this.logger = options.logger;
this.useDashboard = options.useDashboard;
}
addHistory(cmd) {
@ -19,6 +21,9 @@ class REPL {
}
enhancedEval(cmd, context, filename, callback) {
if (this.useDashboard) {
this.logger.consoleOnly("console> ".cyan + cmd.white);
}
this.events.request('console:executeCmd', cmd.trim(), function (err, message) {
if (err) {
// Do not return as the first param (error), because the dashboard doesn't print errors

View File

@ -176,8 +176,7 @@ class Engine {
version: this.version,
ipc: this.ipc,
logger: this.logger,
config: this.config,
useDashboard: this.useDashboard
config: this.config
});
}

View File

@ -126,6 +126,14 @@ Logger.prototype.info = function () {
this.writeToFile("[info]: ", ...arguments);
};
Logger.prototype.consoleOnly = function () {
if (!arguments.length || !(this.shouldLog('info'))) {
return;
}
this.logFunction(...Array.from(arguments), 'green');
this.writeToFile("[consoleOnly]: ", ...arguments);
};
Logger.prototype.debug = function () {
if (!arguments.length || !(this.shouldLog('debug'))) {
return;

View File

@ -30,7 +30,6 @@ class Console {
private cmdHistoryFile: string;
private suggestions?: Suggestions;
private providerReady: boolean;
private useDashboard: boolean;
constructor(embark: Embark, options: any) {
this.embark = embark;
@ -41,7 +40,6 @@ class Console {
this.fs = embark.fs;
this.ipc = options.ipc;
this.config = options.config;
this.useDashboard = options.useDashboard;
this.history = [];
this.cmdHistoryFile = options.cmdHistoryFile || this.fs.dappPath(".embark", "cmd_history");
this.providerReady = false;
@ -153,9 +151,6 @@ class Console {
return this.ipc.request("console:executeCmd", cmd, callback);
}
if (this.useDashboard) {
this.logger.info("console > ".cyan + cmd.white);
}
if (!(cmd.split(" ")[0] === "history" || cmd === __("history"))) {
this.saveHistory(cmd);
}