]> git.r.bdr.sh - rbdr/tomato-sauce/blob - lib/renderers/ansi.js
c3975da9e7ef4ae0eba0470e7be6cd3c63b0203e
[rbdr/tomato-sauce] / lib / renderers / ansi.js
1 'use strict';
2
3 // Returns a basic ANSI color. See the color table in:
4 // https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
5 const ANSI = function (red, blue, green) {
6 let colorOffset = Math.round((red + blue + green) * 7 / (255 * 3));
7
8 let colorNumber = 40 + colorOffset;
9
10 return `\x1B[${colorNumber}m`;
11 };
12
13 module.exports = ANSI;