| 72 | const used: Array<{ start: number; end: number }> = [] |
| 73 | |
| 74 | const take = (value: string): { start: number; end: number; value: string } | undefined => { |
| 75 | let from = 0 |
| 76 | while (true) { |
| 77 | const idx = text.indexOf(value, from) |
| 78 | if (idx === -1) { |
| 79 | return undefined |
| 80 | } |
| 81 | |
| 82 | const start = Bun.stringWidth(text.slice(0, idx)) |
| 83 | const end = start + Bun.stringWidth(value) |
| 84 | if (!used.some((item) => item.start < end && start < item.end)) { |
| 85 | return { start, end, value } |
| 86 | } |
| 87 | |
| 88 | from = idx + value.length |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | const add = (value: string) => { |
| 93 | const gap = text ? " " : "" |