Skip to content

Commit

Permalink
identify terminal processes by name
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsdev committed Feb 23, 2023
1 parent 853b780 commit 4c5da8e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/extension/executors/runner.ts
Expand Up @@ -123,9 +123,9 @@ export async function executeRunner(
const taskExecution = new Task(
{ type: 'shell', name: `Runme Task (${RUNME_ID})` },
TaskScope.Workspace,
cellText.length > LABEL_LIMIT
(cellText.length > LABEL_LIMIT
? `${cellText.slice(0, LABEL_LIMIT)}...`
: cellText,
: cellText) + ` (RUNME_ID: ${RUNME_ID})`,
'exec',
new CustomExecution(async () => program)
)
Expand Down
11 changes: 10 additions & 1 deletion src/extension/provider/background.ts
Expand Up @@ -29,8 +29,17 @@ export class ShowTerminalProvider implements vscode.NotebookCellStatusBarItemPro
return
}

const terminalButtonParts = [
'$(terminal)',
'Open Terminal',
]

if (pid > -1) {
terminalButtonParts.push(`(PID: ${pid})`)
}

const item = new NotebookCellStatusBarItem(
`$(terminal) Open Terminal (PID: ${pid})`,
terminalButtonParts.join(' '),
NotebookCellStatusBarAlignment.Right
)
item.command = 'runme.openTerminal'
Expand Down
9 changes: 7 additions & 2 deletions src/extension/utils.ts
Expand Up @@ -79,10 +79,15 @@ export function validateAnnotations(cell: NotebookCell): CellAnnotationsErrorRes

}

function getTerminalRunmeId(t: vscode.Terminal): string|undefined {
return (t.creationOptions as vscode.TerminalOptions).env?.RUNME_ID
?? /\(RUNME_ID: (.*)\)$/.exec(t.name)?.[1]
?? undefined
}

export function getTerminalByCell(cell: vscode.NotebookCell) {
return vscode.window.terminals.find((t) => {
const taskEnv = (t.creationOptions as vscode.TerminalOptions).env || {}
return taskEnv.RUNME_ID === `${cell.document.fileName}:${cell.index}`
return getTerminalRunmeId(t) === `${cell.document.fileName}:${cell.index}`
})
}

Expand Down

0 comments on commit 4c5da8e

Please sign in to comment.