refactor console cmd exec

This commit is contained in:
Iuri Matias 2018-02-27 17:50:43 -05:00
parent eb6236da65
commit 531af6234b
2 changed files with 14 additions and 18 deletions

View File

@ -34,6 +34,10 @@ class Dashboard {
self.events.on('contractsState', monitor.setContracts); self.events.on('contractsState', monitor.setContracts);
self.events.on('status', monitor.setStatus.bind(monitor)); 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('========================'.bold.green);
self.logger.info(('Welcome to Embark ' + self.version).yellow.bold); self.logger.info(('Welcome to Embark ' + self.version).yellow.bold);
self.logger.info('========================'.bold.green); self.logger.info('========================'.bold.green);

View File

@ -344,30 +344,22 @@ class Dashboard {
self.input.focus(); self.input.focus();
}); });
this.input.on('submit', function (data) { this.input.on('submit', this.executeCmd.bind(this));
if (data !== '') {
self.history.addCommand(data); this.screen.append(this.consoleBox);
self.logText.log('console> '.bold.green + data); }
self.console.executeCmd(data, function (result) {
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); self.logText.log(result);
}); });
} }
self.input.clearValue(); self.input.clearValue();
self.input.focus(); 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);
} }
} }