| 69 | } |
| 70 | |
| 71 | function computeWrap( |
| 72 | text: string, |
| 73 | maxWidth: number, |
| 74 | wrapType: Styles['textWrap'], |
| 75 | ): string { |
| 76 | if (wrapType === 'wrap') { |
| 77 | return wrapAnsi(text, maxWidth, { |
| 78 | trim: false, |
| 79 | hard: true, |
| 80 | }) |
| 81 | } |
| 82 | |
| 83 | if (wrapType === 'wrap-trim') { |
| 84 | return wrapAnsi(text, maxWidth, { |
| 85 | trim: true, |
| 86 | hard: true, |
| 87 | }) |
| 88 | } |
| 89 | |
| 90 | if (wrapType!.startsWith('truncate')) { |
| 91 | let position: 'end' | 'middle' | 'start' = 'end' |
| 92 | |
| 93 | if (wrapType === 'truncate-middle') { |
| 94 | position = 'middle' |
| 95 | } |
| 96 | |
| 97 | if (wrapType === 'truncate-start') { |
| 98 | position = 'start' |
| 99 | } |
| 100 | |
| 101 | return truncate(text, maxWidth, position) |
| 102 | } |
| 103 | |
| 104 | return text |
| 105 | } |
| 106 | |
| 107 | export function resetWrapTextCacheForTesting(): void { |
| 108 | wrapCache.clear() |