Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stefanofiorentino/aa0e76dadfd1fdb0cb0267c28363e306 to your computer and use it in GitHub Desktop.
Save stefanofiorentino/aa0e76dadfd1fdb0cb0267c28363e306 to your computer and use it in GitHub Desktop.
c/c++ function to translate RGB bash terminal colot
// based on https://gist.github.com/mhulse/b11e568260fb8c3aa2a8
void UserLedManager::print_terminal_background_color(const int &r, const int &g, const int &b) const
{
auto r_weight = r < 75 ? 0 : (r - 35) / 40;
auto g_weight = g < 75 ? 0 : (g - 35) / 40;
auto b_weight = b < 75 ? 0 : (b - 35) / 40;
int status = (r_weight * 6 * 6 + g_weight * 6 + b_weight + 16);
fprintf(stdout, "\e[48;5;%dm %3d \e[0m", status, status);
fflush(stdout);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment