Open History to see the last commit
1import type { TerminalSummary } from "@t3tools/contracts";
2import { mFallback, msg } from "gt-i18n";
3import type { MFunctionType } from "gt-i18n/types";
4
5import { getTerminalLabel as getServerTerminalLabel, terminalNumber } from "./terminalLabels.ts";
6
7/** @public */
8export 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 */
17export 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}