From ae90c173c8432cef6f6b05562ef66cbb5f2fba56 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 20 Sep 2017 14:13:19 +0200 Subject: [PATCH] add cmdinterpreter --- src/app.js | 14 +++++++++++++- src/app/panels/editor-panel.js | 1 + src/app/panels/terminal.js | 1 + src/lib/cmdInterpreter.js | 30 ++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/lib/cmdInterpreter.js diff --git a/src/app.js b/src/app.js index 02096d324c..1b51dffdc5 100644 --- a/src/app.js +++ b/src/app.js @@ -40,6 +40,7 @@ var ContextualListener = require('./app/editor/contextualListener') var ContextView = require('./app/editor/contextView') var BasicReadOnlyExplorer = require('./app/files/basicReadOnlyExplorer') var toolTip = require('./app/ui/tooltip') +var CommandInterpreter = require('./lib/cmdInterpreter') var styleGuide = remixLib.ui.themeChooser var styles = styleGuide.chooser() @@ -204,7 +205,7 @@ function run () { var self = this if (window.location.hostname === 'yann300.github.io') { - modalDialogCustom.alert(`This UNSTABLE ALPHA branch of Remix has been moved to http://ethereum.github.io/remix-live-alpha.`) + modalDialogCustom.alert('This UNSTABLE ALPHA branch of Remix has been moved to http://ethereum.github.io/remix-live-alpha.') } else if (window.location.hostname === 'ethereum.github.io' && window.location.pathname.indexOf('/remix-live-alpha') === 0) { modalDialogCustom.alert(`This instance of the Remix IDE is an UNSTABLE ALPHA branch.\n @@ -607,10 +608,21 @@ Please make a backup of your contracts and start using http://remix.ethereum.org } var staticanalysis = new StaticAnalysis(staticAnalysisAPI, compiler.event) + // ----------------- Command Interpreter ----------------- + /* + this module basically listen on user input (from terminal && editor) + and interpret them as command + */ + var cmdInterpreter = new CommandInterpreter() + cmdInterpreter.event.register('debug', (hash) => { + startdebugging(hash) + }) + // ---------------- Righthand-panel -------------------- var rhpAPI = { config: config, + cmdInterpreter: cmdInterpreter, setEditorSize (delta) { $('#righthand-panel').css('width', delta) self._view.centerpanel.style.right = delta + 'px' diff --git a/src/app/panels/editor-panel.js b/src/app/panels/editor-panel.js index 9c7cb19ab1..ac93a5c0ab 100644 --- a/src/app/panels/editor-panel.js +++ b/src/app/panels/editor-panel.js @@ -27,6 +27,7 @@ class EditorPanel { editor: opts.api.editor, // @TODO: instantiate in eventpanel instead of passing via `opts` terminal: new Terminal({ api: { + cmdInterpreter: self._api.cmdInterpreter, getPosition (event) { var limitUp = 36 var limitDown = 20 diff --git a/src/app/panels/terminal.js b/src/app/panels/terminal.js index 0095b96704..32865d5ced 100644 --- a/src/app/panels/terminal.js +++ b/src/app/panels/terminal.js @@ -71,6 +71,7 @@ class Terminal { self.registerCommand('error', self._blocksRenderer('error'), { activate: true }) self.registerCommand('script', function execute (args, scopedCommands, append) { var script = String(args[0]) + if (self._api.cmdInterpreter && self._api.cmdInterpreter.interpret(script)) return scopedCommands.log(`> ${script}`) self._shell(script, scopedCommands, function (error, output) { if (error) scopedCommands.error(error) diff --git a/src/lib/cmdInterpreter.js b/src/lib/cmdInterpreter.js new file mode 100644 index 0000000000..39a032d0c4 --- /dev/null +++ b/src/lib/cmdInterpreter.js @@ -0,0 +1,30 @@ +'use strict' +var remix = require('ethereum-remix') +var EventManager = remix.lib.EventManager + +class CmdInterpreter { + constructor () { + this.event = new EventManager() + } + interpret (cmd) { + if (!cmd) return false + for (var c in commands) { + if (commands[c].exec(cmd)) { + commands[c].action(this, cmd) + return true + } + } + return false + } +} + +var commands = [ + { + command: /^debug /, + action: (self, command) => { + self.event.trigger('debug', command.replace('debug ', '')) + } + } +] + +module.exports = CmdInterpreter