| 407 | private activeHyperlink: ActiveHyperlink | null = null; |
| 408 | |
| 409 | process(ansiCode: string): void { |
| 410 | // OSC 8 hyperlink: \x1b]8;;<url>\x1b\\ (open) or \x1b]8;;\x1b\\ (close). |
| 411 | // Preserve the original terminator because some terminals only make BEL-terminated |
| 412 | // links clickable. OAuth login URLs use BEL, so reopening wrapped lines with ST |
| 413 | // made only the first physical line clickable in those terminals. |
| 414 | const hyperlink = parseOsc8Hyperlink(ansiCode); |
| 415 | if (hyperlink !== undefined) { |
| 416 | this.activeHyperlink = hyperlink; |
| 417 | return; |
| 418 | } |
| 419 | |
| 420 | if (!ansiCode.endsWith("m")) { |
| 421 | return; |
| 422 | } |
| 423 | |
| 424 | // Extract the parameters between \x1b[ and m |
| 425 | const match = ansiCode.match(/\x1b\[([\d;]*)m/); |
| 426 | if (!match) return; |
| 427 | |
| 428 | const params = match[1]!; |
| 429 | if (params === "" || params === "0") { |
| 430 | // Full reset |
| 431 | this.reset(); |
| 432 | return; |
| 433 | } |
| 434 | |
| 435 | // Parse parameters (can be semicolon-separated) |
| 436 | const parts = params.split(";"); |
| 437 | let i = 0; |
| 438 | while (i < parts.length) { |
| 439 | const code = Number.parseInt(parts[i]!, 10); |
| 440 | |
| 441 | // Handle 256-color and RGB codes which consume multiple parameters |
| 442 | if (code === 38 || code === 48) { |
| 443 | // 38;5;N (256 color fg) or 38;2;R;G;B (RGB fg) |
| 444 | // 48;5;N (256 color bg) or 48;2;R;G;B (RGB bg) |
| 445 | if (parts[i + 1] === "5" && parts[i + 2] !== undefined) { |
| 446 | // 256 color: 38;5;N or 48;5;N |
| 447 | const colorCode = `${parts[i]};${parts[i + 1]};${parts[i + 2]}`; |
| 448 | if (code === 38) { |
| 449 | this.fgColor = colorCode; |
| 450 | } else { |
| 451 | this.bgColor = colorCode; |
| 452 | } |
| 453 | i += 3; |
| 454 | continue; |
| 455 | } else if (parts[i + 1] === "2" && parts[i + 4] !== undefined) { |
| 456 | // RGB color: 38;2;R;G;B or 48;2;R;G;B |
| 457 | const colorCode = `${parts[i]};${parts[i + 1]};${parts[i + 2]};${parts[i + 3]};${parts[i + 4]}`; |
| 458 | if (code === 38) { |
| 459 | this.fgColor = colorCode; |
| 460 | } else { |
| 461 | this.bgColor = colorCode; |
| 462 | } |
| 463 | i += 5; |
| 464 | continue; |
| 465 | } |
| 466 | } |