@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 22 lines 1.02 KB
Raw
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 */
6 export function findReusableProjectScriptTerminal(input: {
7 readonly drawerTerminalIds: ReadonlyArray<string>;
8 readonly activeTerminalId: string;
9 readonly panelTerminalIds: ReadonlySet<string>;
10 readonly runningTerminalIds: ReadonlyArray<string>;
11 /** A pending close would end the script's shell once the reopen runs. */
12 readonly closingTerminalIds: ReadonlyArray<string>;
13 }): string | null {
14 const idleDrawerTerminalIds = input.drawerTerminalIds.filter(
15 (terminalId) =>
16 !input.panelTerminalIds.has(terminalId) &&
17 !input.runningTerminalIds.includes(terminalId) &&
18 !input.closingTerminalIds.includes(terminalId),
19 );
20 if (idleDrawerTerminalIds.includes(input.activeTerminalId)) return input.activeTerminalId;
21 return idleDrawerTerminalIds[0] ?? null;
22 }