index method

void index()

https://vt100.net/docs/vt100-ug/chapter3.html#IND IND – Index

ESC D

index causes the active position to move downward one line without changing the column position. If the active position is at the bottom margin, a scroll up is performed.

Implementation

void index() {
  if (isInScrollableRegion) {
    if (_cursorY < _marginBottom) {
      moveCursorY(1);
    } else {
      areaScrollUp(1);
    }
    return;
  }

  // the cursor is not in the scrollable region
  if (_cursorY >= _terminal.viewHeight - 1) {
    // we are at the bottom so a new line is created.
    lines.push(_newEmptyLine());

    // keep viewport from moving if user is scrolling.
    if (isUserScrolling) {
      _scrollOffsetFromBottom++;
    }
  } else {
    // there're still lines so we simply move cursor down.
    moveCursorY(1);
  }
}