getText method
Get the plain text content of the buffer including the scrollback.
Accepts an optional range to get a specific part of the buffer.
Reads (and caches) every line in the range: for large ranges over
deep scrollback this costs about as much as reading the lines one by
one (see COMPATIBILITY.md).
Implementation
String getText([BufferRange? range]) {
range ??= BufferRangeLine(
const CellOffset(0, 0),
CellOffset(viewWidth - 1, height - 1),
);
range = range.normalized;
final builder = StringBuffer();
final lineCount = height;
for (final segment in range.toSegments()) {
if (segment.line < 0 || segment.line >= lineCount) {
continue;
}
final line = lines[segment.line];
if (!(segment.line == range.begin.y ||
segment.line == 0 ||
line.isWrapped)) {
builder.write('\n');
}
builder.write(line.getText(segment.start, segment.end));
}
return builder.toString();
}