change the case definitions to macros

Signed-off-by: 0xf8 <0xf8.dev@proton.me>
This commit is contained in:
0xf8 2023-02-25 12:27:54 -05:00
parent 5d6a297295
commit e9c15019ea
Signed by: 0xf8
GPG Key ID: 446580D758689584

View File

@ -39,6 +39,11 @@ enum color {
red,orange,yellow,green,cyan,blue,purple,pink red,orange,yellow,green,cyan,blue,purple,pink
}; };
#define addcase(enum, defin)\
case enum:\
cstr = "\e[38;2;"defin"m";\
break;
unsigned long long t = 0; unsigned long long t = 0;
void genColors(char *s) { void genColors(char *s) {
for (int i = 0; i < strlen(s); i++) { for (int i = 0; i < strlen(s); i++) {
@ -46,38 +51,15 @@ void genColors(char *s) {
char *cstr = malloc(256*sizeof(char)); char *cstr = malloc(256*sizeof(char));
switch (c) { switch (c) {
case red: //addcase(enum value, #define name)
cstr = "\e[38;2;"RED"m"; addcase(red, RED);
break; addcase(orange, ORANGE);
addcase(yellow, YELLOW);
case orange: addcase(green, GREEN);
cstr = "\e[38;2;"ORANGE"m"; addcase(cyan, CYAN);
break; addcase(blue, BLUE);
addcase(purple, PURPLE);
case yellow: addcase(pink, PINK);
cstr = "\e[38;2;"YELLOW"m";
break;
case green:
cstr = "\e[38;2;"GREEN"m";
break;
case cyan:
cstr = "\e[38;2;"CYAN"m";
break;
case blue:
cstr = "\e[38;2;"BLUE"m";
break;
case purple:
cstr = "\e[38;2;"PURPLE"m";
break;
case pink:
cstr = "\e[38;2;"PINK"m";
break;
} }
printf("%s%c",cstr,s[i]); printf("%s%c",cstr,s[i]);