deleteLines method

void deleteLines(
  1. int count
)

Remove count lines starting at the current cursor position. Lines below the removed lines are shifted up. This only affects the scrollable region. Lines outside the scrollable region are not affected.

Implementation

void deleteLines(int count) {
  if (!isInVerticalMargin || !isInHorizontalMargin) {
    return;
  }

  setCursorX(_marginLeft);

  count = min(count, absoluteMarginBottom - absoluteCursorY + 1);

  final linesToMove = absoluteMarginBottom - absoluteCursorY + 1 - count;

  if (!_usesFullHorizontalMargins) {
    final width = _marginRight - _marginLeft + 1;
    for (var i = 0; i < linesToMove; i++) {
      final index = absoluteCursorY + i;
      lines[index].copyFrom(
        lines[index + count],
        _marginLeft,
        _marginLeft,
        width,
      );
    }

    for (var i = 0; i < count; i++) {
      lines[absoluteMarginBottom - i].eraseRange(
        _marginLeft,
        _marginRight + 1,
        terminal.cursor,
      );
    }
    return;
  }

  for (var i = 0; i < linesToMove; i++) {
    final index = absoluteCursorY + i;
    lines[index] = lines[index + count];
  }

  for (var i = 0; i < count; i++) {
    lines[absoluteMarginBottom - i] = _newEmptyLine();
  }
}