diff --git a/src/app/panels/editor-panel.js b/src/app/panels/editor-panel.js index 29640d36ba..db984e2e27 100644 --- a/src/app/panels/editor-panel.js +++ b/src/app/panels/editor-panel.js @@ -100,7 +100,8 @@ class EditorPanel { self._components.contextView = contextView self._components.terminal = new Terminal({ udapp: self._deps.udapp, - compilers: {} + appStore: self.appStore, + appManager: self.appManager }, { getPosition: (event) => { diff --git a/src/app/panels/terminal.js b/src/app/panels/terminal.js index b881d88ab8..a63c33bbf3 100644 --- a/src/app/panels/terminal.js +++ b/src/app/panels/terminal.js @@ -17,6 +17,7 @@ var AutoCompletePopup = require('../ui/auto-complete-popup') var csjs = require('csjs-inject') var css = require('./styles/terminal-styles') +import { ApiFactory } from 'remix-plugin' var packageV = require('../../../package.json') @@ -26,8 +27,9 @@ function register (api) { KONSOLES.push(api) } var ghostbar = yo`
` -class Terminal { +class Terminal extends ApiFactory { constructor (opts, api) { + super() var self = this self.event = new EventManager() self._api = api @@ -62,12 +64,12 @@ class Terminal { self.updateJournal({ type: 'select', value: label }) } }) - self._components.autoCompletePopup = new AutoCompletePopup() + self._components.autoCompletePopup = new AutoCompletePopup(self._opts) self._components.autoCompletePopup.event.register('handleSelect', function (input) { let textList = self._view.input.innerText.split(' ') textList.pop() textList.push(input) - self._view.input.innerText = `${textList}`.replace(/,/g, ' ') + self._view.input.innerText = textList self._view.input.focus() self.putCursor2End(self._view.input) }) @@ -103,14 +105,27 @@ class Terminal { self._jsSandboxContext = {} self._jsSandboxRegistered = {} + + self.externalApi = this.api() + opts.appManager.init([self.externalApi]) + opts.appManager.activateRequestAndNotification(self.externalApi) + if (opts.shell) self._shell = opts.shell register(self) } - focus () { if (this._view.input) this._view.input.focus() } - + get profile () { + return { + displayName: 'terminal', + name: 'terminal', + methods: [], + events: [], + description: ' - ', + required: false + } + } render () { var self = this if (self._view.el) return self._view.el @@ -649,7 +664,6 @@ class Terminal { function domTerminalFeatures (self, scopedCommands) { return { - compilers: self._opts.compilers, swarmgw, ethers, remix: self._components.cmdInterpreter, diff --git a/src/app/ui/auto-complete-popup.js b/src/app/ui/auto-complete-popup.js index 66ffc5858e..c88d2a6b3a 100644 --- a/src/app/ui/auto-complete-popup.js +++ b/src/app/ui/auto-complete-popup.js @@ -23,8 +23,9 @@ class AutoCompletePopup { var self = this self.event = new EventManager() self.isOpen = false + self.opts = opts self.data = { - _options: opts.options || [] + _options: [] } self._components = { modal: null @@ -33,7 +34,9 @@ class AutoCompletePopup { self._startingElement = 0 self._elementsToShow = 4 self._selectedElement = 0 + this.extraCommands = [] this.render() + this.extendAutocompletion() } render () { @@ -161,6 +164,12 @@ class AutoCompletePopup { }) } }) + this.extraCommands.forEach(item => { + let command = getKeyOf(item) + if (command.includes(autoCompleteInput.trim())) { + this.data._options.push(item) + } + }) if (this.data._options.length === 1 && event.which === 9) { // if only one option and tab is pressed, we resolve it @@ -188,6 +197,21 @@ class AutoCompletePopup { this._selectedElement = 0 yo.update(this._view, this.render()) } + + extendAutocompletion () { + // TODO: this is not using the appManager interface. Terminal should be put as module + this.opts.appStore.event.on('activate', (id) => { + let keyValue = {} + const profile = this.opts.appStore.getOne(id).profile + if (!profile.methods) return + profile.methods.forEach((method) => { + const key = `remix.call({name: '${id}', key:'${method}', payload: []}).then((result) => { console.log(result) }).catch((error) => { console.log(error) })` + keyValue[key] = `call ${id} - ${method}` + if (this.extraCommands.includes(keyValue)) return + this.extraCommands.push(keyValue) + }) + }) + } } function getKeyOf (item) { diff --git a/src/lib/cmdInterpreterAPI.js b/src/lib/cmdInterpreterAPI.js index 7f4e0716c9..a3e04f25c1 100644 --- a/src/lib/cmdInterpreterAPI.js +++ b/src/lib/cmdInterpreterAPI.js @@ -28,6 +28,7 @@ class CmdInterpreterAPI { offsetToLineColumnConverter: self._components.registry.get('offsettolinecolumnconverter').api } self.commandHelp = { + 'remix.call(message: {name, key, payload})': 'Call a registered plugins', 'remix.getFile(path)': 'Returns the content of the file located at the given path', 'remix.setFile(path, content)': 'set the content of the file located at the given path', 'remix.debug(hash)': 'Start debugging a transaction.', @@ -40,6 +41,9 @@ class CmdInterpreterAPI { 'remix.debugHelp()': 'Display help message for debugging' } } + async call (message) { + return await this._components.terminal.externalApi.request(message) + } log () { arguments[0] != null ? this._components.terminal.commands.html(arguments[0]) : this._components.terminal.commands.html(arguments[1]) } highlight (rawLocation) { var self = this