(stack: string[], code: string | number, options: AnsiToHtmlOptions)
| 168 | } |
| 169 | |
| 170 | function handleDisplay(stack: string[], code: string | number, options: AnsiToHtmlOptions): string { |
| 171 | code = isString(code) ? Number.parseInt(code, 10) : code; |
| 172 | const codeMap: Record<number, () => string> = { |
| 173 | '-1': () => '<br />', |
| 174 | 0: () => (stack.length ? resetStyles(stack) : ''), |
| 175 | 1: () => pushTag(stack, 'b'), |
| 176 | 2: () => pushStyle(stack, 'opacity:0.6'), |
| 177 | 3: () => pushTag(stack, 'i'), |
| 178 | 4: () => pushTag(stack, 'u'), |
| 179 | 8: () => pushStyle(stack, 'display:none'), |
| 180 | 9: () => pushTag(stack, 'strike'), |
| 181 | 22: () => closeTag(stack, 'b'), |
| 182 | 23: () => closeTag(stack, 'i'), |
| 183 | 24: () => closeTag(stack, 'u'), |
| 184 | 39: () => pushForegroundColor(stack, unwrap(options.fg)), |
| 185 | 49: () => pushBackgroundColor(stack, unwrap(options.bg)), |
| 186 | }; |
| 187 | |
| 188 | if (code in codeMap) { |
| 189 | return codeMap[code](); |
| 190 | } |
| 191 | if (4 < code && code < 7) { |
| 192 | return pushTag(stack, 'blink'); |
| 193 | } |
| 194 | if (code === 7) { |
| 195 | return ''; |
| 196 | } |
| 197 | if (29 < code && code < 38) { |
| 198 | return pushForegroundColor(stack, options.colors[code - 30]); |
| 199 | } |
| 200 | if (39 < code && code < 48) { |
| 201 | return pushBackgroundColor(stack, options.colors[code - 40]); |
| 202 | } |
| 203 | if (89 < code && code < 98) { |
| 204 | return pushForegroundColor(stack, options.colors[8 + (code - 90)]); |
| 205 | } |
| 206 | if (99 < code && code < 108) { |
| 207 | return pushBackgroundColor(stack, options.colors[8 + (code - 100)]); |
| 208 | } |
| 209 | return 'Unknown code'; |
| 210 | } |
| 211 | |
| 212 | function handleUrl(stack: string[], data: string, options: AnsiToHtmlOptions): string { |
| 213 | const [url, text] = data.split(/\x1b\\|\x07/); |
no test coverage detected