setMargins method

void setMargins(
  1. int top, [
  2. int? bottom
])

Sets the scroll region to rows top to bottom (0-based, inclusive; the last row by default) (DECSTBM). The cursor stays where it is, as in xterm.

Implementation

void setMargins(int top, [int? bottom]) {
  final vt = _vt;
  final last = vt.rows - 1;
  final a = top.clamp(0, last);
  final b = (bottom ?? last).clamp(0, last);
  final first = min(a, b);
  final x = vt.cursorX;
  final y = vt.cursorY;
  // DECSTBM homes the cursor; move it back (relative to the new region
  // in origin mode).
  final row = originMode ? max(y - first, 0) : y;
  _seq('\x1b[${first + 1};${max(a, b) + 1}r\x1b[${row + 1};${x + 1}H');
}