(
segment: string,
{ flushBeforeOversize = true }: { flushBeforeOversize?: boolean } = {},
)
| 14 | } |
| 15 | |
| 16 | const appendSegment = ( |
| 17 | segment: string, |
| 18 | { flushBeforeOversize = true }: { flushBeforeOversize?: boolean } = {}, |
| 19 | ) => { |
| 20 | if (!segment) return |
| 21 | |
| 22 | const segmentWidth = stringWidth(segment) |
| 23 | if (segmentWidth > cols) { |
| 24 | if (flushBeforeOversize && current > 0) emitHardWrap() |
| 25 | let acc = 0 |
| 26 | for (const ch of Array.from(segment)) { |
| 27 | const w = stringWidth(ch) |
| 28 | if (acc + w > cols) { |
| 29 | emitHardWrap() |
| 30 | acc = 0 |
| 31 | } |
| 32 | acc += w |
| 33 | } |
| 34 | current = acc |
| 35 | return |
| 36 | } |
| 37 | |
| 38 | if (current + segmentWidth > cols) emitHardWrap() |
| 39 | current += segmentWidth |
| 40 | } |
| 41 | |
| 42 | for (const token of tokens) { |
| 43 | if (!token) continue |
no test coverage detected