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 | import type { TerminalSummary } from "@t3tools/contracts"; |
| 2 | import { mFallback, msg } from "gt-i18n"; |
| 3 | import type { MFunctionType } from "gt-i18n/types"; |
| 4 | |
| 5 | import { getTerminalLabel as getServerTerminalLabel, terminalNumber } from "./terminalLabels.ts"; |
| 6 | |
| 7 | /** @public */ |
| 8 | export function getTerminalLabel(terminalId: string, resolve: MFunctionType = mFallback): string { |
| 9 | const numericSuffix = terminalNumber(terminalId); |
| 10 | return numericSuffix ? resolve(msg("Terminal {number}", { number: numericSuffix })) : terminalId; |
| 11 | } |
| 12 | |
| 13 | /** |
| 14 | * The server sends the running process name, or its English idle default, which is shown translated. |
| 15 | * @public |
| 16 | */ |
| 17 | export function resolveTerminalSessionLabel( |
| 18 | terminalId: string, |
| 19 | summary: Pick<TerminalSummary, "label" | "hasRunningSubprocess"> | null | undefined, |
| 20 | resolve: MFunctionType = mFallback, |
| 21 | ): string { |
| 22 | const trimmed = summary?.label.trim(); |
| 23 | const isIdleDefault = |
| 24 | !summary?.hasRunningSubprocess && trimmed === getServerTerminalLabel(terminalId); |
| 25 | return trimmed && !isIdleDefault ? trimmed : getTerminalLabel(terminalId, resolve); |
| 26 | } |