* Find the string offset that corresponds to a target display width.
(targetWidth: number)
| 1268 | * Find the string offset that corresponds to a target display width. |
| 1269 | */ |
| 1270 | private offsetAtDisplayWidth(targetWidth: number): number { |
| 1271 | if (targetWidth <= 0) return 0 |
| 1272 | |
| 1273 | let currentWidth = 0 |
| 1274 | const boundaries = this.getGraphemeBoundaries() |
| 1275 | |
| 1276 | // Iterate through grapheme boundaries |
| 1277 | for (let i = 0; i < boundaries.length - 1; i++) { |
| 1278 | const start = boundaries[i] |
| 1279 | const end = boundaries[i + 1] |
| 1280 | if (start === undefined || end === undefined) continue |
| 1281 | const segment = this.text.substring(start, end) |
| 1282 | const segmentWidth = stringWidth(segment) |
| 1283 | |
| 1284 | if (currentWidth + segmentWidth > targetWidth) { |
| 1285 | return start |
| 1286 | } |
| 1287 | currentWidth += segmentWidth |
| 1288 | } |
| 1289 | |
| 1290 | return this.text.length |
| 1291 | } |
| 1292 | |
| 1293 | private measureWrappedText(): WrappedLine[] { |
| 1294 | const wrappedText = wrapAnsi(this.text, this.columns, { |
no test coverage detected