From 7cd578b889ca03990d032ee60bff0b99eb17613f Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Tue, 10 Aug 2021 10:32:08 +0200 Subject: [PATCH] [v0.99] Add color manually to ascii with replace=true and change the printing algorithm to support this new format --- src/common/ascii.h | 156 +++++++++++++++++++++++-------------------- src/common/printer.c | 30 +++++++-- 2 files changed, 108 insertions(+), 78 deletions(-) diff --git a/src/common/ascii.h b/src/common/ascii.h index 2e5e56b..3457461 100644 --- a/src/common/ascii.h +++ b/src/common/ascii.h @@ -36,12 +36,20 @@ struct ascii_logo { * the color in ascii_logo->color_ascii[N] * CR: Color reset, gets replaced by the reset * color by printer.c - * Logos with replace_blocks are replaced by character + * + * Logos with replace_blocks=true are replaced by character * blocks (actually, spaces with background color), so * the color in the structure must be COLOR_BG_XXX. When * replace_blocks is true, the characters '#' are replaced * by spaces printed with color_ascii[0], and '@' are - * printed with color_ascii[1] + * printed with color_ascii[1]. If replace_blocks=true, + * color format specified in ASCIIs ($C1, $C2) are ignored. + * + * In any case, '$' is a illegal character to be used in + * the ascii logos because it is used to parse colors + * + * LONG_LOGOS will be printed only if the fit in the screen, + * otherwise SHORT_LOGOS will be used */ // SHORT LOGOS // @@ -162,87 +170,87 @@ $C1 ###### ## ### ### ## ### " // jp2a --height=17 ibm.jpg #define ASCII_IBM \ -"######### ################ ######### ######### \ - \ -######### ################## ########## ########## \ - \ - ##### ###### ###### #################### \ - \ - ##### ############## #################### \ - \ - ##### ###### ###### ##### ###### ##### \ - \ -######### ################## ######## #### ######## \ - \ -######### ################ ######## ## ######## " +"$C1######### ################ ######### ######### \ +$C1 \ +$C1######### ################## ########## ########## \ +$C1 \ +$C1 ##### ###### ###### #################### \ +$C1 \ +$C1 ##### ############## #################### \ +$C1 \ +$C1 ##### ###### ###### ##### ###### ##### \ +$C1 \ +$C1######### ################## ######## #### ######## \ +$C1 \ +$C1######### ################ ######## ## ######## " // --------------------- LONG LOGOS ------------------------- // #define ASCII_AMD_L \ -" \ - \ - \ - \ - \ - \ - @@@@ @@@ @@@ @@@@@@@@ ############ \ - @@@@@@ @@@@@ @@@@@ @@@ @@@ ########## \ - @@@ @@@ @@@@@@@@@@@@@ @@@ @@ # ##### \ - @@@ @@@ @@@ @@@ @@@ @@@ @@ ### ##### \ - @@@@@@@@@@@@ @@@ @@@ @@@ @@@ ######### ### \ - @@@ @@@ @@@ @@@ @@@@@@@@@ ######## ## \ - \ - \ - \ - \ - \ - \ - " +"$C1 \ +$C1 \ +$C1 \ +$C1 \ +$C1 \ +$C1 \ +$C1 @@@@ @@@ @@@ @@@@@@@@ $C2 ############ \ +$C1 @@@@@@ @@@@@ @@@@@ @@@ @@@ $C2 ########## \ +$C1 @@@ @@@ @@@@@@@@@@@@@ @@@ @@ $C2 # ##### \ +$C1 @@@ @@@ @@@ @@@ @@@ @@@ @@ $C2 ### ##### \ +$C1 @@@@@@@@@@@@ @@@ @@@ @@@ @@@ $C2######### ### \ +$C1 @@@ @@@ @@@ @@@ @@@@@@@@@ $C2######## ## \ +$C1 \ +$C1 \ +$C1 \ +$C1 \ +$C1 \ +$C1 \ +$C1 " #define ASCII_INTEL_L \ -" ###############@ \ - ######@ ######@ \ - ###@ ###@ \ - ##@ ###@ \ - ##@ ##@ \ - ##@ ##@ \ - @ ##@ ##@ ##@ \ - #@ ##@ ########@ #####@ #####@ ##@ ##@ \ - #@ ##@ ##@ ##@ ##@ ###@ ###@ ##@ ##@ \ - #@ ##@ ##@ ##@ ##@ ##@ ##@ ##@ ##@ \ - #@ ##@ ##@ ##@ ##@ #########@ ##@ ###@ \ - #@ ##@ ##@ ##@ ##@ ##@ ##@ ####@ \ - #@ #@ ##@ ##@ ####@ ########@ #@ ##@ \ - ##@ \ - ##@ \ - ###@ ###@ \ - ####@ #########@ \ - #########@ ###############@ \ - ##############################@ " +"$C1 ###############@ \ +$C1 ######@ ######@ \ +$C1 ###@ ###@ \ +$C1 ##@ ###@ \ +$C1 ##@ ##@ \ +$C1 ##@ ##@ \ +$C1 @ ##@ ##@ ##@ \ +$C1 #@ ##@ ########@ #####@ #####@ ##@ ##@ \ +$C1 #@ ##@ ##@ ##@ ##@ ###@ ###@ ##@ ##@ \ +$C1 #@ ##@ ##@ ##@ ##@ ##@ ##@ ##@ ##@ \ +$C1 #@ ##@ ##@ ##@ ##@ #########@ ##@ ###@ \ +$C1 #@ ##@ ##@ ##@ ##@ ##@ ##@ ####@ \ +$C1 #@ #@ ##@ ##@ ####@ ########@ #@ ##@ \ +$C1 ##@ \ +$C1 ##@ \ +$C1 ###@ ###@ \ +$C1 ####@ #########@ \ +$C1 #########@ ###############@ \ +$C1 ##############################@ " #define ASCII_ARM_L \ -" ############ ########## #### ###### ######## \ - ############### ######### ####################### \ - #### #### #### ##### ####### ##### \ -#### #### #### #### ##### #### \ -#### #### #### #### #### #### \ - #### ##### #### #### #### #### \ - ############### #### #### #### #### \ - ######## #### #### #### #### #### " +"$C1 ############ ########## #### ###### ######## \ +$C1 ############### ######### ####################### \ +$C1 #### #### #### ##### ####### ##### \ +$C1#### #### #### #### ##### #### \ +$C1#### #### #### #### #### #### \ +$C1 #### ##### #### #### #### #### \ +$C1 ############### #### #### #### #### \ +$C1 ######## #### #### #### #### #### " #define ASCII_IBM_L \ -" ############ ################ ########## ########## \ - \ - ############ ################## ############ ############ \ - \ - ###### ###### ###### #################### \ - \ - ###### ############## #################### \ - \ - ###### ###### ###### ##### ###### ##### \ - \ - ############ ################## ######### #### ######### \ - \ - ############ ################ ######### ## ######### " +"$C1 ############ ################ ########## ########## \ +$C1 \ +$C1 ############ ################## ############ ############ \ +$C1 \ +$C1 ###### ###### ###### #################### \ +$C1 \ +$C1 ###### ############## #################### \ +$C1 \ +$C1 ###### ###### ###### ##### ###### ##### \ +$C1 \ +$C1 ############ ################## ######### #### ######### \ +$C1 \ +$C1 ############ ################ ######### ## ######### " typedef struct ascii_logo asciiL; diff --git a/src/common/printer.c b/src/common/printer.c index 7edfb0b..a3d42db 100644 --- a/src/common/printer.c +++ b/src/common/printer.c @@ -204,6 +204,25 @@ bool ascii_fits_screen(int termw, struct ascii_logo logo, int lf) { return termw - ((int) logo.width + lf) >= 0; } +// TODO: Instead of using a function to do so, change ascii.h +// and store an color ID that is converted to BG or FG depending +// on logo->replace_blocks +void replace_bgbyfg_color(struct ascii_logo* logo) { + // Replace background by foreground color + for(int i=0; i < 2; i++) { + if(logo->color_ascii[i] == NULL) break; + + if(strcmp(logo->color_ascii[i], COLOR_BG_BLACK) == 0) strcpy(logo->color_ascii[i], COLOR_FG_BLACK); + else if(strcmp(logo->color_ascii[i], COLOR_BG_RED) == 0) strcpy(logo->color_ascii[i], COLOR_FG_RED); + else if(strcmp(logo->color_ascii[i], COLOR_BG_GREEN) == 0) strcpy(logo->color_ascii[i], COLOR_FG_GREEN); + else if(strcmp(logo->color_ascii[i], COLOR_BG_YELLOW) == 0) strcpy(logo->color_ascii[i], COLOR_FG_YELLOW); + else if(strcmp(logo->color_ascii[i], COLOR_BG_BLUE) == 0) strcpy(logo->color_ascii[i], COLOR_FG_BLUE); + else if(strcmp(logo->color_ascii[i], COLOR_BG_MAGENTA) == 0) strcpy(logo->color_ascii[i], COLOR_FG_MAGENTA); + else if(strcmp(logo->color_ascii[i], COLOR_BG_CYAN) == 0) strcpy(logo->color_ascii[i], COLOR_FG_CYAN); + else if(strcmp(logo->color_ascii[i], COLOR_BG_WHITE) == 0) strcpy(logo->color_ascii[i], COLOR_FG_WHITE); + } +} + void choose_ascii_art(struct ascii* art, struct color** cs, struct terminal* term, int lf) { // 1. Choose logo #ifdef ARCH_X86 @@ -260,6 +279,7 @@ void choose_ascii_art(struct ascii* art, struct color** cs, struct terminal* ter break; case STYLE_RETRO: logo->replace_blocks = false; + replace_bgbyfg_color(logo); // fall through case STYLE_FANCY: if(cs != NULL) { @@ -323,8 +343,9 @@ void print_ascii_generic(struct ascii* art, uint32_t la) { // 1. Print logo if(space_up > 0 || (space_up + n >= 0 && space_up + n < (int)logo->height)) { for(uint32_t i=0; i < logo->width; i++) { - if(logo->art[logo_pos] == '$' || logo->art[logo_pos] == '\x1b') { - parse_print_color(art, &logo_pos); + if(logo->art[logo_pos] == '$') { + if(logo->replace_blocks) logo_pos += 3; + else parse_print_color(art, &logo_pos); } if(logo->replace_blocks && logo->art[logo_pos] != ' ') { if(logo->art[logo_pos] == '#') printf("%s%c%s", logo->color_ascii[0], ' ', art->reset); @@ -521,8 +542,9 @@ void print_ascii_arm(struct ascii* art, uint32_t la) { // 1. Print logo if(n >= (int) art->additional_spaces && n < (int) logo->height + (int) art->additional_spaces) { for(uint32_t i=0; i < logo->width; i++) { - if(logo->art[logo_pos] == '$' && logo->art[logo_pos+1] == 'C') { - parse_print_color(art, &logo_pos); + if(logo->art[logo_pos] == '$') { + if(logo->replace_blocks) logo_pos += 3; + else parse_print_color(art, &logo_pos); } if(logo->replace_blocks && logo->art[logo_pos] != ' ') { if(logo->art[logo_pos] == '#') printf("%s%c%s", logo->color_ascii[0], ' ', art->reset);