csiSetMarginsHandler function

void csiSetMarginsHandler(
  1. CSI csi,
  2. Terminal terminal
)

DECSTBM – Set Top and Bottom Margins (DEC Private)

ESC [ Pn; Pn r

This sequence sets the top and bottom margins to define the scrolling region. The first parameter is the line number of the first line in the scrolling region; the second parameter is the line number of the bottom line in the scrolling region. Default is the en tire screen (no margins). The minimum size of the scrolling region allowed is two lines, i.e., the top margin must be less than the bottom margin. The cursor is placed in the home position (see Origin Mode DECOM).

Implementation

void csiSetMarginsHandler(CSI csi, Terminal terminal) {
  var top = 1;
  var bottom = terminal.viewHeight;

  if (csi.params.length > 2) {
    return;
  }

  if (csi.params.isNotEmpty) {
    top = csi.params[0];

    if (csi.params.length > 1) {
      bottom = csi.params[1];
    }
  }

  terminal.buffer.setVerticalMargins(top - 1, bottom - 1);
  terminal.buffer.setPosition(0, 0);
}