Add support for ascii files in files
This commit is contained in:
parent
3648b00e16
commit
3c9d9d113c
4 changed files with 87 additions and 2 deletions
2
Makefile
2
Makefile
|
@ -32,7 +32,7 @@ debug:
|
||||||
install: build
|
install: build
|
||||||
cp $(NAME) $(DESTDIR)$(PREFIX)/$(NAME)
|
cp $(NAME) $(DESTDIR)$(PREFIX)/$(NAME)
|
||||||
ls $(DESTDIR)$(LIBDIR)/uwufetch > /dev/null || mkdir $(DESTDIR)$(LIBDIR)/uwufetch
|
ls $(DESTDIR)$(LIBDIR)/uwufetch > /dev/null || mkdir $(DESTDIR)$(LIBDIR)/uwufetch
|
||||||
cp res/* $(DESTDIR)$(LIBDIR)/uwufetch
|
cp -r res/* $(DESTDIR)$(LIBDIR)/uwufetch
|
||||||
cp ./$(NAME).1.gz $(DESTDIR)$(MANDIR)/
|
cp ./$(NAME).1.gz $(DESTDIR)$(MANDIR)/
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
|
|
8
res/ascii/arch.txt
Normal file
8
res/ascii/arch.txt
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{BLUE} /\
|
||||||
|
/ \
|
||||||
|
/\ \
|
||||||
|
/ > ω <\
|
||||||
|
/ __ \
|
||||||
|
/ __| |__-\
|
||||||
|
/_-'' ''-_\
|
||||||
|
|
7
res/ascii/unknown.txt
Normal file
7
res/ascii/unknown.txt
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{WHITE} ._.--._.
|
||||||
|
\|>{YELLOW}_{WHITE}< |/
|
||||||
|
|{YELLOW}:_/{WHITE} |
|
||||||
|
// \ \ ?
|
||||||
|
(| | ) /
|
||||||
|
{YELLOW}/'\_ _/`\{WHITE}-
|
||||||
|
{YELLOW}\___)=(___/
|
72
uwufetch.c
72
uwufetch.c
|
@ -101,7 +101,9 @@ int pkgman();
|
||||||
void parse_config();
|
void parse_config();
|
||||||
void get_info();
|
void get_info();
|
||||||
void list();
|
void list();
|
||||||
|
void replace(char *original, char *search, char *replacer);
|
||||||
void print_ascii();
|
void print_ascii();
|
||||||
|
void print_unknown_ascii();
|
||||||
void print_info();
|
void print_info();
|
||||||
void print_image();
|
void print_image();
|
||||||
void usage(char *);
|
void usage(char *);
|
||||||
|
@ -623,9 +625,72 @@ void list(char *arg)
|
||||||
NORMAL, BLUE, BLUE, PINK, MAGENTA, WHITE, GREEN, YELLOW, BLUE, WHITE); // Other/spare distributions colors
|
NORMAL, BLUE, BLUE, PINK, MAGENTA, WHITE, GREEN, YELLOW, BLUE, WHITE); // Other/spare distributions colors
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
This replaces all terms in a string with another term.
|
||||||
|
replace("Hello World!", "World", "everyone")
|
||||||
|
This returns "Hello everyone!".
|
||||||
|
*/
|
||||||
|
void replace(char *original, char *search, char *replacer) {
|
||||||
|
char buffer[4096];
|
||||||
|
char *ch;
|
||||||
|
if(!(ch = strstr(original, search))) return;
|
||||||
|
|
||||||
|
strncpy(buffer, original, ch-original);
|
||||||
|
buffer[ch-original] = 0;
|
||||||
|
sprintf(buffer+(ch - original), "%s%s", replacer, ch + strlen(search));
|
||||||
|
|
||||||
|
original[0] = 0;
|
||||||
|
strcpy(original, buffer);
|
||||||
|
return replace(original, search, replacer);
|
||||||
|
}
|
||||||
|
|
||||||
void print_ascii()
|
void print_ascii()
|
||||||
{ // prints logo (as ascii art) of the given system. distributions listed alphabetically.
|
{ // prints logo (as ascii art) of the given system. distributions listed alphabetically.
|
||||||
|
printf("\n");
|
||||||
|
FILE *file;
|
||||||
|
char ascii_file[1024];
|
||||||
|
// First tries to get ascii art file from local directory. Good when modifying these files.
|
||||||
|
sprintf(ascii_file, "./res/ascii/%s.txt", version_name);
|
||||||
|
file = fopen(ascii_file, "r");
|
||||||
|
// Now tries to get file from normal directory
|
||||||
|
if(!file) {
|
||||||
|
if(strcmp(version_name, "android") == 0) {
|
||||||
|
sprintf(ascii_file, "/data/data/com.termux/files/usr/lib/uwufetch/ascii/%s.txt", version_name);
|
||||||
|
} else {
|
||||||
|
sprintf(ascii_file, "/usr/lib/uwufetch/ascii/%s.txt", version_name);
|
||||||
|
}
|
||||||
|
file = fopen(ascii_file, "r");
|
||||||
|
if(!file) {
|
||||||
|
// Prevent infinite loops
|
||||||
|
if(strcmp(version_name, "unknown") == 0) {
|
||||||
|
printf("No\nunknown\nascii\nfile\n\n\n\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sprintf(version_name, "unknown");
|
||||||
|
return print_ascii();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
char line[64];
|
||||||
|
while(fgets(line, 64, file)) {
|
||||||
|
replace(line, "{NORMAL}", NORMAL);
|
||||||
|
replace(line, "{BOLD}", BOLD);
|
||||||
|
replace(line, "{BLACK}", BLACK);
|
||||||
|
replace(line, "{RED}", RED);
|
||||||
|
replace(line, "{GREEN}", GREEN);
|
||||||
|
replace(line, "{YELLOW}", YELLOW);
|
||||||
|
replace(line, "{BLUE}", BLUE);
|
||||||
|
replace(line, "{MAGENTA}", MAGENTA);
|
||||||
|
replace(line, "{CYAN}", CYAN);
|
||||||
|
replace(line, "{WHITE}", WHITE);
|
||||||
|
replace(line, "{PINK}", PINK);
|
||||||
|
replace(line, "{LPINK}", LPINK);
|
||||||
|
printf(line);
|
||||||
|
}
|
||||||
|
// Always set color to NORMAL, so there's no need to do this in every ascii file.
|
||||||
|
printf(NORMAL);
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
|
/*
|
||||||
// linux
|
// linux
|
||||||
if (strcmp(version_name, "alpine") == 0)
|
if (strcmp(version_name, "alpine") == 0)
|
||||||
{
|
{
|
||||||
|
@ -871,7 +936,12 @@ void print_ascii()
|
||||||
" (| | ) /\n"
|
" (| | ) /\n"
|
||||||
" %s/'\\_ _/`\\%s-\n"
|
" %s/'\\_ _/`\\%s-\n"
|
||||||
" %s\\___)=(___/\n\n",
|
" %s\\___)=(___/\n\n",
|
||||||
WHITE, YELLOW, WHITE, YELLOW, WHITE, YELLOW, WHITE, YELLOW);
|
WHITE, YELLOW, WHITE, YELLOW, WHITE, YELLOW, WHITE, YELLOW);*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_unknown_ascii() {
|
||||||
|
printf("\n\n\n\n\nidk man\n");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_image()
|
void print_image()
|
||||||
|
|
Loading…
Reference in a new issue