rgb method

AnsiPen rgb({
  1. num r = 1.0,
  2. num g = 1.0,
  3. num b = 1.0,
  4. bool bg = false,
})

Sets the pen color to the rgb value between 0.0..1.0. Compatible with ansicolor's AnsiPen.rgb() signature. Maps to xterm 256-color palette (same as ansicolor).

Implementation

AnsiPen rgb({num r = 1.0, num g = 1.0, num b = 1.0, bool bg = false}) {
  final int code =
      (r.clamp(0.0, 1.0) * 5).toInt() * 36 +
      (g.clamp(0.0, 1.0) * 5).toInt() * 6 +
      (b.clamp(0.0, 1.0) * 5).toInt() +
      16;
  styleStack.add(
    bg ? QuectoColors.bgAnsi256(code) : QuectoColors.ansi256(code),
  );
  return this;
}