Files
openclaw/src/terminal/terminal-link.ts
2026-03-27 15:56:54 +00:00

16 lines
503 B
TypeScript

export function formatTerminalLink(
label: string,
url: string,
opts?: { fallback?: string; force?: boolean },
): string {
const esc = "\u001b";
const safeLabel = label.replaceAll(esc, "");
const safeUrl = url.replaceAll(esc, "");
const allow =
opts?.force === true ? true : opts?.force === false ? false : Boolean(process.stdout.isTTY);
if (!allow) {
return opts?.fallback ?? `${safeLabel} (${safeUrl})`;
}
return `\u001b]8;;${safeUrl}\u0007${safeLabel}\u001b]8;;\u0007`;
}