diff options
| author | Ben Beltran <ben@nsovocal.com> | 2016-05-09 00:31:25 -0500 |
|---|---|---|
| committer | Ben Beltran <ben@nsovocal.com> | 2016-05-09 00:31:25 -0500 |
| commit | a140f3add912ef4bd659c1c1e82184643be7d845 (patch) | |
| tree | 131f33520cc40abc387474fa9c2ac4f536e6d7d1 /lib/renderers/256_colors.js | |
| parent | ae6dbe43bf54581dd7012f95581d4a1b6ee245f0 (diff) | |
| parent | 09ab7e985d46cad6d3c89e37f983e286e9fda2f6 (diff) | |
Merge branch 'feature/the-actual-tomato-sauce' into develop
Diffstat (limited to 'lib/renderers/256_colors.js')
| -rw-r--r-- | lib/renderers/256_colors.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/renderers/256_colors.js b/lib/renderers/256_colors.js new file mode 100644 index 0000000..e8e6e37 --- /dev/null +++ b/lib/renderers/256_colors.js @@ -0,0 +1,16 @@ +'use strict'; + +// Returns a 256 color, see +// https://en.wikipedia.org/wiki/ANSI_escape_code#Colors +// under 256 colors for more info. +const TwoFiftySixColors = function (red, blue, green) { + let redValue = Math.round(red * 5 / 255); + let blueValue = Math.round(blue * 5 / 255); + let greenValue = Math.round(green * 5 / 255); + + let colorNumber = 16 + 36 * redValue + 6 * greenValue + blueValue; + + return `\x1B[48;5;${colorNumber}m`; +}; + +module.exports = TwoFiftySixColors; |