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, 03:37 UTC
| 1 | export function terminalNumber(terminalId: string): string | undefined { |
| 2 | return /^term(?:inal)?-(\d+)(?:-[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12})?$/i.exec( |
| 3 | terminalId, |
| 4 | )?.[1]; |
| 5 | } |
| 6 | |
| 7 | export function getTerminalLabel(terminalId: string): string { |
| 8 | const numericSuffix = terminalNumber(terminalId); |
| 9 | if (numericSuffix) { |
| 10 | return `Terminal ${numericSuffix}`; |
| 11 | } |
| 12 | |
| 13 | return terminalId; |
| 14 | } |
| 15 | |
| 16 | /** Append a UUID when metadata is unavailable to avoid reusing unseen host sessions. */ |
| 17 | export function nextTerminalId( |
| 18 | existingTerminalIds: ReadonlyArray<string>, |
| 19 | uniqueSuffix?: string, |
| 20 | ): string { |
| 21 | const usedNumbers = new Set(existingTerminalIds.map(terminalNumber)); |
| 22 | let nextIndex = 1; |
| 23 | while (usedNumbers.has(String(nextIndex))) { |
| 24 | nextIndex += 1; |
| 25 | } |
| 26 | |
| 27 | return `term-${nextIndex}${uniqueSuffix === undefined ? "" : `-${uniqueSuffix}`}`; |
| 28 | } |