From 04901fe5f5e72554c1e60c58974ac894b4a1a7b6 Mon Sep 17 00:00:00 2001 From: Christian Bromann Date: Tue, 4 Oct 2022 11:27:05 -0700 Subject: [PATCH] minor UX improvements --- examples/README.md | 4 ++-- package.json | 6 +++--- src/extension/executors/task.ts | 27 +++++++++++++++++---------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/examples/README.md b/examples/README.md index b22ba0695..298ae391a 100644 --- a/examples/README.md +++ b/examples/README.md @@ -10,11 +10,11 @@ This markdown file contains some custom examples to test the execution within a ## Shell Executions ```sh -echo "Hello World" +echo "Hello World!" ``` ## More Shell -```sh { inline=true } +```sh { interactive=false } echo "Foo 👀" sleep 2 echo "Bar 🕺" diff --git a/package.json b/package.json index 4ce864897..f1c8d633d 100644 --- a/package.json +++ b/package.json @@ -84,11 +84,11 @@ { "title": "Runme", "properties": { - "runme.shell.runinline": { + "runme.shell.interactive": { "type": "boolean", "scope": "machine", - "default": false, - "markdownDescription": "Run Shell scripts inline rather than as VS Code task." + "default": true, + "markdownDescription": "If set to `true` all shell scripts are run as interactive VS Code tasks, if set to `false` they are executed within the kernel and output is set in resulting cell." } } } diff --git a/src/extension/executors/task.ts b/src/extension/executors/task.ts index 7bf70098b..02a9936d1 100644 --- a/src/extension/executors/task.ts +++ b/src/extension/executors/task.ts @@ -12,9 +12,9 @@ import { sh as inlineSh } from './shell' const LABEL_LIMIT = 15 -export function closeTerminalByScript (script: string) { +export function closeTerminalByScript () { const terminal = window.terminals.find((t) => ( - t.creationOptions as TerminalOptions).shellArgs?.includes(script)) + t.creationOptions as TerminalOptions).env?.RUNME_TASK) if (terminal) { terminal.hide() } @@ -26,10 +26,11 @@ async function taskExecutor( doc: TextDocument ): Promise { /** - * run shell inline if set as configuration + * run as non interactive shell script if set as configuration or annotated + * in markdown section */ const config = workspace.getConfiguration('runme') - if (config.get('shell.runinline') || exec.cell.metadata.attributes?.inline === 'true') { + if (!config.get('shell.interactive') || exec.cell.metadata.attributes?.interactive === 'false') { return inlineSh(context, exec, doc) } @@ -48,7 +49,9 @@ async function taskExecutor( : cellText, 'exec', new ShellExecution(scriptFile.path, { - cwd: path.dirname(doc.uri.path) + cwd: path.dirname(doc.uri.path), + // eslint-disable-next-line @typescript-eslint/naming-convention + env: { RUNME_TASK: 'true' } }), ) const isBackground = exec.cell.metadata.attributes?.['background'] === 'true' @@ -59,16 +62,14 @@ async function taskExecutor( reveal: isBackground ? TaskRevealKind.Always : TaskRevealKind.Always, panel: isBackground ? TaskPanelKind.Dedicated : TaskPanelKind.Shared } - if (isBackground) { - await commands.executeCommand('workbench.action.terminal.clear') - } + await commands.executeCommand('workbench.action.terminal.clear') const execution = await tasks.executeTask(taskExecution) const p = new Promise((resolve) => { exec.token.onCancellationRequested(() => { try { execution.terminate() - closeTerminalByScript(scriptFile.path) + closeTerminalByScript() resolve(0) } catch (err: any) { console.error(`[Runme] Failed to terminate task: ${(err as Error).message}`) @@ -95,7 +96,13 @@ async function taskExecutor( return } - closeTerminalByScript(scriptFile.path) + /** + * only close terminal if execution passed + */ + if (e.exitCode === 0) { + closeTerminalByScript() + } + return resolve(e.exitCode) }) })