Skip to content
Source
Sign inSign up

projectScriptTerminal.ts

18 lines855 Bytes

1/**
2 * Project actions reuse only an idle drawer terminal (the active one first). Right-panel ids
3 * are excluded even when drawer state lists them: reusing one renders a single PTY in both
4 * surfaces, and closing the drawer copy kills the panel shell.
5 */
6export function findReusableProjectScriptTerminal(input: {
7 readonly drawerTerminalIds: ReadonlyArray<string>;
8 readonly activeTerminalId: string;
9 readonly panelTerminalIds: ReadonlySet<string>;
10 readonly runningTerminalIds: ReadonlyArray<string>;
11}): string | null {
12 const idleDrawerTerminalIds = input.drawerTerminalIds.filter(
13 (terminalId) =>
14 !input.panelTerminalIds.has(terminalId) && !input.runningTerminalIds.includes(terminalId),
15 );
16 if (idleDrawerTerminalIds.includes(input.activeTerminalId)) return input.activeTerminalId;
17 return idleDrawerTerminalIds[0] ?? null;