1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| /* If possible, display the 256 colours. Only for Linux
*
* with bash
* foreground: \33[38;5;${code}m
* background: \33[48;5;${code}m
*
* with C
* foreground: \033[38;5;codem
* background: \033[45;5;codem
*/
#include <stdio.h>
#define FIRST_SYSTEM_COLOUR 0
#define END_SYSTEM_COLOUR 16
#define FIRST_NORMAL_COLOUR 16
#define END_NORMAL_COLOUR 232
#define BEGIN_GREY_COLOUR 232
#define END_GREY_COLOUR 256
int main(void)
{
/* Print the 16 first colours, known as system colours */
puts("System colours :");
for(unsigned char colour = FIRST_SYSTEM_COLOUR; colour < END_SYSTEM_COLOUR; colour++)
{
printf("\033[48;5;%hhum ", colour);
}
puts("\033[0m\n");
/* The 216 colours */
puts("Color cube: 6x6x6");
for(unsigned char colour = FIRST_NORMAL_COLOUR, space = 0; colour < END_NORMAL_COLOUR; colour++, espace++)
{
if(espace % 6 == 0)
{
fputs("\033[0m ", stdout);
}
if(espace % 36 == 0)
{
puts("\033[0m");
}
printf("\033[48;5;%hhum ", colour);
}
puts("\033[0m\n");
/* And the grey colours */
puts("Greyscale ramp");
for (unsigned char colour = BEGIN_GREY_COLOUR ; colour < END_GREY_COLOUR; colour++)
{
printf("\033[48;5;%hhum ", colour);
}
puts("\033[0m\n");
return 0;
} |
Partager