diff --git a/lib/dashboard/dashboard.js b/lib/dashboard/dashboard.js index 7815974b6..7dfda8f2c 100644 --- a/lib/dashboard/dashboard.js +++ b/lib/dashboard/dashboard.js @@ -34,6 +34,10 @@ class Dashboard { self.events.on('contractsState', monitor.setContracts); self.events.on('status', monitor.setStatus.bind(monitor)); + self.events.setCommandHandler("console:command", (cmd, cb) => { + cb(monitor.executeCmd(cmd)); + }); + self.logger.info('========================'.bold.green); self.logger.info(('Welcome to Embark ' + self.version).yellow.bold); self.logger.info('========================'.bold.green); diff --git a/lib/dashboard/monitor.js b/lib/dashboard/monitor.js index b311d2b4c..7edeeaf61 100644 --- a/lib/dashboard/monitor.js +++ b/lib/dashboard/monitor.js @@ -344,30 +344,22 @@ class Dashboard { self.input.focus(); }); - this.input.on('submit', function (data) { - if (data !== '') { - self.history.addCommand(data); - self.logText.log('console> '.bold.green + data); - self.console.executeCmd(data, function (result) { - self.logText.log(result); - }); - } - self.input.clearValue(); - self.input.focus(); - }); + this.input.on('submit', this.executeCmd.bind(this)); - // TODO: can put cmd exe code into its own method, then set this handler - // outside this - this.events.setCommandHandler("console:command", (cmd, cb) => { + this.screen.append(this.consoleBox); + } + + executeCmd(cmd) { + const self = this; + if (cmd !== '') { 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); + } + self.input.clearValue(); + self.input.focus(); } }