From eb6236da655a0e4b524a11256ff8b58300dd3dd0 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 27 Feb 2018 17:04:41 -0500 Subject: [PATCH] add command handler for console cmd --- lib/dashboard/console.js | 3 +++ lib/dashboard/dashboard.js | 2 +- lib/dashboard/monitor.js | 12 ++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/dashboard/console.js b/lib/dashboard/console.js index 907e9844..cdd58606 100644 --- a/lib/dashboard/console.js +++ b/lib/dashboard/console.js @@ -28,6 +28,9 @@ class Console { 'The web3 object and the interfaces for the deployed contracts and their methods are also available' ]; return helpText.join('\n'); + } else if (cmd === 'test') { + this.events.request("console:command", "help", () => {}); + return "test"; } else if (['quit', 'exit', 'sair', 'sortir'].indexOf(cmd) >= 0) { utils.exit(); } diff --git a/lib/dashboard/dashboard.js b/lib/dashboard/dashboard.js index b0d04c8b..7815974b 100644 --- a/lib/dashboard/dashboard.js +++ b/lib/dashboard/dashboard.js @@ -28,7 +28,7 @@ class Dashboard { callback(); }, function startMonitor(callback) { - monitor = new Monitor({env: self.env, console: console}); + monitor = new Monitor({env: self.env, console: console, events: self.events}); self.logger.logFunction = monitor.logEntry; self.events.on('contractsState', monitor.setContracts); diff --git a/lib/dashboard/monitor.js b/lib/dashboard/monitor.js index 7b0dba2e..b311d2b4 100644 --- a/lib/dashboard/monitor.js +++ b/lib/dashboard/monitor.js @@ -7,6 +7,7 @@ class Dashboard { this.env = options.env; this.console = options.console; this.history = new CommandHistory(); + this.events = options.events; this.color = options.color || "green"; this.minimal = options.minimal || false; @@ -355,6 +356,17 @@ class Dashboard { self.input.focus(); }); + // TODO: can put cmd exe code into its own method, then set this handler + // outside this + this.events.setCommandHandler("console:command", (cmd, cb) => { + self.history.addCommand(cmd); + self.logText.log('console> '.bold.green + cmd); + self.console.executeCmd(cmd, function (result) { + self.logText.log(result); + cb(result); + }); + }); + this.screen.append(this.consoleBox); }