getTrimmedLength method
Returns the offset of the last cell that has content from the start of the line.
Implementation
int getTrimmedLength([int? cols]) {
// Clamp to _length, not capacity: resize() shrinking a line keeps the
// cell data beyond _length around, so scanning past it would count
// stale content that's no longer part of the line.
final maxCols = _length;
if (cols == null || cols > maxCols) {
cols = maxCols;
}
if (cols <= 0) {
return 0;
}
for (var i = cols - 1; i >= 0; i--) {
var codePoint = getCodePoint(i);
if (codePoint != 0) {
// we are at the last cell in this line that has content.
// the length of this line is the index of this cell + 1
// the only exception is that if that last cell is wider
// than 1 then we have to add the diff
final lastCellWidth = getWidth(i);
return i + lastCellWidth;
}
}
return 0;
}