add cmdinterpreter

pull/1/head
yann300 7 years ago
parent 359c4d2eca
commit ae90c173c8
  1. 14
      src/app.js
  2. 1
      src/app/panels/editor-panel.js
  3. 1
      src/app/panels/terminal.js
  4. 30
      src/lib/cmdInterpreter.js

@ -40,6 +40,7 @@ var ContextualListener = require('./app/editor/contextualListener')
var ContextView = require('./app/editor/contextView') var ContextView = require('./app/editor/contextView')
var BasicReadOnlyExplorer = require('./app/files/basicReadOnlyExplorer') var BasicReadOnlyExplorer = require('./app/files/basicReadOnlyExplorer')
var toolTip = require('./app/ui/tooltip') var toolTip = require('./app/ui/tooltip')
var CommandInterpreter = require('./lib/cmdInterpreter')
var styleGuide = remixLib.ui.themeChooser var styleGuide = remixLib.ui.themeChooser
var styles = styleGuide.chooser() var styles = styleGuide.chooser()
@ -204,7 +205,7 @@ function run () {
var self = this var self = this
if (window.location.hostname === 'yann300.github.io') { 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' && } else if (window.location.hostname === 'ethereum.github.io' &&
window.location.pathname.indexOf('/remix-live-alpha') === 0) { window.location.pathname.indexOf('/remix-live-alpha') === 0) {
modalDialogCustom.alert(`This instance of the Remix IDE is an UNSTABLE ALPHA branch.\n 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) 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 -------------------- // ---------------- Righthand-panel --------------------
var rhpAPI = { var rhpAPI = {
config: config, config: config,
cmdInterpreter: cmdInterpreter,
setEditorSize (delta) { setEditorSize (delta) {
$('#righthand-panel').css('width', delta) $('#righthand-panel').css('width', delta)
self._view.centerpanel.style.right = delta + 'px' self._view.centerpanel.style.right = delta + 'px'

@ -27,6 +27,7 @@ class EditorPanel {
editor: opts.api.editor, // @TODO: instantiate in eventpanel instead of passing via `opts` editor: opts.api.editor, // @TODO: instantiate in eventpanel instead of passing via `opts`
terminal: new Terminal({ terminal: new Terminal({
api: { api: {
cmdInterpreter: self._api.cmdInterpreter,
getPosition (event) { getPosition (event) {
var limitUp = 36 var limitUp = 36
var limitDown = 20 var limitDown = 20

@ -71,6 +71,7 @@ class Terminal {
self.registerCommand('error', self._blocksRenderer('error'), { activate: true }) self.registerCommand('error', self._blocksRenderer('error'), { activate: true })
self.registerCommand('script', function execute (args, scopedCommands, append) { self.registerCommand('script', function execute (args, scopedCommands, append) {
var script = String(args[0]) var script = String(args[0])
if (self._api.cmdInterpreter && self._api.cmdInterpreter.interpret(script)) return
scopedCommands.log(`> ${script}`) scopedCommands.log(`> ${script}`)
self._shell(script, scopedCommands, function (error, output) { self._shell(script, scopedCommands, function (error, output) {
if (error) scopedCommands.error(error) if (error) scopedCommands.error(error)

@ -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
Loading…
Cancel
Save