Skip to content

Instantly share code, notes, and snippets.

@ShivamJoker
Created May 26, 2022 09:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShivamJoker/ef0d21e9905edf17452122c0648e588a to your computer and use it in GitHub Desktop.
Save ShivamJoker/ef0d21e9905edf17452122c0648e588a to your computer and use it in GitHub Desktop.
Simple function which rendereds RGB color in your terminal console

Sample color pallete output

image

type RgbColor = {
r: number;
g: number;
b: number;
};
// Borrowed from https://stackoverflow.com/a/50984135/5748481
const toRgb = (_text: string, rgb: RgbColor)=> {
const { r, g, b } = rgb;
return "\x1b[38;2;" + r + ";" + g + ";" + b + "m" + _text + "\x1b[0m";
};
// usage
toRgb("hello", {r: 123, g: 223, b: 100})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment