resolveAnsi256 method

Color resolveAnsi256(
  1. int index
)

Resolves an ANSI 256-color index (0..255) using this theme's 16-color palette for slots 0..15 and standard xterm-256 cube/grayscale math above.

Implementation

Color resolveAnsi256(int index) {
  if (index < 0 || index > 255) return foreground;
  if (index < 16) return ansi[index];
  if (index < 232) {
    final cube = index - 16;
    final r = (cube ~/ 36) % 6;
    final g = (cube ~/ 6) % 6;
    final b = cube % 6;
    return Color(
      r == 0 ? 0 : r * 40 + 55,
      g == 0 ? 0 : g * 40 + 55,
      b == 0 ? 0 : b * 40 + 55,
    );
  }
  final gray = (index - 232) * 10 + 8;
  return Color(gray, gray, gray);
}