| 19 | const emojiRegex = /\p{Emoji_Presentation}|\p{Extended_Pictographic}/gu; |
| 20 | |
| 21 | function getDisplayWidth(str: string): number { |
| 22 | // Remove ANSI codes first |
| 23 | // eslint-disable-next-line no-control-regex |
| 24 | const plain = str.replace(/\x1b\[[0-9;]*m/g, ''); |
| 25 | // Count emojis (each takes 2 columns but counts as 1-2 chars) |
| 26 | const emojis = plain.match(emojiRegex) || []; |
| 27 | // Base length minus emoji chars, plus 2 per emoji for display width |
| 28 | const baseLen = [...plain].length; |
| 29 | return baseLen + emojis.length; // Add 1 extra column per emoji |
| 30 | } |
| 31 | |
| 32 | function printBox(lines: string[], borderColor: string) { |
| 33 | const maxLen = Math.max(...lines.map((l) => getDisplayWidth(l))); |