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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
/* Texte coloré en console sous windows
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <ctype.h> // pour la fonction toupper() qui transforme les lettres en majuscules, l'inverse tolower()
#ifdef __linux__
#include <dirent.h> // parcourir et afficher les dossiers sous linux
#include <unistd.h> // sleep(secondes) et usleep(microsecondes)
#define CLEAR system("clear"); // efface la console sous linux
#define PAUSE getchar(); // fait une pause dans un programme sous linux
#define RESET_COLOR "\x1B[0m" // pas de ;
#define SLEEP(ms) usleep((ms) * 1000); // temps d'affichage en millisecondes sous linux
#elif defined(_WIN32) || defined(_WIN64)
#include <windows.h> // gestion des couleurs sous windows
#define CLEAR system("cls"); // efface la console sous windows
#define PAUSE system("pause"); // fait une pause dans un programme sous windows
#define RESET_COLOR color(15,0);
#define SLEEP(ms) Sleep(ms); // temps d'affichage en millisecondes sous windows
#endif
void color(int t,int f) // fonction permettant l'affichage des couleurs du texte en console sous windows
{
HANDLE H=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(H,f*16+t);
}
int main()
{
printf("\n Test - C programming text color windows ! ");
printf("\n--------------------------------");
color(15,0); // 15 pour le texte en blanc, 0 pour le fond noir
printf("\n WHITE \n");
color(0,15); // 0 pour le texte en noir, 15 pour le fond blanc
printf(" BLACK with withe background \n");
color(4,0); // 4 pour le texte en rouge, 0 pour le fond noir
printf(" RED "); RESET_COLOR printf(" (RED not visible) \n");
color(12,15); // 12 pour le texte en rouge clair, 0 pour le fond blanc
printf(" LIGHTRED with withe background \n");
color(12,0);
printf(" LIGHTRED with black background "); RESET_COLOR printf(" (LIGHTRED with black background) \n");
color(1,0);
printf(" BLUE "); RESET_COLOR printf(" (BLUE not visible) \n");
color(9,0);
printf(" LIGHTBLUE with black background "); RESET_COLOR printf(" (LIGHTBLUE with black background) \n");
color(9,15);
printf(" LIGHTBLUE with withe background \n");
color(2,0);
printf(" GREEN \n");
color(5,0);
printf(" MAGENTA \n");
color(14,0);
printf(" YELLOW \n");
color(3,0);
printf(" CYAN \n");
color(7,0);
printf(" LIGHT GRAY \n\n");
RESET_COLOR
PAUSE
return EXIT_SUCCESS;
} |
Partager