| 362 | } |
| 363 | |
| 364 | function 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 | |
| 384 | function formatOsc8Hyperlink(hyperlink: ActiveHyperlink): string { |
| 385 | return `\x1b]8;${hyperlink.params};${hyperlink.url}${hyperlink.terminator}`; |