eraseRange method

void eraseRange(
  1. int start,
  2. int end,
  3. CursorStyle style, {
  4. bool respectProtected = false,
})

Erase cells whose index satisfies start <= index < end. Erased cells are filled with style.

Implementation

void eraseRange(
  int start,
  int end,
  CursorStyle style, {
  bool respectProtected = false,
}) {
  start = max(0, start);
  if (end > _length) {
    if (style.foreground != 0 ||
        style.background != 0 ||
        style.attrs != 0 ||
        style.underlineColor != 0) {
      resize(end, clearNewCells: true);
    } else {
      end = _length;
    }
  }
  if (start >= end) return;
  // reset cell one to the left if start is second cell of a wide char
  if (start > 0 &&
      getWidth(start - 1) == 2 &&
      _canErase(start - 1, respectProtected)) {
    eraseCell(start - 1, style);
  }

  // reset cell one to the right if end is second cell of a wide char
  if (end < _length &&
      getWidth(end - 1) == 2 &&
      _canErase(end - 1, respectProtected)) {
    eraseCell(end - 1, style);
  }

  end = min(end, _length);
  for (var i = start; i < end; i++) {
    if (!_canErase(i, respectProtected)) continue;
    eraseCell(i, style);
  }
}