Merge pull request #1414 from ethereum/fixTerminalInterpreter

use proper javascript object for scripting
pull/3094/head
yann300 6 years ago committed by GitHub
commit 6a4b5133e1
  1. 8
      .circleci/config.yml
  2. 4
      src/app/panels/editor-panel.js
  3. 4
      src/app/panels/terminal.js
  4. 27
      src/lib/cmdInterpreter.js
  5. 18
      src/lib/cmdInterpreterAPI.js

@ -26,10 +26,10 @@ jobs:
- checkout
- restore_cache:
keys:
- dep-bundle-13-{{ checksum "package.json" }}
- dep-bundle-14-{{ checksum "package.json" }}
- run: npm install
- save_cache:
key: dep-bundle-13-{{ checksum "package.json" }}
key: dep-bundle-14-{{ checksum "package.json" }}
paths:
- ~/repo/node_modules
- run: npm run lint && npm run test && npm run downloadsolc && npm run make-mock-compiler && npm run build
@ -46,10 +46,10 @@ jobs:
- checkout
- restore_cache:
keys:
- dep-bundle-8-{{ checksum "package.json" }}
- dep-bundle-9-{{ checksum "package.json" }}
- run: npm install
- save_cache:
key: dep-bundle-8-{{ checksum "package.json" }}
key: dep-bundle-9-{{ checksum "package.json" }}
paths:
- ~/repo/node_modules
- run: npm run build_debugger

@ -7,7 +7,6 @@ var Terminal = require('./terminal')
var Editor = require('../editor/editor')
var globalRegistry = require('../../global/registry')
var CommandInterpreter = require('../../lib/cmdInterpreter')
var ContextualListener = require('../editor/contextualListener')
var ContextView = require('../editor/contextView')
var styles = require('./styles/editor-panel-styles')
@ -47,8 +46,7 @@ class EditorPanel {
contextualListener: contextualListener,
contextView: new ContextView({contextualListener: contextualListener, editor: editor}),
terminal: new Terminal({
udapp: self._deps.udapp,
cmdInterpreter: new CommandInterpreter()
udapp: self._deps.udapp
},
{
getPosition: (event) => {

@ -8,6 +8,7 @@ var remixLib = require('remix-lib')
var EventManager = remixLib.EventManager
var Web3 = require('web3')
var CommandInterpreterAPI = require('../../lib/cmdInterpreterAPI')
var executionContext = require('../../execution-context')
var Dropdown = require('../ui/dropdown')
@ -37,6 +38,7 @@ class Terminal {
}
self._view = { el: null, bar: null, input: null, term: null, journal: null, cli: null }
self._components = {}
self._components.cmdInterpreter = new CommandInterpreterAPI(this)
self._components.dropdown = new Dropdown({
options: [
'only remix transactions',
@ -74,7 +76,6 @@ class Terminal {
self.registerCommand('script', function execute (args, scopedCommands, append) {
var script = String(args[0])
scopedCommands.log(`> ${script}`)
if (self._opts.cmdInterpreter && self._opts.cmdInterpreter.interpret(script)) return
self._shell(script, scopedCommands, function (error, output) {
if (error) scopedCommands.error(error)
else scopedCommands.log(output)
@ -561,6 +562,7 @@ class Terminal {
function domTerminalFeatures (self, scopedCommands) {
return {
remix: self._components.cmdInterpreter,
web3: executionContext.getProvider() !== 'vm' ? new Web3(executionContext.web3().currentProvider) : null,
console: {
log: function () { scopedCommands.log.apply(scopedCommands, arguments) },

@ -1,27 +0,0 @@
'use strict'
var remixLib = require('remix-lib')
var EventManager = remixLib.EventManager
var CommandInterpreterAPI = require('./cmdInterpreterAPI')
class CmdInterpreter {
constructor () {
this.event = new EventManager()
this.api = new CommandInterpreterAPI(this)
}
interpret (cmd, cb) {
if (!cmd) return false
var accept = commandsRegEx.exec(cmd)
if (accept) {
var param = accept[2]
if (param) param = param.trim()
this.api[accept[1]](param, cb)
return accept[1]
}
return null
}
}
var commandsRegEx = /^remix:(debug|loadgist|setproviderurl|loadurl|batch)(.*)/
module.exports = CmdInterpreter

@ -8,12 +8,12 @@ var toolTip = require('../app/ui/tooltip')
var globalRegistry = require('../global/registry')
class CmdInterpreterAPI {
constructor (cmdInterpreter, localRegistry) {
constructor (terminal, localRegistry) {
const self = this
self.event = new EventManager()
self._components = {}
self._components.registry = localRegistry || globalRegistry
self._components.cmdInterpreter = cmdInterpreter
self._components.terminal = terminal
self._deps = {
app: self._components.registry.get('app').api,
editor: self._components.registry.get('editor').api
@ -60,7 +60,7 @@ class CmdInterpreterAPI {
if (cb) cb()
})
}
batch (url, cb) {
exeCurrent (cb) {
const self = this
var content = self._deps.editor.currentContent()
if (!content) {
@ -68,17 +68,7 @@ class CmdInterpreterAPI {
if (cb) cb()
return
}
var split = content.split('\n')
async.eachSeries(split, (value, cb) => {
if (!self._components.cmdInterpreter.interpret(value, (error) => {
error ? cb(`Cannot run ${value}. stopping`) : cb()
})) {
cb(`Cannot interpret ${value}. stopping`)
}
}, (error) => {
if (error) toolTip(error)
if (cb) cb()
})
self._components.terminal.commands.script(content)
}
}

Loading…
Cancel
Save