New color system; it's now a simple array
Signed-off-by: 0xf8 <0xf8.dev@proton.me>
This commit is contained in:
parent
3068ed3461
commit
526a64e982
59
rbtext.c
59
rbtext.c
@ -18,61 +18,43 @@ I DON'T CARE HOW YOU USE OR CONFIGURE THIS PROGRAM.
|
|||||||
// How many times a color should be shown before switching to the next ( DEFAULT = 2 )
|
// How many times a color should be shown before switching to the next ( DEFAULT = 2 )
|
||||||
#define CONF_COLOR_LAG 2
|
#define CONF_COLOR_LAG 2
|
||||||
|
|
||||||
// BEWARE RICERS
|
|
||||||
// If you add extra colors make sure to
|
|
||||||
// a) Add it to the color enum
|
|
||||||
// b) Add the case to the switch statement in the genColors function
|
|
||||||
// c) Update the COLORS definition with the new amount of colors
|
|
||||||
// FORMAT
|
|
||||||
// #define COLOR "R;G;B"
|
|
||||||
#define RED "193;71;87"
|
|
||||||
#define ORANGE "193;116;71"
|
|
||||||
#define YELLOW "193;177;71"
|
|
||||||
#define GREEN "149;193;71"
|
|
||||||
#define CYAN "71;193;161"
|
|
||||||
#define BLUE "71;165;193"
|
|
||||||
#define PURPLE "155;71;193"
|
|
||||||
#define PINK "193;71;153"
|
|
||||||
#define COLORS 8
|
|
||||||
|
|
||||||
enum color {
|
// RICERS:
|
||||||
red,orange,yellow,green,cyan,blue,purple,pink
|
// To add colors, simply add the color (according to the format below) to COLORS
|
||||||
|
// FORMAT: "R;G;B",
|
||||||
|
const char *COLORS[] = {
|
||||||
|
"193;71;87", // RED
|
||||||
|
"193;116;71", // ORANGE
|
||||||
|
"193;177;71", // YELLOW
|
||||||
|
"149;193;71", // GREEN
|
||||||
|
"71;193;161", // CYAN
|
||||||
|
"71;165;193", // BLUE
|
||||||
|
"155;71;193", // PURPLE
|
||||||
|
"193;71;153", // 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) {
|
||||||
char *cstr = malloc(20 * sizeof(char));
|
char *cstr = (char *)malloc(20 * sizeof(char) + 1);
|
||||||
for (int i = 0; i < strlen(s); i++) {
|
|
||||||
enum color c = (((t + i) / CONF_COLOR_LAG) % COLORS);
|
|
||||||
|
|
||||||
switch (c) {
|
for (unsigned long i = 0; i < strlen(s); i++) {
|
||||||
//addcase(enum value, #define name)
|
unsigned long c = (((t + i) / CONF_COLOR_LAG) % (sizeof(COLORS) / sizeof(char *)));
|
||||||
addcase(red, RED);
|
snprintf(cstr, 20 * sizeof(char), "\e[38;2;%sm", COLORS[c]);
|
||||||
addcase(orange, ORANGE);
|
printf("%s%c\e[0m",cstr,s[i]);
|
||||||
addcase(yellow, YELLOW);
|
|
||||||
addcase(green, GREEN);
|
|
||||||
addcase(cyan, CYAN);
|
|
||||||
addcase(blue, BLUE);
|
|
||||||
addcase(purple, PURPLE);
|
|
||||||
addcase(pink, PINK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%s%c",cstr,s[i]);
|
free(cstr);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int carg, char **varg) {
|
int main(int carg, char **varg) {
|
||||||
if (carg < 2) {
|
if (carg < 2) {
|
||||||
|
// [ERROR] No arguments given. USAGE: ... <text>
|
||||||
printf("\e[1;31m[ERROR]\e[0m No arguments given.\n\tUSAGE: \e[34m%s \e[33m<text>\e[0m\n",varg[0]);
|
printf("\e[1;31m[ERROR]\e[0m No arguments given.\n\tUSAGE: \e[34m%s \e[33m<text>\e[0m\n",varg[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *text = malloc(1024 * sizeof(char));
|
char *text = (char *)malloc(1024 * sizeof(char) + 1);
|
||||||
|
|
||||||
// Similar to pythons str.join(' ') method
|
// Similar to pythons str.join(' ') method
|
||||||
// Adds all the arguments together with spaces seperating them
|
// Adds all the arguments together with spaces seperating them
|
||||||
@ -89,7 +71,6 @@ int main(int carg, char **varg) {
|
|||||||
while (1) {
|
while (1) {
|
||||||
printf("\r\e[2K");
|
printf("\r\e[2K");
|
||||||
genColors(text);
|
genColors(text);
|
||||||
printf("\e[0m");
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
usleep(CONF_SLEEP_TIMEMS*1000);
|
usleep(CONF_SLEEP_TIMEMS*1000);
|
||||||
t += 1;
|
t += 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user