| 79 | } |
| 80 | |
| 81 | function parseExtendedColor( |
| 82 | params: Param[], |
| 83 | idx: number, |
| 84 | ): { r: number; g: number; b: number } | { index: number } | null { |
| 85 | const p = params[idx] |
| 86 | if (!p) return null |
| 87 | |
| 88 | if (p.colon && p.subparams.length >= 1) { |
| 89 | if (p.subparams[0] === 5 && p.subparams.length >= 2) { |
| 90 | return { index: p.subparams[1]! } |
| 91 | } |
| 92 | if (p.subparams[0] === 2 && p.subparams.length >= 4) { |
| 93 | const off = p.subparams.length >= 5 ? 1 : 0 |
| 94 | return { |
| 95 | r: p.subparams[1 + off]!, |
| 96 | g: p.subparams[2 + off]!, |
| 97 | b: p.subparams[3 + off]!, |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | const next = params[idx + 1] |
| 103 | if (!next) return null |
| 104 | if ( |
| 105 | next.value === 5 && |
| 106 | params[idx + 2]?.value !== null && |
| 107 | params[idx + 2]?.value !== undefined |
| 108 | ) { |
| 109 | return { index: params[idx + 2]!.value! } |
| 110 | } |
| 111 | if (next.value === 2) { |
| 112 | const r = params[idx + 2]?.value |
| 113 | const g = params[idx + 3]?.value |
| 114 | const b = params[idx + 4]?.value |
| 115 | if ( |
| 116 | r !== null && |
| 117 | r !== undefined && |
| 118 | g !== null && |
| 119 | g !== undefined && |
| 120 | b !== null && |
| 121 | b !== undefined |
| 122 | ) { |
| 123 | return { r, g, b } |
| 124 | } |
| 125 | } |
| 126 | return null |
| 127 | } |
| 128 | |
| 129 | export function applySGR(paramStr: string, style: TextStyle): TextStyle { |
| 130 | const params = parseParams(paramStr) |