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
1 changed files with 14 additions and 32 deletions

View File

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