fillRect method

void fillRect(
  1. Rect rect, {
  2. String? char,
  3. int? fg,
  4. int? bg,
  5. int? modifiers,
  6. int? underlineColor,
  7. String? uri,
  8. bool? blend,
})

Fills a rectangular region with the given character and attributes.

Implementation

void fillRect(
  Rect rect, {
  String? char,
  int? fg,
  int? bg,
  int? modifiers,
  int? underlineColor,
  String? uri,
  bool? blend,
}) {
  final clipped = _clipStack.isEmpty ? rect : activeClip.intersect(rect);
  if (clipped.width <= 0 || clipped.height <= 0) return;

  final startX = max(0, clipped.left);
  final startY = max(0, clipped.top);
  final endX = min(width, clipped.right);
  final endY = min(height, clipped.bottom);
  if (startX >= endX || startY >= endY) return;

  if (char != null) {
    for (var y = startY; y < endY; y++) {
      final rowOffset = y * width;
      _clearSplitWideEdges(rowOffset, startX, endX, char);
      characters.fillRange(rowOffset + startX, rowOffset + endX, char);
    }
  }

  if (fg == null &&
      bg == null &&
      modifiers == null &&
      underlineColor == null &&
      uri == null) {
    return;
  }
  final useBlend = blend ?? defaultBlend;
  for (var y = startY; y < endY; y++) {
    final rowOffset = y * width;
    for (var x = startX; x < endX; x++) {
      _writeCellAttributes(
        (rowOffset + x) * 3,
        fg: fg,
        bg: bg,
        modifiers: modifiers,
        underlineColor: underlineColor,
        uri: uri,
        blend: useBlend,
      );
    }
  }
}