Skip to content

Instantly share code, notes, and snippets.

@kevinetienne
Created May 3, 2011 20:34
Show Gist options
  • Save kevinetienne/954169 to your computer and use it in GitHub Desktop.
Save kevinetienne/954169 to your computer and use it in GitHub Desktop.
playing with term color
/* Set the color : only for Linux
*
* with bash
* foreground \33[38;5;${code}m
* background \33[48;5;${code}m
*
* with c
* fg: \e[38;5;codem
* bg: \e[45;5;codem
*
*/
#include <stdio.h>
int main()
{
/* Initialise the main variables
* colour: for the 256 colours (0-255)
* space: to insert space or newline
*/
int colour = 0;
int space = 0;
/* Print the 16 first colours, known as colours system */
printf("System colours:\n");
for( ; colour < 16; colour++) {
printf("\e[48;5;%dm ", colour);
}
printf("\e[0m\n\n");
/* The 216 colours */
printf("Color cube: 6x6x6\n");
for ( ; colour < 232; colour++, space++) {
if ((space%6) == 0) {
printf("\e[0m ");
}
if ((space%36 == 0)) {
printf("\e[0m\n");
}
printf("\e[48;5;%dm ", colour);
}
printf("\e[0m\n\n");
/* And the grey colours */
printf("Greayscale ramp\n");
for ( ; colour < 256; colour++) {
printf("\e[48;5;%dm ", colour);
}
printf("\e[0m\n\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment