resize method
Resizes the buffer to the new dimensions, preserving existing content where it fits.
Implementation
void resize(int newWidth, int newHeight) {
Tracer.record(_traceResizeId, Phase.begin);
try {
newWidth = max(0, newWidth);
newHeight = max(0, newHeight);
final newCells = List.generate(newWidth * newHeight, (_) => Cell.empty());
for (var y = 0; y < newHeight; y++) {
for (var x = 0; x < newWidth; x++) {
final targetIdx = y * newWidth + x;
if (x < width && y < height) {
final sourceCell = cells[_index(x, y)];
newCells[targetIdx].char = sourceCell.char;
newCells[targetIdx].style = sourceCell.style;
}
}
}
width = newWidth;
height = newHeight;
cells = newCells;
} finally {
Tracer.record(_traceResizeId, Phase.end);
}
}