renderChar method

  1. @override
void renderChar(
  1. int x,
  2. int y,
  3. Char char
)
override

Render the given Char at column x, row y in a Terminal

Implementation

@override
void renderChar(int x, int y, Char char) {
  if (!_glyphsLoaded) return;

  // fill the background
  ctx.fillStyle = char.background.cssColor;
  ctx.fillRect(x * charWidth * scale, y * charHeight * scale,
      charWidth * scale, charHeight * scale);

  // skip rendering empty characters
  if (char.charCode == CharCode.nullChar ||
      char.charCode == CharCode.space ||
      char.charCode == CharCode.nbsp) return;

  // index into the glyph array
  var glyphIndex = _charToGlyphIndex[char.charCode] ?? char.charCode;
  var gx = (glyphIndex % 32) * charWidth;
  var gy = (glyphIndex ~/ 32) * charHeight;

  // skip rendering out-of-bounds characters
  if (glyphIndex > _maxGlyphIndex) return;

  // render the glyph
  var colorGlyphs = _getColorGlyphs(char.foreground);
  ctx.imageSmoothingEnabled = false;
  ctx.drawImageScaledFromSource(
      colorGlyphs,
      gx,
      gy,
      charWidth,
      charHeight,
      x * charWidth * scale,
      y * charHeight * scale,
      charWidth * scale,
      charHeight * scale);
}