File size: 654 Bytes
c9c900b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import { cellWidth } from '../cell-width'
/**
* The cells a sanitized text is charged when laid into rows and padded:
* cellWidth, but a code point drawing in no cell is still charged one.
*
* The slicer and the band padding both count by this, so a row never
* emits more code points than the cells it was given, combining marks or
* not.
*
* @param text a line or segment with no tabs or control characters
* @returns its charge in cells, at least one per code point
*/
export function chargedWidth(text: string) {
let charged = 0
for (const character of text) {
charged += Math.max(1, cellWidth(character))
}
return charged
}
|