Skip to content

Commit

Permalink
Merge pull request #1414 from ethereum/fixTerminalInterpreter
Browse files Browse the repository at this point in the history
use proper javascript object for scripting
  • Loading branch information
yann300 authored Jul 16, 2018
2 parents c745cdb + 01f0df4 commit 6fdf001
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 49 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/app/panels/editor-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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) => {
Expand Down
4 changes: 3 additions & 1 deletion src/app/panels/terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) },
Expand Down
27 changes: 0 additions & 27 deletions src/lib/cmdInterpreter.js

This file was deleted.

18 changes: 4 additions & 14 deletions src/lib/cmdInterpreterAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -60,25 +60,15 @@ class CmdInterpreterAPI {
if (cb) cb()
})
}
batch (url, cb) {
exeCurrent (cb) {
const self = this
var content = self._deps.editor.currentContent()
if (!content) {
toolTip('no content to execute')
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)
}
}

Expand Down

0 comments on commit 6fdf001

Please sign in to comment.