summaryrefslogtreecommitdiff
path: root/lib/renderers/ansi.js
blob: b3a461d5f449f37cba1c2bac66887a11c7913c19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
'use strict';

/**
 * Returns a basic ansi color, see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
 * for more info.
 *
 * @function ANSIRenderer
 * @implements IRenderer
 */
module.exports = function (red, blue, green) {

  const colorOffset = Math.round((red + blue + green) * 7 / (255 * 3));
  const colorNumber = 40 + colorOffset;

  return `\x1B[${colorNumber}m`;
};