From 410dc45648646896f935e21b630f7f0804e37601 Mon Sep 17 00:00:00 2001 From: "davidzagi93@gmail.com" Date: Tue, 17 Aug 2021 13:45:15 +0100 Subject: [PATCH] feat: uncomment and implemented loadgist --- libs/remix-ui/terminal/src/lib/commands.ts | 2 +- libs/remix-ui/terminal/src/lib/remix-ui-terminal.tsx | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libs/remix-ui/terminal/src/lib/commands.ts b/libs/remix-ui/terminal/src/lib/commands.ts index 3e4a01e646..a2e85f5b07 100644 --- a/libs/remix-ui/terminal/src/lib/commands.ts +++ b/libs/remix-ui/terminal/src/lib/commands.ts @@ -9,7 +9,7 @@ export const allCommands = [ // { 'remix.execute(filepath)': 'Run the script specified by file path. If filepath is empty, script currently displayed in the editor is executed.' }, { 'remix.exeCurrent()': 'Run the script currently displayed in the editor.' }, // { 'remix.help()': 'Display this help message.' }, - // { 'remix.loadgist(id)': 'Load a gist in the file explorer.' }, + { 'remix.loadgist(id)': 'Load a gist in the file explorer.' }, // { 'remix.loadurl(url)': 'Load the given url in the file explorer. The url can be of type github, swarm or ipfs.' }, // { 'swarmgw.get(url, cb)': 'Download files from Swarm via https://swarm-gateways.net/' }, diff --git a/libs/remix-ui/terminal/src/lib/remix-ui-terminal.tsx b/libs/remix-ui/terminal/src/lib/remix-ui-terminal.tsx index 45fdfea909..942d3f4439 100644 --- a/libs/remix-ui/terminal/src/lib/remix-ui-terminal.tsx +++ b/libs/remix-ui/terminal/src/lib/remix-ui-terminal.tsx @@ -169,6 +169,12 @@ export const RemixUiTerminal = (props: RemixUiTerminalProps) => { return '' } + function loadgist (id, cb) { + console.log('load gist') + props.gistHandler.loadFromGist({ gist: id }, props._deps.fileManager) + if (cb) cb() + } + const _shell = async (script, scopedCommands, done) => { // default shell if (script.indexOf('remix:') === 0) { return done(null, 'This type of command has been deprecated and is not functionning anymore. Please run remix.help() to list available commands.') @@ -176,7 +182,7 @@ export const RemixUiTerminal = (props: RemixUiTerminalProps) => { if (script.indexOf('remix.') === 0) { // we keep the old feature. This will basically only be called when the command is querying the "remix" object. // for all the other case, we use the Code Executor plugin - const context = { remix: { exeCurrent: () => { return execute(undefined, undefined) } } } + const context = { remix: { exeCurrent: () => { return execute(undefined, undefined) }, loadgist: () => { return loadgist(script, undefined) } } } try { const cmds = vm.createContext(context) const result = vm.runInContext(script, cmds)