C-chat
console-color.h
Go to the documentation of this file.
1 
7 #ifndef C_CHAT_CONSOLE_COLOR_H
8 #define C_CHAT_CONSOLE_COLOR_H
9 
10 #include "../common/interop.h"
11 
17 void setTextColor(unsigned int colorCode);
18 
26 void resetColor();
27 
28 #if IS_POSIX
29 
30 #include <stdio.h>
31 
36 #define FG_RED 31
37 
41 #define FG_YELLOW 33
42 
46 #define FG_WHITE 39
47 
51 #define FG_BLUE 96
52 
56 #define FG_GREEN 32
57 
58 void setTextColor(unsigned int colorCode) {
59  printf("\033[%dm", colorCode);
60 }
61 
62 #elif IS_WINDOWS
63 
64 #ifndef WIN32_LEAN_AND_MEAN
65 #include <windows.h>
66 #define WIN32_LEAN_AND_MEAN
67 #endif
68 
73 #define FG_RED FOREGROUND_RED | FOREGROUND_INTENSITY
74 
78 #define FG_YELLOW FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY
79 
83 #define FG_WHITE FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY
84 
88 #define FG_BLUE FOREGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_GREEN
89 
93 #define FG_GREEN FOREGROUND_INTENSITY | FOREGROUND_GREEN
94 
95 
96 void setTextColor(unsigned int colorCode) {
97  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), colorCode);
98 }
99 
100 #endif
101 
102 // Implementing here so macros got defined an have associated value
103 void resetColor() {
104  setTextColor(FG_WHITE);
105 }
106 
107 #endif //C_CHAT_CONSOLE_COLOR_H
setTextColor
void setTextColor(unsigned int colorCode)
Sets output text color.
resetColor
void resetColor()
Set output text color to white.
Definition: console-color.h:103