resizeKeeping method
Simulates a resize of a terminal that keeps what the screen shows:
rows are cut or padded with blanks at the right (no reflow) and the
cursor stays on its row. A screen shorter than the cursor's row
scrolls the rows above it into history (rows below the cursor are
cut); a taller one gains blank rows at the bottom (xterm) or, with
pull, takes lines back from history at the top (VTE).
Implementation
void resizeKeeping(int w, int h, {bool pull = false}) {
for (final row in _grid) {
_fit(row, w);
}
if (h < height && cy >= h) {
final k = cy - h + 1;
for (var i = 0; i < k; i++) {
final row = _grid.removeAt(0);
if (scrollback) {
history.add(row);
}
}
cy -= k;
}
if (_grid.length > h) {
_grid.removeRange(h, _grid.length);
}
if (pull) {
while (_grid.length < h && history.isNotEmpty) {
_grid.insert(0, _fit(history.removeLast(), w));
cy++;
}
}
while (_grid.length < h) {
final row = List<VtCell>.generate(w, (_) => VtCell());
if (konsoleLines) {
_lengths[row] = 0;
}
_grid.add(row);
}
width = w;
height = h;
cx = cx.clamp(0, w - 1);
topMargin = 0;
bottomMargin = h - 1;
leftMargin = 0;
rightMargin = w - 1;
pendingWrap = false;
}