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.
Implementation
String getText([BufferRange? range, bool trimWhitespace = false]) {
range ??= BufferRangeLine(
CellOffset(0, 0),
CellOffset(viewWidth, height - 1),
);
range = range.normalized;
final chunks = <String>[];
for (var segment in range.toSegments()) {
if (segment.line < 0 || segment.line >= height) {
continue;
}
final line = lines[segment.line];
final joinWrappedLine = range is! BufferRangeBlock && line.isWrapped;
if (!(segment.line == range.begin.y ||
segment.line == 0 ||
joinWrappedLine)) {
if (trimWhitespace) {
_trimTrailingSelectionWhitespace(chunks);
}
chunks.add('\n');
}
chunks.add(line.getText(segment.start, segment.end));
}
if (trimWhitespace) {
_trimTrailingSelectionWhitespace(chunks);
}
return chunks.join();
}