cmdInterpreter: debug, loadgist, loadswarm, setproviderurl

pull/1/head
yann300 7 years ago
parent ae90c173c8
commit 96a751b165
  1. 56
      src/app.js
  2. 2
      src/app/panels/terminal.js
  3. 20
      src/lib/cmdInterpreter.js

@ -6,6 +6,7 @@ var yo = require('yo-yo')
var async = require('async')
var remixLib = require('remix-lib')
var EventManager = remixLib.EventManager
var swarmgw = require('swarmgw')
var UniversalDApp = require('./universal-dapp.js')
var UniversalDAppUI = require('./universal-dapp-ui.js')
@ -351,6 +352,42 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
})
txlistener.startListening()
// ----------------- Command Interpreter -----------------
/*
this module basically listen on user input (from terminal && editor)
and interpret them as commands
*/
var cmdInterpreter = new CommandInterpreter()
cmdInterpreter.event.register('debug', (hash) => {
startdebugging(hash)
})
cmdInterpreter.event.register('loadgist', (id) => {
loadFromGist({gist: id})
})
cmdInterpreter.event.register('loadswarm', (url) => {
swarmgw.get(url, function (err, ret) {
if (err) {
modalDialogCustom.log(`Unable to load ${url} from swarm: ${err}`)
} else {
ret = JSON.parse(ret)
for (var k in ret.sources) {
var url = ret.sources[k].urls[0] // @TODO retrieve all other content
swarmgw.get(url, (error, content) => {
if (!error) {
filesProviders['browser'].addReadOnly(k, content)
} else {
filesProviders['browser'].addReadOnly(k, `Cannot retrieve the content of ${url}: ${error}`)
}
})
}
}
})
})
cmdInterpreter.event.register('setproviderurl', (url) => {
executionContext.setContext('web3', url, true)
})
// ----------------- editor ----------------------------
this._components.editor = new Editor({}) // @TODO: put into editorpanel
var editor = self._components.editor // shortcut for the editor
@ -436,6 +473,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
// ----------------- editor panel ----------------------
this._components.editorpanel = new EditorPanel({
api: {
cmdInterpreter: cmdInterpreter,
editor: self._components.editor,
config: self._api.config,
txListener: txlistener,
@ -503,8 +541,8 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
}
// ------------------ gist load ----------------
var loadingFromGist = gistHandler.handleLoad(queryParams.get(), function (gistId) {
function loadFromGist (gistId) {
return gistHandler.handleLoad(gistId, function (gistId) {
$.ajax({
url: 'https://api.github.com/gists/' + gistId,
jsonp: 'callback',
@ -520,6 +558,9 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
}
})
})
}
var loadingFromGist = loadFromGist(queryParams.get())
// insert ballot contract if there are no files available
if (!loadingFromGist) {
@ -608,21 +649,10 @@ 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'

@ -71,8 +71,8 @@ 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}`)
if (self._api.cmdInterpreter && self._api.cmdInterpreter.interpret(script)) return
self._shell(script, scopedCommands, function (error, output) {
if (error) scopedCommands.error(error)
else scopedCommands.log(output)

@ -8,23 +8,15 @@ class CmdInterpreter {
}
interpret (cmd) {
if (!cmd) return false
for (var c in commands) {
if (commands[c].exec(cmd)) {
commands[c].action(this, cmd)
return true
var accept = commandsRegEx.exec(cmd)
if (accept) {
this.event.trigger(accept[1], [cmd.replace(commandsRegEx, '')])
return accept[1]
}
}
return false
return null
}
}
var commands = [
{
command: /^debug /,
action: (self, command) => {
self.event.trigger('debug', command.replace('debug ', ''))
}
}
]
var commandsRegEx = /^remix:(debug|loadgist|setproviderurl|loadswarm)\s/
module.exports = CmdInterpreter

Loading…
Cancel
Save