diff options
Diffstat (limited to 'lib/renderers')
| -rw-r--r-- | lib/renderers/256_colors.js | 23 | ||||
| -rw-r--r-- | lib/renderers/ansi.js | 17 | ||||
| -rw-r--r-- | lib/renderers/fake_color.js | 12 | ||||
| -rw-r--r-- | lib/renderers/true_color.js | 14 |
4 files changed, 42 insertions, 24 deletions
diff --git a/lib/renderers/256_colors.js b/lib/renderers/256_colors.js index e8e6e37..f6e57d3 100644 --- a/lib/renderers/256_colors.js +++ b/lib/renderers/256_colors.js @@ -1,16 +1,19 @@ '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); +/** + * 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) { - let colorNumber = 16 + 36 * redValue + 6 * greenValue + blueValue; + 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`; }; - -module.exports = TwoFiftySixColors; diff --git a/lib/renderers/ansi.js b/lib/renderers/ansi.js index c3975da..b3a461d 100644 --- a/lib/renderers/ansi.js +++ b/lib/renderers/ansi.js @@ -1,13 +1,16 @@ 'use strict'; -// Returns a basic ANSI color. See the color table in: -// https://en.wikipedia.org/wiki/ANSI_escape_code#Colors -const ANSI = function (red, blue, green) { - let colorOffset = Math.round((red + blue + green) * 7 / (255 * 3)); +/** + * Returns a basic ansi color, see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors + * for more info. + * + * @function ANSIRenderer + * @implements IRenderer + */ +module.exports = function (red, blue, green) { - let colorNumber = 40 + colorOffset; + const colorOffset = Math.round((red + blue + green) * 7 / (255 * 3)); + const colorNumber = 40 + colorOffset; return `\x1B[${colorNumber}m`; }; - -module.exports = ANSI; diff --git a/lib/renderers/fake_color.js b/lib/renderers/fake_color.js index b82bb45..b03309c 100644 --- a/lib/renderers/fake_color.js +++ b/lib/renderers/fake_color.js @@ -1,8 +1,12 @@ 'use strict'; -// Sends malformed ANSI 24-bit color strings -const FakeColor = function (red, blue, green) { +/** + * Returns a malformed 24-bit ansi color + * + * @function FakeColorRenderer + * @implements IRenderer + */ +module.exports = function (red, blue, green) { + return `\x1B[28;2;${Math.round(red)};${Math.round(green)};${Math.round(blue)}m`; }; - -module.exports = FakeColor; diff --git a/lib/renderers/true_color.js b/lib/renderers/true_color.js index 5f7725f..811d186 100644 --- a/lib/renderers/true_color.js +++ b/lib/renderers/true_color.js @@ -4,8 +4,16 @@ // https://en.wikipedia.org/wiki/ANSI_escape_code#Colors // and look for 24-bit colors. Only looks good in supported terminals, // otherwise looks like FakeColor. -const TrueColor = function (red, blue, green) { +/** + * Returns an ANSI code for 24-bit True Color, see + * https://en.wikipedia.org/wiki/ANSI_escape_code#Colors and look for + * 24-bit colors for more info. Only looks good in supported terminals, + * otherwise looks like FakeColor + * + * @function TrueColorRenderer + * @implements IRenderer + */ +module.exports = function (red, blue, green) { + return `\x1B[48;2;${Math.round(red)};${Math.round(green)};${Math.round(blue)}m`; }; - -module.exports = TrueColor; |