Rainbow Color Constants

A collection of constants that define the color palettes used by the rainbow() function and the progress bar's rainbow animation. There are three palettes — standard (4-bit), extended (8-bit, smooth gradient), and pastel — each paired with a pre-computed array of raw ANSI escape strings for direct use.

rainbowColors & rainbowASCIICodes

Six 4-bit named colors used by rainbow(str) in standard mode.

const rainbowColors: Color[] = [
"red",
"yellow",
"green",
"cyan",
"blue",
"magenta",
];

// Pre-mapped ANSI escape sequences (same order)
const rainbowASCIICodes: string[] = rainbowColors.map(c => Colors[c]);
IndexColorANSI code
0red\x1b[31m
1yellow\x1b[33m
2green\x1b[32m
3cyan\x1b[36m
4blue\x1b[34m
5magenta\x1b[35m

rainbowColorsExtended & rainbowExtendedASCIICodes

A 26-stop 8-bit palette used by rainbow(str, true) (smooth mode) and the progress bar "rainbow-smooth" animation. Colors span the full spectrum from bright red through orange, yellow, green, teal, cyan, blue, and into purple-magenta.

const rainbowColorsExtended: number[] = [
196, 202, 208, 214, 220, 226, // red → yellow
184, 190, 154, 118, 82, 46, // yellow → green
47, 48, 50, 51, 44, 39, 33, 27, 21, // green → blue
57, 93, 129, 165, 201, // blue → magenta
];

const rainbowExtendedASCIICodes: string[] = rainbowColorsExtended.map(c => getColorCode(eightBit(c), false));

rainbowPastelColors

A 7-stop pastel 8-bit palette (pink → peach → yellow → green → cyan → blue → purple) available for custom cycling. Not currently used by any built-in function but exported for manual use.

const rainbowPastelColors: number[] = [
217, // pastel pink
223, // pastel peach
229, // pastel yellow
120, // pastel green
159, // pastel cyan
147, // pastel blue
183, // pastel purple
];
IndexCodeDescription
0217pastel pink
1223pastel peach
2229pastel yellow
3120pastel green
4159pastel cyan
5147pastel blue
6183pastel purple

Usage

import { rainbowColors, rainbowASCIICodes, cls } from "ts-better-console";

// Cycle through the palette manually
const words = ["hello", "world"];
words.forEach((w, i) => {
const code = rainbowASCIICodes[i % rainbowASCIICodes.length];
process.stdout.write(code + w + cls + " ");
});

Want to support this project?

If you find ts-better-console useful and want to support its development, consider starring the GitHub repository or buying me a coffee! Your support helps me dedicate more time to improving the library and adding new features.

Want to contribute to this project?

Contributions are welcome! If you're interested in improving the library, fixing bugs, or adding new features, feel free to check out the GitHub repository and submit a pull request. Whether you're a seasoned developer or new to open source, your contributions can make a difference!