2023-02-25 22:57:53 +05:30
|
|
|
/*
|
|
|
|
|
2023-02-25 23:00:35 +05:30
|
|
|
Copyright 2022-2023 0xf8.dev@proton.me
|
2023-02-25 22:57:56 +05:30
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2023-02-25 22:57:53 +05:30
|
|
|
*/
|
|
|
|
|
2023-02-25 22:57:56 +05:30
|
|
|
#include <memory.h>
|
2023-02-25 22:57:53 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2023-02-25 22:57:56 +05:30
|
|
|
#include <time.h>
|
2023-02-25 22:57:53 +05:30
|
|
|
#include <unistd.h>
|
|
|
|
|
2023-02-25 22:57:54 +05:30
|
|
|
// How many milliseconds the program will wait until the next print ( DEFAULT = 100 )
|
2023-02-25 22:57:56 +05:30
|
|
|
#define CONF_SLEEP_TIMEMS (long)100
|
|
|
|
// How many seconds (in addition to millisecond above) the program will wait ( DEFAULT = 0 )
|
|
|
|
#define CONF_SLEEP_TIMESEC (time_t)0
|
2023-02-25 22:57:54 +05:30
|
|
|
// How many times a color should be shown before switching to the next ( DEFAULT = 2 )
|
2023-02-25 22:57:55 +05:30
|
|
|
#define CONF_COLOR_LAG 2
|
2023-02-25 22:57:54 +05:30
|
|
|
|
2023-02-25 22:57:54 +05:30
|
|
|
|
2023-02-25 22:57:56 +05:30
|
|
|
// RICERS:
|
|
|
|
// 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
|
2023-02-25 22:57:54 +05:30
|
|
|
};
|
|
|
|
|
2023-02-25 22:57:56 +05:30
|
|
|
unsigned long COLORS_SIZE = sizeof(COLORS) / sizeof(char *);
|
2023-02-25 22:57:54 +05:30
|
|
|
unsigned long long t = 0;
|
2023-02-25 22:57:53 +05:30
|
|
|
void genColors(char *s) {
|
2023-02-25 22:57:56 +05:30
|
|
|
char *cstr = (char *)malloc(64 + 1);
|
2023-02-25 22:57:53 +05:30
|
|
|
|
2023-02-25 22:57:56 +05:30
|
|
|
for (unsigned long i = 0; i < strlen(s); i++) {
|
2023-02-25 22:57:56 +05:30
|
|
|
unsigned long c = ((t + i) / CONF_COLOR_LAG) % COLORS_SIZE;
|
2023-02-25 22:57:56 +05:30
|
|
|
snprintf(cstr, 64, "\e[38;2;%sm", COLORS[c]);
|
2023-02-25 22:57:56 +05:30
|
|
|
printf("%s%c\e[0m",cstr,s[i]);
|
2023-02-25 22:57:53 +05:30
|
|
|
}
|
2023-02-25 22:57:56 +05:30
|
|
|
|
|
|
|
free(cstr);
|
2023-02-25 22:57:53 +05:30
|
|
|
}
|
|
|
|
|
2023-02-25 22:57:56 +05:30
|
|
|
int main(int argc, char **argv) {
|
|
|
|
if (argc < 2) {
|
2023-02-25 22:57:56 +05:30
|
|
|
// [ERROR] No arguments given. USAGE: ... <text>
|
2023-02-25 22:57:56 +05:30
|
|
|
printf("\e[1;31m[ERROR]\e[0m No arguments given.\n\tUSAGE: \e[34m%s \e[33m<text>\e[0m\n",argv[0]);
|
2023-02-25 22:57:53 +05:30
|
|
|
return 1;
|
|
|
|
}
|
2023-02-25 22:57:55 +05:30
|
|
|
|
2023-02-25 23:16:53 +05:30
|
|
|
uint reqSize = 0;
|
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
reqSize += strlen(argv[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *text = (char *)malloc(reqSize + argc);
|
2023-02-25 22:57:56 +05:30
|
|
|
|
2023-02-25 22:57:53 +05:30
|
|
|
// Adds all the arguments together with spaces seperating them
|
2023-02-25 22:57:56 +05:30
|
|
|
for (int i = 1, j = 0; i < argc; i++) {
|
|
|
|
for (unsigned int k = 0; k < strlen(argv[i]); k++, j++)
|
|
|
|
text[j] = argv[i][k];
|
2023-02-25 22:57:55 +05:30
|
|
|
|
|
|
|
text[j] = ' ';
|
|
|
|
j++;
|
2023-02-25 22:57:56 +05:30
|
|
|
}
|
2023-02-25 22:57:53 +05:30
|
|
|
|
2023-02-25 22:57:56 +05:30
|
|
|
struct timespec rem, req = {CONF_SLEEP_TIMESEC, CONF_SLEEP_TIMEMS*1000*1000};
|
2023-02-25 22:57:53 +05:30
|
|
|
while (1) {
|
2023-02-25 22:57:55 +05:30
|
|
|
printf("\r\e[2K");
|
2023-02-25 22:57:53 +05:30
|
|
|
genColors(text);
|
|
|
|
fflush(stdout);
|
2023-02-25 22:57:56 +05:30
|
|
|
nanosleep(&req, &rem);
|
2023-02-25 22:57:54 +05:30
|
|
|
t += 1;
|
2023-02-25 22:57:53 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2023-02-25 22:57:55 +05:30
|
|
|
}
|