]>
Commit | Line | Data |
---|---|---|
c7b4bd19 BB |
1 | 'use strict'; |
2 | ||
fd38d409 RBR |
3 | /** |
4 | * Returns a 256 color, see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors | |
5 | * for more info. | |
6 | * | |
7 | * @function 256ColorsRenderer | |
8 | * @implements IRenderer | |
9 | */ | |
10 | module.exports = function (red, blue, green) { | |
c7b4bd19 | 11 | |
a0666be3 RBR |
12 | const redValue = Math.round(red * 5 / 255); |
13 | const blueValue = Math.round(blue * 5 / 255); | |
14 | const greenValue = Math.round(green * 5 / 255); | |
fd38d409 | 15 | |
a0666be3 | 16 | const colorNumber = 16 + 36 * redValue + 6 * greenValue + blueValue; |
c7b4bd19 | 17 | |
a0666be3 | 18 | return `\x1B[48;5;${colorNumber}m`; |
c7b4bd19 | 19 | }; |