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 (isInVerticalMargin) {
if (_cursorY == _marginBottom) {
if (marginTop == 0 && !isAltBuffer) {
// Inserting past the bottom scrolls the oldest line out when the
// buffer is full. Reuse that line instead of allocating a new one:
// under output floods this allocation (BufferLine + its cell data
// array) was the dominant source of GC pressure.
final line = lines.isFull ? (lines[0]..reset()) : _newEmptyLine();
_invalidateCurrentLine();
lines.insert(absoluteMarginBottom + 1, line);
} else {
scrollUp(1);
}
} else {
moveCursorY(1);
}
return;
}
// the cursor is not in the scrollable region
if (_cursorY >= viewHeight - 1) {
// we are at the bottom
if (isAltBuffer) {
scrollUp(1);
} else {
// See above: recycle the scrolled-out line when the buffer is full.
final line = lines.isFull ? (lines[0]..reset()) : _newEmptyLine();
_invalidateCurrentLine();
lines.push(line);
}
} else {
// there're still lines so we simply move cursor down.
moveCursorY(1);
}
}