aboutsummaryrefslogtreecommitdiff
path: root/lib/renderers/256_colors.js
blob: e8e6e37566c57e516ca77f62cedc79dca6a396de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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;