writeText method

void writeText(
  1. int x,
  2. int y,
  3. String text, {
  4. Style style = Style.none,
  5. int? maxWidth,
})

Implementation

void writeText(int x, int y, String text,
    {Style style = Style.none, int? maxWidth}) {
  if (y < 0 || y >= height) return;
  var cursor = x;
  final limit = maxWidth != null ? x + maxWidth : width;
  final runes = text.runes;
  for (final r in runes) {
    if (cursor >= limit || cursor >= width) break;
    if (r == 10 || r == 13) continue;
    final w = charWidth(r);
    if (w == 0) continue;
    if (cursor + w > limit || cursor + w > width) {
      if (cursor < limit) setChar(cursor, y, ' ', style: style);
      break;
    }
    setChar(cursor, y, String.fromCharCode(r), style: style, width: w);
    cursor += w;
  }
}