-
Notifications
You must be signed in to change notification settings - Fork 0
/
colors.c
115 lines (92 loc) · 2.05 KB
/
colors.c
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifdef _WIN32
#include <windows.h>
#include <stdio.h>
#include "colors.h"
#include <stdlib.h>
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
#endif
static HANDLE stdoutHandle;
static DWORD outModeInit;
void setupConsole(void) {
DWORD outMode = 0;
stdoutHandle = GetStdHandle(STD_OUTPUT_HANDLE);
if(stdoutHandle == INVALID_HANDLE_VALUE) {
exit(GetLastError());
}
if(!GetConsoleMode(stdoutHandle, &outMode)) {
exit(GetLastError());
}
outModeInit = outMode;
outMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
if(!SetConsoleMode(stdoutHandle, outMode)) {
exit(GetLastError());
}
}
void clear_screen() {
system("cls");
}
void change_bg_color(select_color x){
if (x == red)
printf("\x1b[41m");
if (x == blue)
printf("\x1b[44m");
if (x == white)
printf("\x1b[107m");
}
void reset_color(){
printf("\x1b[40m\x1b[97m");
}
void change_fg_color(select_color x){
if(x == red)
printf("\x1b[31m");
if(x == blue)
printf("\x1b[34m");
if(x == black)
printf("\x1b[30m");
if(x == yellow)
printf("\x1b[33m");
if(x == green)
printf("\x1b[92m");
}
void cprint(select_color x,char buffer[200]){
change_fg_color(x);
printf("%s",buffer);
reset_color();
}
#else
#include <stdio.h>
#include "colors.h"
#include <stdlib.h>
void setupConsole(){
}
void change_bg_color(select_color x){
if (x == red)
printf("\x1b[41m");
if (x == blue)
printf("\x1b[44m");
if (x == white)
printf("\x1b[107m");
}
void reset_color(){
printf("\x1b[40m\x1b[97m");
}
void change_fg_color(select_color x){
if (x == red)
printf("\x1b[31m");
if (x == blue)
printf("\x1b[34m");
if (x == black)
printf("\x1b[30m");
if (x == yellow)
printf("\x1b[33m");
}
void clear_screen() {
system("clear");
}
void cprint(select_color x,char buffer[200]){
change_fg_color(x);
printf("%s",buffer);
reset_color();
}
#endif