MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / parseOsc8Hyperlink

Function parseOsc8Hyperlink

packages/pi-tui/src/utils.ts:364–382  ·  view source on GitHub ↗
(ansiCode: string)

Source from the content-addressed store, hash-verified

362}
363
364function parseOsc8Hyperlink(ansiCode: string): ActiveHyperlink | null | undefined {
365 if (!ansiCode.startsWith("\x1b]8;")) {
366 return undefined;
367 }
368
369 const terminator: Osc8Terminator = ansiCode.endsWith("\x07") ? "\x07" : "\x1b\\";
370 const body = ansiCode.slice(4, terminator === "\x07" ? -1 : -2);
371 const separatorIndex = body.indexOf(";");
372 if (separatorIndex === -1) {
373 return undefined;
374 }
375
376 const params = body.slice(0, separatorIndex);
377 const url = body.slice(separatorIndex + 1);
378 if (!url) {
379 return null;
380 }
381 return { params, url, terminator };
382}
383
384function formatOsc8Hyperlink(hyperlink: ActiveHyperlink): string {
385 return `\x1b]8;${hyperlink.params};${hyperlink.url}${hyperlink.terminator}`;

Callers 1

processMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected