aboutsummaryrefslogtreecommitdiff
path: root/lib/renderers/256_colors.js
blob: 8fc67b29eb215e70632cec39dc3b66fb833b572a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
'use strict';

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

    const redValue = Math.round(red * 5 / 255);
    const blueValue = Math.round(blue * 5 / 255);
    const greenValue = Math.round(green * 5 / 255);

    const colorNumber = 16 + 36 * redValue + 6 * greenValue + blueValue;

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