diff --git a/src/common/ascii.h b/src/common/ascii.h index df4f71a..c16d50d 100644 --- a/src/common/ascii.h +++ b/src/common/ascii.h @@ -1,25 +1,41 @@ #ifndef __ASCII__ #define __ASCII__ -#define COLOR_BLACK "\x1b[30;1m" -#define COLOR_RED "\x1b[31;1m" -#define COLOR_GREEN "\x1b[32;1m" -#define COLOR_YELLOW "\x1b[33;1m" -#define COLOR_BLUE "\x1b[34;1m" -#define COLOR_MAGENTA "\x1b[35;1m" -#define COLOR_CYAN "\x1b[36;1m" -#define COLOR_WHITE "\x1b[37;1m" +#define COLOR_NONE "" +#define COLOR_FG_BLACK "\x1b[30;1m" +#define COLOR_FG_RED "\x1b[31;1m" +#define COLOR_FG_GREEN "\x1b[32;1m" +#define COLOR_FG_YELLOW "\x1b[33;1m" +#define COLOR_FG_BLUE "\x1b[34;1m" +#define COLOR_FG_MAGENTA "\x1b[35;1m" +#define COLOR_FG_CYAN "\x1b[36;1m" +#define COLOR_FG_WHITE "\x1b[37;1m" +#define COLOR_BG_BLACK "\x1b[40;1m" +#define COLOR_BG_RED "\x1b[41;1m" +#define COLOR_BG_GREEN "\x1b[42;1m" +#define COLOR_BG_YELLOW "\x1b[43;1m" +#define COLOR_BG_BLUE "\x1b[44;1m" +#define COLOR_BG_MAGENTA "\x1b[45;1m" +#define COLOR_BG_CYAN "\x1b[46;1m" +#define COLOR_BG_WHITE "\x1b[47;1m" +#define COLOR_RESET "\x1b[m" struct ascii_logo { char* art; uint32_t width; uint32_t height; + bool replace_blocks; char* color_ascii[8]; char* color_text[2]; }; -// 1 2 3 4 5 6 -//0123456789012345678901234567890123456789012345678901234567890 +/* + * Brief explanation: + * C1, C2, ...: ColorN, gets replaced by printer.c with + * the color in ascii_logo->color_ascii[N] + * CR: Color reset, gets replaced by the reset color by printer.c + */ + #define ASCII_AMD \ "$C2 '############### \ $C2 ,############# \ @@ -37,8 +53,6 @@ $C1 ######### ### ## ### ## ## \ $C1## ## ### ### ## ## \ $C1## ## ### ### ####### " -// 1 2 3 4 5 6 -// 123456789012345678901234567890123456789012345678901234567890 #define ASCII_INTEL \ "$C1 ################ \ $C1 ####### ####### \ @@ -86,19 +100,19 @@ $C1 ## ### ## # # # # ## ## $C2@@ @ @@ @@ \ $C1## ## ## ###### ##### # ## ## $C2@@ @@@@@@ @@ @@ " #define ASCII_EXYNOS \ -"$C1 \ -$C1 \ -$C1 \ -$C1 ## ## ## \ -$C1 ## ## \ -$C1 ## \ -$C1 ## ## \ -$C1 ## ## ## \ -$C1 \ +"$C2 \ +$C2 \ +$C2 \ + $C1##$CR $C1##$CR $C1##$CR \ + $C1##$CR $C1##$CR \ + $C1##$CR \ + $C1##$CR $C1##$CR \ + $C1##$CR $C1##$CR $C1##$CR \ +$C2 \ $C2 SAMSUNG \ $C2 Exynos \ -$C1 \ -$C1 " +$C2 \ +$C2 " #define ASCII_KIRIN \ "$C1 ####### \ @@ -144,44 +158,34 @@ $C1 ###### ## ### ### ## ### " // jp2a --height=17 ibm.jpg #define ASCII_IBM \ -"$C1######### ################ ######### ######### \ -$C1 \ -$C1######### ################## ########## ########## \ -$C1 \ -$C1 ##### ###### ###### #################### \ -$C1 \ -$C1 ##### ############## #################### \ -$C1 \ -$C1 ##### ###### ###### ##### ###### ##### \ -$C1 \ -$C1######### ################## ######## #### ######## \ -$C1 \ -$C1######### ################ ######## ## ######## " +"######### ################ ######### ######### \ + \ +######### ################## ########## ########## \ + \ + ##### ###### ###### #################### \ + \ + ##### ############## #################### \ + \ + ##### ###### ###### ##### ###### ##### \ + \ +######### ################## ######## #### ######## \ + \ +######### ################ ######## ## ######## " -// LOGO W H COLORS LOGO (>0 && <10) COLORS TEXT (=2) -// -------------------------------------------------------------------------------- -static struct ascii_logo logo_amd = { ASCII_AMD, 39, 15, {COLOR_WHITE, COLOR_GREEN}, {COLOR_WHITE, COLOR_GREEN} }; -static struct ascii_logo logo_intel = { ASCII_INTEL, 62, 19, {COLOR_CYAN}, {COLOR_CYAN, COLOR_WHITE} }; -static struct ascii_logo logo_snapd = { ASCII_SNAPD, 39, 16, {COLOR_RED, COLOR_WHITE}, {COLOR_RED, COLOR_WHITE} }; -static struct ascii_logo logo_mtk = { ASCII_MTK, 59, 5, {COLOR_BLUE, COLOR_YELLOW}, {COLOR_BLUE, COLOR_YELLOW} }; -static struct ascii_logo logo_exynos = { ASCII_EXYNOS, 22, 13, {COLOR_BLUE, COLOR_WHITE}, {COLOR_BLUE, COLOR_WHITE} }; -static struct ascii_logo logo_kirin = { ASCII_KIRIN, 53, 12, {COLOR_RED}, {COLOR_WHITE, COLOR_RED} }; -static struct ascii_logo logo_broadcom = { ASCII_BROADCOM, 44, 19, {COLOR_WHITE, COLOR_RED}, {COLOR_WHITE, COLOR_RED} }; -static struct ascii_logo logo_arm = { ASCII_ARM, 42, 5, {COLOR_CYAN}, {COLOR_WHITE, COLOR_CYAN} }; -static struct ascii_logo logo_ibm = { ASCII_IBM, 57, 13, {COLOR_CYAN, COLOR_WHITE}, {COLOR_CYAN, COLOR_WHITE} }; -static struct ascii_logo logo_unknown = { NULL, 0, 0, {"" }, {"", ""} }; +typedef struct ascii_logo asciiL; -static struct ascii_logo* ASCII_ARRAY [] = { - &logo_amd, - &logo_intel, - &logo_snapd, - &logo_mtk, - &logo_exynos, - &logo_kirin, - &logo_broadcom, - &logo_arm, - &logo_ibm, - &logo_unknown -}; +// ------------------------------------------------------------------------------------------------------ +// | LOGO | W | H | REPLACE | COLORS LOGO (>0 && <10) | COLORS TEXT (=2) | +// ------------------------------------------------------------------------------------------------------ +asciiL logo_amd = { ASCII_AMD, 39, 15, false, {COLOR_FG_WHITE, COLOR_FG_GREEN}, {COLOR_FG_WHITE, COLOR_FG_GREEN} }; +asciiL logo_intel = { ASCII_INTEL, 62, 19, false, {COLOR_FG_CYAN}, {COLOR_FG_CYAN, COLOR_FG_WHITE} }; +asciiL logo_snapd = { ASCII_SNAPD, 39, 16, false, {COLOR_FG_RED, COLOR_FG_WHITE}, {COLOR_FG_RED, COLOR_FG_WHITE} }; +asciiL logo_mtk = { ASCII_MTK, 59, 5, false, {COLOR_FG_BLUE, COLOR_FG_YELLOW}, {COLOR_FG_BLUE, COLOR_FG_YELLOW} }; +asciiL logo_exynos = { ASCII_EXYNOS, 22, 13, true, {COLOR_BG_BLUE, COLOR_FG_WHITE}, {COLOR_FG_BLUE, COLOR_FG_WHITE} }; +asciiL logo_kirin = { ASCII_KIRIN, 53, 12, false, {COLOR_FG_RED}, {COLOR_FG_WHITE, COLOR_FG_RED} }; +asciiL logo_broadcom = { ASCII_BROADCOM, 44, 19, false, {COLOR_FG_WHITE, COLOR_FG_RED}, {COLOR_FG_WHITE, COLOR_FG_RED} }; +asciiL logo_arm = { ASCII_ARM, 42, 5, false, {COLOR_FG_CYAN}, {COLOR_FG_WHITE, COLOR_FG_CYAN} }; +asciiL logo_ibm = { ASCII_IBM, 57, 13, true, {COLOR_BG_CYAN, COLOR_FG_WHITE}, {COLOR_FG_CYAN, COLOR_FG_WHITE} }; +asciiL logo_unknown = { NULL, 0, 0, false, {COLOR_NONE }, {COLOR_NONE, COLOR_NONE} }; #endif diff --git a/src/common/printer.c b/src/common/printer.c index fa6dcee..c92e5d8 100644 --- a/src/common/printer.c +++ b/src/common/printer.c @@ -28,25 +28,6 @@ #define max(a,b) (((a)>(b))?(a):(b)) #define MAX_ATTRIBUTES 100 -#define COLOR_NONE "" -#define COLOR_FG_BLACK "\x1b[30;1m" -#define COLOR_FG_RED "\x1b[31;1m" -#define COLOR_FG_GREEN "\x1b[32;1m" -#define COLOR_FG_YELLOW "\x1b[33;1m" -#define COLOR_FG_BLUE "\x1b[34;1m" -#define COLOR_FG_MAGENTA "\x1b[35;1m" -#define COLOR_FG_CYAN "\x1b[36;1m" -#define COLOR_FG_WHITE "\x1b[37;1m" -#define COLOR_BG_BLACK "\x1b[40;1m" -#define COLOR_BG_RED "\x1b[41;1m" -#define COLOR_BG_GREEN "\x1b[42;1m" -#define COLOR_BG_YELLOW "\x1b[43;1m" -#define COLOR_BG_BLUE "\x1b[44;1m" -#define COLOR_BG_MAGENTA "\x1b[45;1m" -#define COLOR_BG_CYAN "\x1b[46;1m" -#define COLOR_BG_WHITE "\x1b[47;1m" -#define COLOR_RESET "\x1b[m" - enum { #if defined(ARCH_X86) || defined(ARCH_PPC) ATTRIBUTE_NAME, @@ -307,11 +288,17 @@ uint32_t longest_attribute_length(struct ascii* art) { } #ifdef ARCH_X86 -void parse_print_color(struct ascii_logo* logo, uint32_t* logo_pos) { +void parse_print_color(struct ascii* art, uint32_t* logo_pos) { + struct ascii_logo* logo = art->art; char color_id_str = logo->art[*logo_pos + 2]; - int color_id = (color_id_str - '0') - 1; - printf("%s", logo->color_ascii[color_id]); + if(color_id_str == 'R') { + printf("%s", art->reset); + } + else { + int color_id = (color_id_str - '0') - 1; + printf("%s", logo->color_ascii[color_id]); + } *logo_pos+=3; } @@ -333,9 +320,13 @@ void print_ascii_x86(struct ascii* art, uint32_t la) { 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+1] == 'C') { - parse_print_color(logo, &logo_pos); + parse_print_color(art, &logo_pos); } - printf("%c", logo->art[logo_pos]); + if(logo->replace_blocks && logo->art[logo_pos] == '#') + printf("%s%c%s", logo->color_ascii[0], ' ', art->reset); + else + printf("%c", logo->art[logo_pos]); + logo_pos++; } printf("%s", art->reset); @@ -727,17 +718,6 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct color** cs) { #endif bool print_cpufetch(struct cpuInfo* cpu, STYLE s, struct color** cs) { - // Sanity check of ASCII arts - /*int len = sizeof(ASCII_ARRAY) / sizeof(ASCII_ARRAY[0]); - for(int i=0; i < len; i++) { - const struct ascii_logo* logo = ASCII_ARRAY[i]; - if(strlen(logo->art) != (logo->width * logo->height)) { - printBug("ASCII art %d is wrong! ASCII length: %d, expected length: %d", - i, strlen(logo->art), logo->height * logo->width); - return false; - } - }*/ - #ifdef ARCH_X86 return print_cpufetch_x86(cpu, s, cs); #elif ARCH_PPC