Skip to content

Commit

Permalink
minor UX improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Oct 4, 2022
1 parent faf6acf commit 04901fe
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
4 changes: 2 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 🕺"
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
}
Expand Down
27 changes: 17 additions & 10 deletions src/extension/executors/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -26,10 +26,11 @@ async function taskExecutor(
doc: TextDocument
): Promise<boolean> {
/**
* 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)
}

Expand All @@ -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'
Expand All @@ -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<number>((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}`)
Expand All @@ -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)
})
})
Expand Down

0 comments on commit 04901fe

Please sign in to comment.