Skip to content

Commit

Permalink
Rewire stdio for non-interactive
Browse files Browse the repository at this point in the history
  • Loading branch information
sourishkrout committed Nov 22, 2024
1 parent b4dad17 commit a991d85
Show file tree
Hide file tree
Showing 14 changed files with 254 additions and 157 deletions.
5 changes: 4 additions & 1 deletion src/client/components/configuration/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ export class Annotations extends LitElement {
description: 'Run cell inside terminal to allow for interactive input.',
},
closeTerminalOnSuccess: {
description: 'Hide terminal after cell successful execution.',
description: 'Hide terminal panel after cell successful execution.',
},
openTerminalOnError: {
description: 'open terminal panel after cell execution error.',
},
promptEnv: {
description: 'Prompt user input for exported environment variables.',
Expand Down
43 changes: 25 additions & 18 deletions src/extension/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ export class NotebookCellOutputManager {
return new NotebookCellOutput([NotebookCellOutputItem.json(json, OutputType.vercel)])
}

case OutputType.outputItems:
case OutputType.terminal: {
const terminalState = this.terminalState
if (!terminalState) {
Expand Down Expand Up @@ -276,24 +275,32 @@ export class NotebookCellOutputManager {
'runme.dev/id': cellId,
},
)
} else {
const terminalStateBase64 = terminalState.serialize()
const json: CellOutputPayload<OutputType.outputItems> = {
type: OutputType.outputItems,
output: {
content: terminalStateBase64,
mime: 'text/plain',
id: cellId,
},
}
}
}

case OutputType.outputItems: {
const terminalState = this.terminalState
if (!terminalState) {
return
}

return new NotebookCellOutput([
NotebookCellOutputItem.json(json, OutputType.outputItems),
NotebookCellOutputItem.stdout(
Buffer.from(terminalStateBase64, 'base64').toString('utf-8'),
),
])
const { 'runme.dev/id': cellId } = getAnnotations(cell)
const terminalStateBase64 = terminalState.serialize()
const json: CellOutputPayload<OutputType.outputItems> = {
type: OutputType.outputItems,
output: {
content: terminalStateBase64,
mime: 'text/plain',
id: cellId!,
},
}

return new NotebookCellOutput([
NotebookCellOutputItem.json(json, OutputType.outputItems),
NotebookCellOutputItem.stdout(
Buffer.from(terminalStateBase64, 'base64').toString('utf-8'),
),
])
}

case OutputType.github: {
Expand Down Expand Up @@ -631,7 +638,7 @@ export class NotebookCellOutputManager {
const terminalOutput = this.terminalState?.outputType

if (terminalOutput) {
this.terminalEnabled = this.hasOutputTypeUnsafe(terminalOutput)
this.terminalEnabled = this.hasOutputTypeUnsafe(OutputType.terminal)
}

if (!((await mutater?.()) ?? true)) {
Expand Down
Loading

0 comments on commit a991d85

Please sign in to comment.