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