From 490d9f6566666fcd1a71a65db674779c23724cad Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Sun, 8 Aug 2021 09:13:17 +0200 Subject: [PATCH 01/21] [v0.99] Initial idea to allow printing non-fixed sized logos (each logo with a different w/h) --- src/common/ascii.h | 27 +++++++++----------- src/common/printer.c | 59 +++++++++----------------------------------- 2 files changed, 24 insertions(+), 62 deletions(-) diff --git a/src/common/ascii.h b/src/common/ascii.h index bd77ac9..610ecf4 100644 --- a/src/common/ascii.h +++ b/src/common/ascii.h @@ -4,6 +4,12 @@ #define NUMBER_OF_LINES 19 #define LINE_SIZE 62 +struct ascii_logo { + char* art; + int width; + int height; +}; + #define AMD_ASCII \ " \ \ @@ -25,6 +31,8 @@ \ " +// 1 2 3 4 5 6 +//3456789012345678901234567890123456789012345678901234567890 #define INTEL_ASCII \ " ################ \ ####### ####### \ @@ -45,7 +53,7 @@ ##### ########## \ ########## ################ \ ############################### " - + #define SNAPDRAGON_ASCII \ " \ @@######## \ @@ -150,7 +158,7 @@ ######################## \ ############### \ " - + #define ARM_ASCII \ " \ \ @@ -215,18 +223,7 @@ \ \ " - -static const char* ASCII_ARRAY [] = { - AMD_ASCII, - INTEL_ASCII, - ARM_ASCII, - SNAPDRAGON_ASCII, - MEDIATEK_ASCII, - EXYNOS_ASCII, - KIRIN_ASCII, - BROADCOM_ASCII, - IBM_ASCII, - UNKNOWN_ASCII -}; +static struct ascii_logo logo_intel = { INTEL_ASCII, 62, 19 }; +static struct ascii_logo logo_amd = { AMD_ASCII, 62, 19 }; #endif diff --git a/src/common/printer.c b/src/common/printer.c index f256fc0..90e5e14 100644 --- a/src/common/printer.c +++ b/src/common/printer.c @@ -111,7 +111,7 @@ struct attribute { }; struct ascii { - char art[NUMBER_OF_LINES][LINE_SIZE+1]; + struct ascii_logo* art; char color1_ascii[100]; char color2_ascii[100]; char color1_text[100]; @@ -166,8 +166,8 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct color** cs) { #ifdef ARCH_X86 if(art->vendor == CPU_VENDOR_INTEL) { - COL_FANCY_1 = COLOR_BG_CYAN; - COL_FANCY_2 = COLOR_BG_WHITE; + COL_FANCY_1 = COLOR_FG_CYAN; + COL_FANCY_2 = COLOR_FG_WHITE; COL_FANCY_3 = COLOR_FG_CYAN; COL_FANCY_4 = COLOR_FG_WHITE; art->ascii_chars[0] = '#'; @@ -278,8 +278,8 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct color** cs) { break; case STYLE_FANCY: if(cs != NULL) { - COL_FANCY_1 = rgb_to_ansi(cs[0], true, true); - COL_FANCY_2 = rgb_to_ansi(cs[1], true, true); + COL_FANCY_1 = rgb_to_ansi(cs[0], false, true); + COL_FANCY_2 = rgb_to_ansi(cs[1], false, true); COL_FANCY_3 = rgb_to_ansi(cs[2], false, true); COL_FANCY_4 = rgb_to_ansi(cs[3], false, true); } @@ -323,9 +323,9 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct color** cs) { char tmp[NUMBER_OF_LINES * LINE_SIZE + 1]; #ifdef ARCH_X86 if(art->vendor == CPU_VENDOR_INTEL) - strcpy(tmp, INTEL_ASCII); + art->art = &logo_intel; else if(art->vendor == CPU_VENDOR_AMD) - strcpy(tmp, AMD_ASCII); + art->art = &logo_amd; else strcpy(tmp, UNKNOWN_ASCII); #elif ARCH_PPC @@ -345,9 +345,6 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct color** cs) { strcpy(tmp, ARM_ASCII); #endif - for(int i=0; i < NUMBER_OF_LINES; i++) - memcpy(art->art[i], tmp + i*LINE_SIZE, LINE_SIZE); - return art; } @@ -367,39 +364,14 @@ uint32_t longest_attribute_length(struct ascii* art) { #ifdef ARCH_X86 void print_algorithm_intel(struct ascii* art, int n, bool* flag) { - for(int i=0; i < LINE_SIZE; i++) { - if(*flag) { - if(art->art[n][i] == ' ') { - *flag = false; - printf("%s%c%s", art->color2_ascii, art->ascii_chars[1], art->reset); - } - else { - printf("%s%c%s", art->color1_ascii, art->ascii_chars[0], art->reset); - } - } - else { - if(art->art[n][i] != ' ' && art->art[n][i] != '\0') { - *flag = true; - printf("%c",' '); - } - else { - printf("%c",' '); - } - } + struct ascii_logo* logo = art->art; + + for(int i=0; i < logo->width; i++) { + printf("%s%c%s", art->color1_ascii, logo->art[n * logo->width + i], art->reset); } } void print_algorithm_amd(struct ascii* art, int n, bool* flag) { - *flag = false; // dummy, just silence compiler error - - for(int i=0; i < LINE_SIZE; i++) { - if(art->art[n][i] == '@') - printf("%s%c%s", art->color1_ascii, art->ascii_chars[0], art->reset); - else if(art->art[n][i] == '#') - printf("%s%c%s", art->color2_ascii, art->ascii_chars[1], art->reset); - else - printf("%c",art->art[n][i]); - } } void print_ascii_x86(struct ascii* art, uint32_t la, void (*callback_print_algorithm)(struct ascii* art, int i, bool* flag)) { @@ -814,14 +786,7 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct color** cs) { 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 char* ascii = ASCII_ARRAY[i]; - if(strlen(ascii) != (NUMBER_OF_LINES * LINE_SIZE)) { - printBug("ASCII art %d is wrong! ASCII length: %d, expected length: %d", i, strlen(ascii), (NUMBER_OF_LINES * LINE_SIZE)); - return false; - } - } + // TODO with new logos #ifdef ARCH_X86 return print_cpufetch_x86(cpu, s, cs); From 783785e3129065c7afcef203115ab44d31d0cb5b Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Sun, 8 Aug 2021 09:44:07 +0200 Subject: [PATCH 02/21] [v0.99] Create structs for all logos and remove width/height constants --- src/common/ascii.h | 63 +++++++++++++++++++++++++-------------- src/common/printer.c | 71 ++++++++++++++++++-------------------------- 2 files changed, 70 insertions(+), 64 deletions(-) diff --git a/src/common/ascii.h b/src/common/ascii.h index 610ecf4..6178833 100644 --- a/src/common/ascii.h +++ b/src/common/ascii.h @@ -1,16 +1,13 @@ #ifndef __ASCII__ #define __ASCII__ -#define NUMBER_OF_LINES 19 -#define LINE_SIZE 62 - struct ascii_logo { char* art; - int width; - int height; + uint32_t width; + uint32_t height; }; -#define AMD_ASCII \ +#define ASCII_AMD \ " \ \ \ @@ -33,7 +30,7 @@ struct ascii_logo { // 1 2 3 4 5 6 //3456789012345678901234567890123456789012345678901234567890 -#define INTEL_ASCII \ +#define ASCII_INTEL \ " ################ \ ####### ####### \ #### #### \ @@ -54,7 +51,7 @@ struct ascii_logo { ########## ################ \ ############################### " -#define SNAPDRAGON_ASCII \ +#define ASCII_SNAPD \ " \ @@######## \ @@@@@########### \ @@ -74,8 +71,8 @@ struct ascii_logo { @@@@########### \ \ " - -#define MEDIATEK_ASCII \ + +#define ASCII_MTK \ " \ \ \ @@ -96,7 +93,7 @@ struct ascii_logo { \ " -#define EXYNOS_ASCII \ +#define ASCII_EXYNOS \ " \ \ \ @@ -116,8 +113,8 @@ struct ascii_logo { \ \ " - -#define KIRIN_ASCII \ + +#define ASCII_KIRIN \ " \ \ \ @@ -136,9 +133,9 @@ struct ascii_logo { ######################### \ ######################### \ \ - " - -#define BROADCOM_ASCII \ + " + +#define ASCII_BROADCOM \ " \ ################ \ ########################## \ @@ -159,7 +156,7 @@ struct ascii_logo { ############### \ " -#define ARM_ASCII \ +#define ASCII_ARM \ " \ \ \ @@ -178,10 +175,10 @@ struct ascii_logo { \ \ \ - " + " // jp2a --height=17 ibm.jpg -#define IBM_ASCII \ +#define ASCII_IBM \ " \ \ \ @@ -203,7 +200,7 @@ struct ascii_logo { " -#define UNKNOWN_ASCII \ +#define ASCII_UNKNOWN \ " \ \ \ @@ -223,7 +220,29 @@ struct ascii_logo { \ \ " -static struct ascii_logo logo_intel = { INTEL_ASCII, 62, 19 }; -static struct ascii_logo logo_amd = { AMD_ASCII, 62, 19 }; + +static struct ascii_logo logo_amd = { ASCII_AMD, 62, 19 }; +static struct ascii_logo logo_intel = { ASCII_INTEL, 62, 19 }; +static struct ascii_logo logo_snapd = { ASCII_SNAPD, 62, 19 }; +static struct ascii_logo logo_mtk = { ASCII_MTK, 62, 19 }; +static struct ascii_logo logo_exynos = { ASCII_EXYNOS, 62, 19 }; +static struct ascii_logo logo_kirin = { ASCII_KIRIN, 62, 19 }; +static struct ascii_logo logo_broadcom = { ASCII_BROADCOM, 62, 19 }; +static struct ascii_logo logo_arm = { ASCII_ARM, 62, 19 }; +static struct ascii_logo logo_ibm = { ASCII_IBM, 62, 19 }; +static struct ascii_logo logo_unknown = { ASCII_UNKNOWN, 62, 19 }; + +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 +}; #endif diff --git a/src/common/printer.c b/src/common/printer.c index 90e5e14..ca4949d 100644 --- a/src/common/printer.c +++ b/src/common/printer.c @@ -320,29 +320,28 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct color** cs) { return NULL; } - char tmp[NUMBER_OF_LINES * LINE_SIZE + 1]; #ifdef ARCH_X86 if(art->vendor == CPU_VENDOR_INTEL) art->art = &logo_intel; else if(art->vendor == CPU_VENDOR_AMD) art->art = &logo_amd; else - strcpy(tmp, UNKNOWN_ASCII); + art->art = &logo_unknown; #elif ARCH_PPC - strcpy(tmp, IBM_ASCII); + art->art = &logo_ibm; #elif ARCH_ARM if(art->vendor == SOC_VENDOR_SNAPDRAGON) - strcpy(tmp, SNAPDRAGON_ASCII); + art->art = &logo_snapd; else if(art->vendor == SOC_VENDOR_MEDIATEK) - strcpy(tmp, MEDIATEK_ASCII); + art->art = &logo_mtk; else if(art->vendor == SOC_VENDOR_EXYNOS) - strcpy(tmp, EXYNOS_ASCII); + art->art = &logo_exynos; else if(art->vendor == SOC_VENDOR_KIRIN) - strcpy(tmp, KIRIN_ASCII); + art->art = &logo_kirin; else if(art->vendor == SOC_VENDOR_BROADCOM) - strcpy(tmp, BROADCOM_ASCII); + art->art = &logo_broadcom; else - strcpy(tmp, ARM_ASCII); + art->art = &logo_unknown; #endif return art; @@ -363,31 +362,22 @@ uint32_t longest_attribute_length(struct ascii* art) { } #ifdef ARCH_X86 -void print_algorithm_intel(struct ascii* art, int n, bool* flag) { +void print_ascii_x86(struct ascii* art, uint32_t la) { struct ascii_logo* logo = art->art; - - for(int i=0; i < logo->width; i++) { - printf("%s%c%s", art->color1_ascii, logo->art[n * logo->width + i], art->reset); - } -} - -void print_algorithm_amd(struct ascii* art, int n, bool* flag) { -} - -void print_ascii_x86(struct ascii* art, uint32_t la, void (*callback_print_algorithm)(struct ascii* art, int i, bool* flag)) { int attr_to_print = 0; int attr_type; char* attr_value; uint32_t space_right; - uint32_t space_up = (NUMBER_OF_LINES - art->n_attributes_set)/2; - uint32_t space_down = NUMBER_OF_LINES - art->n_attributes_set - space_up; - bool flag = false; + uint32_t space_up = (logo->height - art->n_attributes_set)/2; + uint32_t space_down = logo->height - art->n_attributes_set - space_up; printf("\n"); - for(uint32_t n=0;nheight; n++) { + for(uint32_t i=0; i < logo->width; i++) { + printf("%s%c%s", art->color1_ascii, logo->art[n * logo->width + i], art->reset); + } - if(n > space_up-1 && n < NUMBER_OF_LINES-space_down) { + if(n > space_up-1 && n < logo->height - space_down) { attr_type = art->attributes[attr_to_print]->type; attr_value = art->attributes[attr_to_print]->value; attr_to_print++; @@ -400,24 +390,12 @@ void print_ascii_x86(struct ascii* art, uint32_t la, void (*callback_print_algor printf("\n"); } -void print_ascii(struct ascii* art) { - uint32_t longest_attribute = longest_attribute_length(art); - - if(art->vendor == CPU_VENDOR_INTEL) - print_ascii_x86(art, longest_attribute, &print_algorithm_intel); - else if(art->vendor == CPU_VENDOR_AMD) - print_ascii_x86(art, longest_attribute, &print_algorithm_amd); - else { - printBug("Invalid CPU vendor: %d\n", art->vendor); - } - -} - bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs) { struct ascii* art = set_ascii(get_cpu_vendor(cpu), s, cs); if(art == NULL) return false; + struct ascii_logo* logo = art->art; char* uarch = get_str_uarch(cpu); char* manufacturing_process = get_str_process(cpu); char* sockets = get_str_sockets(cpu->topo); @@ -460,12 +438,13 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs) { } setAttribute(art,ATTRIBUTE_PEAK,pp); - if(art->n_attributes_set > NUMBER_OF_LINES) { + if(art->n_attributes_set > logo->height) { printBug("The number of attributes set is bigger than the max that can be displayed"); return false; } - print_ascii(art); + uint32_t longest_attribute = longest_attribute_length(art); + print_ascii_x86(art, longest_attribute); free(manufacturing_process); free(max_frequency); @@ -786,7 +765,15 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct color** cs) { bool print_cpufetch(struct cpuInfo* cpu, STYLE s, struct color** cs) { // Sanity check of ASCII arts - // TODO with new logos + 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); From 13263141033141506a38db0a4a702d2e89beba0c Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Sun, 8 Aug 2021 11:47:03 +0200 Subject: [PATCH 03/21] [v0.99] Set colors in the logo struct, instead of deducing them from the CPU manufacturer --- src/common/ascii.h | 169 +++++++++++++++++++++++-------------------- src/common/printer.c | 94 +++++++----------------- 2 files changed, 118 insertions(+), 145 deletions(-) diff --git a/src/common/ascii.h b/src/common/ascii.h index 6178833..2fbb39c 100644 --- a/src/common/ascii.h +++ b/src/common/ascii.h @@ -1,10 +1,21 @@ #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" + struct ascii_logo { char* art; uint32_t width; uint32_t height; + char* color_ascii[8]; + char* color_text[2]; }; #define ASCII_AMD \ @@ -14,12 +25,12 @@ struct ascii_logo { \ \ \ - @@@@ @@@ @@@ @@@@@@@@ ############ \ - @@@@@@ @@@@@ @@@@@ @@@ @@@ ########## \ - @@@ @@@ @@@@@@@@@@@@@ @@@ @@ # ##### \ - @@@ @@@ @@@ @@@ @@@ @@@ @@ ### ##### \ - @@@@@@@@@@@@ @@@ @@@ @@@ @@@ ######### ### \ - @@@ @@@ @@@ @@@ @@@@@@@@@ ######## ## \ +$C1 @@@@ @@@ @@@ @@@@@@@@ $C2############ \ +$C1 @@@@@@ @@@@@ @@@@@ @@@ @@@ $C2########## \ +$C1 @@@ @@@ @@@@@@@@@@@@@ @@@ @@ $C2# ##### \ +$C1 @@@ @@@ @@@ @@@ @@@ @@@ @@ $C2### ##### \ +$C1 @@@@@@@@@@@@ @@@ @@@ @@@ @@@ $C2######### ### \ +$C1 @@@ @@@ @@@ @@@ @@@@@@@@@ $C2######## ## \ \ \ \ @@ -28,47 +39,47 @@ struct ascii_logo { \ " -// 1 2 3 4 5 6 -//3456789012345678901234567890123456789012345678901234567890 +// 1 2 3 4 5 6 +// 123456789012345678901234567890123456789012345678901234567890 #define ASCII_INTEL \ -" ################ \ - ####### ####### \ - #### #### \ - ### #### \ - ### ### \ - ### ### \ - # ### ### ### \ - ## ### ######### ###### ###### ### ### \ - ## ### ### ### ### #### #### ### ### \ - ## ### ### ### ### ### ### ### ### \ -## ### ### ### ### ########## ### #### \ -## ### ### ### ### ### ### ##### \ -## ## ### ### ##### ######### ## ### \ -### \ - ### \ - #### #### \ - ##### ########## \ - ########## ################ \ - ############################### " +"$C1 ################ \ +$C1 ####### ####### \ +$C1 #### #### \ +$C1 ### #### \ +$C1 ### ### \ +$C1 ### ### \ +$C1 # ### ### ### \ +$C1 ## ### ######### ###### ###### ### ### \ +$C1 ## ### ### ### ### #### #### ### ### \ +$C1 ## ### ### ### ### ### ### ### ### \ +$C1## ### ### ### ### ########## ### #### \ +$C1## ### ### ### ### ### ### ##### \ +$C1## ## ### ### ##### ######### ## ### \ +$C1### \ +$C1 ### \ +$C1 #### #### \ +$C1 ##### ########## \ +$C1 ########## ################ \ +$C1 ############################### " #define ASCII_SNAPD \ " \ - @@######## \ - @@@@@########### \ - @@ @@@@@################# \ - @@@@@@@@@@#################### \ - @@@@@@@@@@@@##################### \ - @@@@@@@@@@@@@@@#################### \ - @@@@@@@@@@@@@@@@@################### \ - @@@@@@@@@@@@@@@@@@@@################ \ - @@@@@@@@@@@@@@@@@@@@############# \ - @@@@@@@@@@@@@@@@@@############ \ - @ @@@@@@@@@@@@@@@########### \ - @@@@@ @@@@@@@@@@@@@########## \ - @@@@@@@@@ @@@@@@@@@@@@######## \ - @@@@@@@@@ @@@@@@@@@@####### \ - @@@@@@@@@@@@@@@@####### \ - @@@@########### \ + $C1@@$C2######## \ + $C1@@@@@$C2########### \ + $C1@@ @@@@@$C2################# \ + $C1@@@@@@@@@@$C2#################### \ + $C1@@@@@@@@@@@@$C2##################### \ + $C1@@@@@@@@@@@@@@@$C2#################### \ + $C1@@@@@@@@@@@@@@@@@$C2################### \ + $C1@@@@@@@@@@@@@@@@@@@@$C2################ \ + $C1@@@@@@@@@@@@@@@@@@@@$C2############# \ + $C1@@@@@@@@@@@@@@@@@@$C2############ \ + $C1@ @@@@@@@@@@@@@@@$C2########### \ + $C1@@@@@ @@@@@@@@@@@@@$C2########## \ + $C1@@@@@@@@@ @@@@@@@@@@@@$C2######## \ + $C1@@@@@@@@@ @@@@@@@@@@$C2####### \ + $C1@@@@@@@@@@@@@@@@$C2####### \ + $C1@@@@$C2########### \ \ " @@ -79,11 +90,11 @@ struct ascii_logo { \ \ \ - ## ## ###### ###### # ### @@@@@@ @@@@@@ @@ @@ \ - ### ### # # # # #### @@ @ @@ @@ \ - ######## # ### # # # ## ## @@ @ @@@ @@@@ \ - ## ### ## # # # # ## ## @@ @ @@ @@ \ - ## ## ## ###### ##### # ## ## @@ @@@@@@ @@ @@ \ + $C1## ## ###### ###### # ### $C2@@@@@@ @@@@@@ @@ @@ \ + $C1### ### # # # # #### $C2@@ @ @@ @@ \ + $C1######## # ### # # # ## ## $C2@@ @ @@@ @@@@ \ + $C1## ### ## # # # # ## ## $C2@@ @ @@ @@ \ + $C1## ## ## ###### ##### # ## ## $C2@@ @@@@@@ @@ @@ \ \ \ \ @@ -100,14 +111,14 @@ struct ascii_logo { \ \ \ - ## ## ## \ - ## ## \ - ## \ - ## ## \ - ## ## ## \ - \ - SAMSUNG \ - Exynos \ + $C1## ## ## \ + $C1## ## \ + $C1## \ + $C1## ## \ + $C1## ## ## \ + \ + $C2SAMSUNG \ + $C2Exynos \ \ \ \ @@ -120,18 +131,18 @@ struct ascii_logo { \ \ \ - ####### \ - ##### #################### \ - ###################################### \ - ####################################### \ - ####################################### \ - ############################## \ - ########################## \ - ######################### \ - ######################## \ - ######################## \ - ######################### \ - ######################### \ +$C1 ####### \ +$C1 ##### #################### \ +$C1 ###################################### \ +$C1 ####################################### \ +$C1 ####################################### \ +$C1 ############################## \ +$C1 ########################## \ +$C1 ######################### \ +$C1 ######################## \ +$C1 ######################## \ +$C1 ######################### \ +$C1 ######################### \ \ " @@ -221,16 +232,18 @@ struct ascii_logo { \ " -static struct ascii_logo logo_amd = { ASCII_AMD, 62, 19 }; -static struct ascii_logo logo_intel = { ASCII_INTEL, 62, 19 }; -static struct ascii_logo logo_snapd = { ASCII_SNAPD, 62, 19 }; -static struct ascii_logo logo_mtk = { ASCII_MTK, 62, 19 }; -static struct ascii_logo logo_exynos = { ASCII_EXYNOS, 62, 19 }; -static struct ascii_logo logo_kirin = { ASCII_KIRIN, 62, 19 }; -static struct ascii_logo logo_broadcom = { ASCII_BROADCOM, 62, 19 }; -static struct ascii_logo logo_arm = { ASCII_ARM, 62, 19 }; -static struct ascii_logo logo_ibm = { ASCII_IBM, 62, 19 }; -static struct ascii_logo logo_unknown = { ASCII_UNKNOWN, 62, 19 }; +// LOGO W H COLORS LOGO (>0 && <10) COLORS TEXT (=2) +// -------------------------------------------------------------------------------- +static struct ascii_logo logo_amd = { ASCII_AMD, 62, 19, {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, 62, 19, {COLOR_RED, COLOR_WHITE}, {COLOR_RED, COLOR_WHITE} }; +static struct ascii_logo logo_mtk = { ASCII_MTK, 62, 19, {COLOR_BLUE, COLOR_YELLOW}, {COLOR_BLUE, COLOR_YELLOW} }; +static struct ascii_logo logo_exynos = { ASCII_EXYNOS, 62, 19, {COLOR_BLUE, COLOR_WHITE}, {COLOR_BLUE, COLOR_WHITE}, }; +static struct ascii_logo logo_kirin = { ASCII_KIRIN, 62, 19, {COLOR_WHITE, COLOR_RED}, {COLOR_WHITE, COLOR_RED} }; +static struct ascii_logo logo_broadcom = { ASCII_BROADCOM, 62, 19, {COLOR_WHITE, COLOR_RED}, {COLOR_WHITE, COLOR_RED} }; +static struct ascii_logo logo_arm = { ASCII_ARM, 62, 19, {COLOR_CYAN}, {COLOR_WHITE, COLOR_CYAN} }; +static struct ascii_logo logo_ibm = { ASCII_IBM, 62, 19, {COLOR_CYAN, COLOR_WHITE}, {COLOR_CYAN, COLOR_WHITE}, }; +static struct ascii_logo logo_unknown = { ASCII_UNKNOWN, 62, 19, {COLOR_BLUE}, {COLOR_BLUE} }; static struct ascii_logo* ASCII_ARRAY [] = { &logo_amd, diff --git a/src/common/printer.c b/src/common/printer.c index ca4949d..954d82b 100644 --- a/src/common/printer.c +++ b/src/common/printer.c @@ -112,11 +112,6 @@ struct attribute { struct ascii { struct ascii_logo* art; - char color1_ascii[100]; - char color2_ascii[100]; - char color1_text[100]; - char color2_text[100]; - char ascii_chars[2]; char reset[100]; struct attribute** attributes; uint32_t n_attributes_set; @@ -151,7 +146,7 @@ char* rgb_to_ansi(struct color* c, bool background, bool bold) { } struct ascii* set_ascii(VENDOR vendor, STYLE style, struct color** cs) { - char *COL_FANCY_1, *COL_FANCY_2, *COL_FANCY_3, *COL_FANCY_4, *COL_RETRO_1, *COL_RETRO_2, *COL_RETRO_3, *COL_RETRO_4; + char *COL_FANCY_1, *COL_FANCY_2, *COL_RETRO_1, *COL_RETRO_2; struct ascii* art = emalloc(sizeof(struct ascii)); art->n_attributes_set = 0; art->additional_spaces = 0; @@ -168,16 +163,10 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct color** cs) { if(art->vendor == CPU_VENDOR_INTEL) { COL_FANCY_1 = COLOR_FG_CYAN; COL_FANCY_2 = COLOR_FG_WHITE; - COL_FANCY_3 = COLOR_FG_CYAN; - COL_FANCY_4 = COLOR_FG_WHITE; - art->ascii_chars[0] = '#'; } else if(art->vendor == CPU_VENDOR_AMD) { COL_FANCY_1 = COLOR_BG_WHITE; COL_FANCY_2 = COLOR_BG_GREEN; - COL_FANCY_3 = COLOR_FG_WHITE; - COL_FANCY_4 = COLOR_FG_GREEN; - art->ascii_chars[0] = '@'; } else { printBug("Invalid CPU vendor in set_ascii (%d)", art->vendor); @@ -186,58 +175,36 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct color** cs) { #elif ARCH_PPC COL_FANCY_1 = COLOR_BG_CYAN; COL_FANCY_2 = COLOR_BG_WHITE; - COL_FANCY_3 = COLOR_FG_CYAN; - COL_FANCY_4 = COLOR_FG_WHITE; art->ascii_chars[0] = '#'; #elif ARCH_ARM if(art->vendor == SOC_VENDOR_SNAPDRAGON) { COL_FANCY_1 = COLOR_BG_RED; COL_FANCY_2 = COLOR_BG_WHITE; - COL_FANCY_3 = COLOR_FG_RED; - COL_FANCY_4 = COLOR_FG_WHITE; - art->ascii_chars[0] = '@'; } else if(art->vendor == SOC_VENDOR_MEDIATEK) { - COL_FANCY_1 = COLOR_BG_BLUE; - COL_FANCY_2 = COLOR_BG_YELLOW; - COL_FANCY_3 = COLOR_FG_WHITE; - COL_FANCY_4 = COLOR_FG_BLUE; - art->ascii_chars[0] = '@'; + COL_FANCY_1 = COLOR_FG_WHITE; + COL_FANCY_2 = COLOR_FG_BLUE; } else if(art->vendor == SOC_VENDOR_EXYNOS) { COL_FANCY_1 = COLOR_BG_BLUE; COL_FANCY_2 = COLOR_BG_WHITE; - COL_FANCY_3 = COLOR_FG_BLUE; - COL_FANCY_4 = COLOR_FG_WHITE; - art->ascii_chars[0] = '@'; } else if(art->vendor == SOC_VENDOR_KIRIN) { COL_FANCY_1 = COLOR_BG_WHITE; COL_FANCY_2 = COLOR_BG_RED; - COL_FANCY_3 = COLOR_FG_WHITE; - COL_FANCY_4 = COLOR_FG_RED; - art->ascii_chars[0] = '@'; } else if(art->vendor == SOC_VENDOR_BROADCOM) { COL_FANCY_1 = COLOR_BG_WHITE; COL_FANCY_2 = COLOR_BG_RED; - COL_FANCY_3 = COLOR_FG_WHITE; - COL_FANCY_4 = COLOR_FG_RED; - art->ascii_chars[0] = '@'; } else { - COL_FANCY_1 = COLOR_BG_CYAN; - COL_FANCY_2 = COLOR_BG_CYAN; - COL_FANCY_3 = COLOR_FG_WHITE; - COL_FANCY_4 = COLOR_FG_CYAN; - art->ascii_chars[0] = '#'; + COL_FANCY_1 = COLOR_FG_WHITE; + COL_FANCY_2 = COLOR_FG_CYAN; } #endif - COL_RETRO_1 = COL_FANCY_3; - COL_RETRO_2 = COL_FANCY_4; - COL_RETRO_3 = COL_RETRO_1; - COL_RETRO_4 = COL_RETRO_2; - art->ascii_chars[1] = '#'; + // TODO + COL_RETRO_1 = COL_FANCY_1; + COL_RETRO_2 = COL_FANCY_2; #ifdef _WIN32 // Old Windows do not define the flag @@ -270,48 +237,26 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct color** cs) { switch(art->style) { case STYLE_LEGACY: - strcpy(art->color1_ascii, COLOR_NONE); - strcpy(art->color2_ascii, COLOR_NONE); - strcpy(art->color1_text, COLOR_NONE); - strcpy(art->color2_text, COLOR_NONE); art->reset[0] = '\0'; break; case STYLE_FANCY: if(cs != NULL) { COL_FANCY_1 = rgb_to_ansi(cs[0], false, true); COL_FANCY_2 = rgb_to_ansi(cs[1], false, true); - COL_FANCY_3 = rgb_to_ansi(cs[2], false, true); - COL_FANCY_4 = rgb_to_ansi(cs[3], false, true); } - art->ascii_chars[0] = ' '; - art->ascii_chars[1] = ' '; - strcpy(art->color1_ascii,COL_FANCY_1); - strcpy(art->color2_ascii,COL_FANCY_2); - strcpy(art->color1_text,COL_FANCY_3); - strcpy(art->color2_text,COL_FANCY_4); if(cs != NULL) { free(COL_FANCY_1); free(COL_FANCY_2); - free(COL_FANCY_3); - free(COL_FANCY_4); } break; case STYLE_RETRO: if(cs != NULL) { COL_RETRO_1 = rgb_to_ansi(cs[0], false, true); COL_RETRO_2 = rgb_to_ansi(cs[1], false, true); - COL_RETRO_3 = rgb_to_ansi(cs[2], false, true); - COL_RETRO_4 = rgb_to_ansi(cs[3], false, true); } - strcpy(art->color1_ascii,COL_RETRO_1); - strcpy(art->color2_ascii,COL_RETRO_2); - strcpy(art->color1_text,COL_RETRO_3); - strcpy(art->color2_text,COL_RETRO_4); if(cs != NULL) { free(COL_RETRO_1); free(COL_RETRO_2); - free(COL_RETRO_3); - free(COL_RETRO_4); } break; case STYLE_INVALID: @@ -362,6 +307,15 @@ uint32_t longest_attribute_length(struct ascii* art) { } #ifdef ARCH_X86 +void parse_print_color(struct ascii_logo* logo, uint32_t* logo_pos) { + char color_id_str = logo->art[*logo_pos + 2]; + int color_id = (color_id_str - '0') - 1; + + printf("%s", logo->color_ascii[color_id]); + + *logo_pos+=3; +} + void print_ascii_x86(struct ascii* art, uint32_t la) { struct ascii_logo* logo = art->art; int attr_to_print = 0; @@ -370,12 +324,18 @@ void print_ascii_x86(struct ascii* art, uint32_t la) { uint32_t space_right; uint32_t space_up = (logo->height - art->n_attributes_set)/2; uint32_t space_down = logo->height - art->n_attributes_set - space_up; + uint32_t logo_pos = 0; printf("\n"); for(uint32_t n=0; n < logo->height; n++) { for(uint32_t i=0; i < logo->width; i++) { - printf("%s%c%s", art->color1_ascii, logo->art[n * logo->width + i], art->reset); + if(logo->art[logo_pos] == '$' && logo->art[logo_pos+1] == 'C') { + parse_print_color(logo, &logo_pos); + } + printf("%c", logo->art[logo_pos]); + logo_pos++; } + printf("%s", art->reset); if(n > space_up-1 && n < logo->height - space_down) { attr_type = art->attributes[attr_to_print]->type; @@ -383,7 +343,7 @@ void print_ascii_x86(struct ascii* art, uint32_t la) { attr_to_print++; space_right = 1 + (la - strlen(ATTRIBUTE_FIELDS[attr_type])); - printf("%s%s%s%*s%s%s%s\n", art->color1_text, ATTRIBUTE_FIELDS[attr_type], art->reset, space_right, "", art->color2_text, attr_value, art->reset); + printf("%s%s%s%*s%s%s%s\n", logo->color_text[0], ATTRIBUTE_FIELDS[attr_type], art->reset, space_right, "", logo->color_text[1], attr_value, art->reset); } else printf("\n"); } @@ -765,7 +725,7 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct color** cs) { 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]); + /*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)) { @@ -773,7 +733,7 @@ bool print_cpufetch(struct cpuInfo* cpu, STYLE s, struct color** cs) { i, strlen(logo->art), logo->height * logo->width); return false; } - } + }*/ #ifdef ARCH_X86 return print_cpufetch_x86(cpu, s, cs); From b7c32fcd4acbca3bb85fc2086a362b4826f423c3 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Sun, 8 Aug 2021 12:53:16 +0200 Subject: [PATCH 04/21] [v0.99] Center automatically logo and text, when logo is longer than text and viceversa (before this commit only the first case was supported) --- src/common/ascii.h | 19 +++---------------- src/common/printer.c | 35 +++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/common/ascii.h b/src/common/ascii.h index 2fbb39c..9f4d7a6 100644 --- a/src/common/ascii.h +++ b/src/common/ascii.h @@ -19,25 +19,12 @@ struct ascii_logo { }; #define ASCII_AMD \ -" \ - \ - \ - \ - \ - \ -$C1 @@@@ @@@ @@@ @@@@@@@@ $C2############ \ +"$C1 @@@@ @@@ @@@ @@@@@@@@ $C2############ \ $C1 @@@@@@ @@@@@ @@@@@ @@@ @@@ $C2########## \ $C1 @@@ @@@ @@@@@@@@@@@@@ @@@ @@ $C2# ##### \ $C1 @@@ @@@ @@@ @@@ @@@ @@@ @@ $C2### ##### \ $C1 @@@@@@@@@@@@ @@@ @@@ @@@ @@@ $C2######### ### \ -$C1 @@@ @@@ @@@ @@@ @@@@@@@@@ $C2######## ## \ - \ - \ - \ - \ - \ - \ - " +$C1 @@@ @@@ @@@ @@@ @@@@@@@@@ $C2######## ## " // 1 2 3 4 5 6 // 123456789012345678901234567890123456789012345678901234567890 @@ -234,7 +221,7 @@ $C1 ######################### \ // LOGO W H COLORS LOGO (>0 && <10) COLORS TEXT (=2) // -------------------------------------------------------------------------------- -static struct ascii_logo logo_amd = { ASCII_AMD, 62, 19, {COLOR_WHITE, COLOR_GREEN}, {COLOR_WHITE, COLOR_GREEN} }; +static struct ascii_logo logo_amd = { ASCII_AMD, 62, 6, {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, 62, 19, {COLOR_RED, COLOR_WHITE}, {COLOR_RED, COLOR_WHITE} }; static struct ascii_logo logo_mtk = { ASCII_MTK, 62, 19, {COLOR_BLUE, COLOR_YELLOW}, {COLOR_BLUE, COLOR_YELLOW} }; diff --git a/src/common/printer.c b/src/common/printer.c index 954d82b..8f2248e 100644 --- a/src/common/printer.c +++ b/src/common/printer.c @@ -322,22 +322,31 @@ void print_ascii_x86(struct ascii* art, uint32_t la) { int attr_type; char* attr_value; uint32_t space_right; - uint32_t space_up = (logo->height - art->n_attributes_set)/2; - uint32_t space_down = logo->height - art->n_attributes_set - space_up; + int32_t space_up = ((int)logo->height - (int)art->n_attributes_set)/2; + int32_t space_down = (int)logo->height - (int)art->n_attributes_set - (int)space_up; uint32_t logo_pos = 0; + int32_t iters = max(logo->height, art->n_attributes_set); printf("\n"); - for(uint32_t n=0; n < logo->height; n++) { - 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); + for(int32_t n=0; n < iters; n++) { + // 1. Print logo + if(space_up > 0 || (space_up + n >= 0 && n + space_down < (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); + } + printf("%c", logo->art[logo_pos]); + logo_pos++; } - printf("%c", logo->art[logo_pos]); - logo_pos++; + printf("%s", art->reset); + } + else { + // If logo should not be printed, fill with spaces + printf("%*c", logo->width, ' '); } - printf("%s", art->reset); - if(n > space_up-1 && n < logo->height - space_down) { + // 2. Print text + if(space_up < 0 || (n > space_up-1 && n < (int)logo->height - space_down)) { attr_type = art->attributes[attr_to_print]->type; attr_value = art->attributes[attr_to_print]->value; attr_to_print++; @@ -355,7 +364,6 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs) { if(art == NULL) return false; - struct ascii_logo* logo = art->art; char* uarch = get_str_uarch(cpu); char* manufacturing_process = get_str_process(cpu); char* sockets = get_str_sockets(cpu->topo); @@ -398,11 +406,6 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs) { } setAttribute(art,ATTRIBUTE_PEAK,pp); - if(art->n_attributes_set > logo->height) { - printBug("The number of attributes set is bigger than the max that can be displayed"); - return false; - } - uint32_t longest_attribute = longest_attribute_length(art); print_ascii_x86(art, longest_attribute); From 43b25c15e392ffc8d38a2caffe916cf9d0a21d02 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Sun, 8 Aug 2021 16:40:24 +0200 Subject: [PATCH 05/21] [v0.99] New AMD logo --- src/common/ascii.h | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/common/ascii.h b/src/common/ascii.h index 9f4d7a6..469b440 100644 --- a/src/common/ascii.h +++ b/src/common/ascii.h @@ -18,13 +18,24 @@ struct ascii_logo { char* color_text[2]; }; +// 1 2 3 4 5 6 +//0123456789012345678901234567890123456789012345678901234567890 #define ASCII_AMD \ -"$C1 @@@@ @@@ @@@ @@@@@@@@ $C2############ \ -$C1 @@@@@@ @@@@@ @@@@@ @@@ @@@ $C2########## \ -$C1 @@@ @@@ @@@@@@@@@@@@@ @@@ @@ $C2# ##### \ -$C1 @@@ @@@ @@@ @@@ @@@ @@@ @@ $C2### ##### \ -$C1 @@@@@@@@@@@@ @@@ @@@ @@@ @@@ $C2######### ### \ -$C1 @@@ @@@ @@@ @@@ @@@@@@@@@ $C2######## ## " +"$C2 '::::::::::::::: \ +$C2 ,ccccccccccccc \ +$C2 .cccc \ +$C2 ;. .cccc \ +$C2 ::c. .cccc \ +$C2 :ccc. .cccc \ +$C2 cccc:::::. :cc \ +$C2 ccccccc. ; \ + \ +$C1 @@@@ @@@ @@@ @@@@@@@@ \ +$C1 @@@@@@ @@@@@ @@@@@ @@@ @@@ \ +$C1 @@@ @@@ @@@@@@@@@@@@@ @@@ @@ \ +$C1 @@@ @@@ @@@ @@@ @@@ @@@ @@ \ +$C1@@@@@@@@@@@@ @@@ @@@ @@@ @@@ \ +$C1@@@ @@@ @@@ @@@ @@@@@@@@@ " // 1 2 3 4 5 6 // 123456789012345678901234567890123456789012345678901234567890 @@ -221,7 +232,7 @@ $C1 ######################### \ // LOGO W H COLORS LOGO (>0 && <10) COLORS TEXT (=2) // -------------------------------------------------------------------------------- -static struct ascii_logo logo_amd = { ASCII_AMD, 62, 6, {COLOR_WHITE, COLOR_GREEN}, {COLOR_WHITE, COLOR_GREEN} }; +static struct ascii_logo logo_amd = { ASCII_AMD, 43, 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, 62, 19, {COLOR_RED, COLOR_WHITE}, {COLOR_RED, COLOR_WHITE} }; static struct ascii_logo logo_mtk = { ASCII_MTK, 62, 19, {COLOR_BLUE, COLOR_YELLOW}, {COLOR_BLUE, COLOR_YELLOW} }; From 8f31e22452193b87f0940c3e18c6e9b995a1bc54 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Sun, 8 Aug 2021 16:58:43 +0200 Subject: [PATCH 06/21] [v0.99] Improve AMD logo --- src/common/ascii.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/common/ascii.h b/src/common/ascii.h index 469b440..b9625e3 100644 --- a/src/common/ascii.h +++ b/src/common/ascii.h @@ -21,21 +21,21 @@ struct ascii_logo { // 1 2 3 4 5 6 //0123456789012345678901234567890123456789012345678901234567890 #define ASCII_AMD \ -"$C2 '::::::::::::::: \ -$C2 ,ccccccccccccc \ -$C2 .cccc \ -$C2 ;. .cccc \ -$C2 ::c. .cccc \ -$C2 :ccc. .cccc \ -$C2 cccc:::::. :cc \ -$C2 ccccccc. ; \ - \ -$C1 @@@@ @@@ @@@ @@@@@@@@ \ -$C1 @@@@@@ @@@@@ @@@@@ @@@ @@@ \ -$C1 @@@ @@@ @@@@@@@@@@@@@ @@@ @@ \ -$C1 @@@ @@@ @@@ @@@ @@@ @@@ @@ \ -$C1@@@@@@@@@@@@ @@@ @@@ @@@ @@@ \ -$C1@@@ @@@ @@@ @@@ @@@@@@@@@ " +"$C2 '############### \ +$C2 ,############# \ +$C2 .#### \ +$C2 #. .#### \ +$C2 :##. .#### \ +$C2 :###. .#### \ +$C2 #########. :## \ +$C2 #######. ; \ +$C1 \ +$C1 ### ### ### ####### \ +$C1 ## ## ##### ##### ## ## \ +$C1 ## ## ### #### ### ## ## \ +$C1 ######### ### ## ### ## ## \ +$C1## ## ### ### ## ## \ +$C1## ## ### ### ####### " // 1 2 3 4 5 6 // 123456789012345678901234567890123456789012345678901234567890 @@ -232,7 +232,7 @@ $C1 ######################### \ // LOGO W H COLORS LOGO (>0 && <10) COLORS TEXT (=2) // -------------------------------------------------------------------------------- -static struct ascii_logo logo_amd = { ASCII_AMD, 43, 15, {COLOR_WHITE, COLOR_GREEN}, {COLOR_WHITE, COLOR_GREEN} }; +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, 62, 19, {COLOR_RED, COLOR_WHITE}, {COLOR_RED, COLOR_WHITE} }; static struct ascii_logo logo_mtk = { ASCII_MTK, 62, 19, {COLOR_BLUE, COLOR_YELLOW}, {COLOR_BLUE, COLOR_YELLOW} }; From 00981c3c468c3b745112bc6d72838adb8e49c0ad Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Sun, 8 Aug 2021 19:42:34 +0200 Subject: [PATCH 07/21] [v0.99] Adapt more logos to new color scheme and make them shorter --- src/common/ascii.h | 174 +++++++++++++++++++-------------------------- 1 file changed, 72 insertions(+), 102 deletions(-) diff --git a/src/common/ascii.h b/src/common/ascii.h index b9625e3..6b03033 100644 --- a/src/common/ascii.h +++ b/src/common/ascii.h @@ -61,109 +61,79 @@ $C1 ########## ################ \ $C1 ############################### " #define ASCII_SNAPD \ -" \ - $C1@@$C2######## \ - $C1@@@@@$C2########### \ - $C1@@ @@@@@$C2################# \ - $C1@@@@@@@@@@$C2#################### \ - $C1@@@@@@@@@@@@$C2##################### \ - $C1@@@@@@@@@@@@@@@$C2#################### \ - $C1@@@@@@@@@@@@@@@@@$C2################### \ - $C1@@@@@@@@@@@@@@@@@@@@$C2################ \ - $C1@@@@@@@@@@@@@@@@@@@@$C2############# \ - $C1@@@@@@@@@@@@@@@@@@$C2############ \ - $C1@ @@@@@@@@@@@@@@@$C2########### \ - $C1@@@@@ @@@@@@@@@@@@@$C2########## \ - $C1@@@@@@@@@ @@@@@@@@@@@@$C2######## \ - $C1@@@@@@@@@ @@@@@@@@@@$C2####### \ - $C1@@@@@@@@@@@@@@@@$C2####### \ - $C1@@@@$C2########### \ - \ - " +" $C1@@$C2######## \ + $C1@@@@@$C2########### \ + $C1@@ @@@@@$C2################# \ + $C1@@@@@@@@@@$C2#################### \ + $C1@@@@@@@@@@@@$C2##################### \ + $C1@@@@@@@@@@@@@@@$C2#################### \ + $C1@@@@@@@@@@@@@@@@@$C2################### \ + $C1@@@@@@@@@@@@@@@@@@@@$C2################ \ + $C1@@@@@@@@@@@@@@@@@@@@$C2############# \ + $C1@@@@@@@@@@@@@@@@@@$C2############ \ +$C1@ @@@@@@@@@@@@@@@$C2########### \ + $C1@@@@@ @@@@@@@@@@@@@$C2########## \ + $C1@@@@@@@@@ @@@@@@@@@@@@$C2######## \ + $C1@@@@@@@@@ @@@@@@@@@@$C2####### \ + $C1@@@@@@@@@@@@@@@@$C2####### \ + $C1@@@@$C2########### " #define ASCII_MTK \ -" \ - \ - \ - \ - \ - \ - $C1## ## ###### ###### # ### $C2@@@@@@ @@@@@@ @@ @@ \ - $C1### ### # # # # #### $C2@@ @ @@ @@ \ - $C1######## # ### # # # ## ## $C2@@ @ @@@ @@@@ \ - $C1## ### ## # # # # ## ## $C2@@ @ @@ @@ \ - $C1## ## ## ###### ##### # ## ## $C2@@ @@@@@@ @@ @@ \ - \ - \ - \ - \ - \ - \ - \ - " +"$C1 ## ## ###### ###### # ### $C2@@@@@@ @@@@@@ @@ @@ \ +$C1 ### ### # # # # #### $C2@@ @ @@ @@ \ +$C1 ######## # ### # # # ## ## $C2@@ @ @@@ @@@@ \ +$C1 ## ### ## # # # # ## ## $C2@@ @ @@ @@ \ +$C1## ## ## ###### ##### # ## ## $C2@@ @@@@@@ @@ @@ " #define ASCII_EXYNOS \ -" \ - \ - \ - \ - \ - \ - $C1## ## ## \ - $C1## ## \ - $C1## \ - $C1## ## \ - $C1## ## ## \ - \ - $C2SAMSUNG \ - $C2Exynos \ - \ - \ - \ - \ - " +"$C1 \ +$C1 \ +$C1 \ +$C1 ## ## ## \ +$C1 ## ## \ +$C1 ## \ +$C1 ## ## \ +$C1 ## ## ## \ +$C1 \ +$C2 SAMSUNG \ +$C2 Exynos \ +$C1 \ +$C1 " #define ASCII_KIRIN \ -" \ - \ - \ - \ - \ -$C1 ####### \ -$C1 ##### #################### \ -$C1 ###################################### \ -$C1 ####################################### \ -$C1 ####################################### \ -$C1 ############################## \ -$C1 ########################## \ -$C1 ######################### \ -$C1 ######################## \ -$C1 ######################## \ -$C1 ######################### \ -$C1 ######################### \ - \ - " +"$C1 ####### \ +$C1 ##### #################### \ +$C1 ###################################### \ +$C1 ####################################### \ +$C1 ####################################### \ +$C1 ############################## \ +$C1 ########################## \ +$C1 ######################### \ +$C1 ######################## \ +$C1 ######################## \ +$C1 ######################### \ +$C1######################### " #define ASCII_BROADCOM \ -" \ - ################ \ - ########################## \ - ################################ \ - ################@@@@################ \ - ################@@@@@@################ \ - #################@@@@@@################# \ - #################@@@@@@@@################# \ - #################@@@@@@@@################# \ - ################@@@@##@@@@################ \ - ################@@@@##@@@@################ \ - ###############@@@@####@@@@############### \ - @@@@@@@@@@####@@@@####@@@@####@@@@@@@@@@ \ - ######@@@@@@@@@@######@@@@@@@@@@###### \ - ################################## \ - ############################## \ - ######################## \ - ############### \ - " +"$C2 \ +$C2 ################ \ +$C2 ########################## \ +$C2 ################################ \ +$C2 ################$C1@@@@$C2################ \ +$C2 ################$C1@@@@@@$C2################ \ +$C2 #################$C1@@@@@@$C2################# \ +$C2#################$C1@@@@@@@@$C2################# \ +$C2#################$C1@@@@@@@@$C2################# \ +$C2################$C1@@@@$C2##$C1@@@@$C2################ \ +$C2################$C1@@@@$C2##$C1@@@@$C2################ \ +$C2###############$C1@@@@$C2####$C1@@@@$C2############### \ +$C1 @@@@@@@@@@$C2####$C1@@@@$C2####$C1@@@@$C2####$C1@@@@@@@@@@ \ +$C2 ######$C1@@@@@@@@@@$C2######$C1@@@@@@@@@@$C2###### \ +$C2 ################################## \ +$C2 ############################## \ +$C2 ######################## \ +$C2 ############### \ +$C2 " #define ASCII_ARM \ " \ @@ -234,13 +204,13 @@ $C1 ######################### \ // -------------------------------------------------------------------------------- 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, 62, 19, {COLOR_RED, COLOR_WHITE}, {COLOR_RED, COLOR_WHITE} }; -static struct ascii_logo logo_mtk = { ASCII_MTK, 62, 19, {COLOR_BLUE, COLOR_YELLOW}, {COLOR_BLUE, COLOR_YELLOW} }; -static struct ascii_logo logo_exynos = { ASCII_EXYNOS, 62, 19, {COLOR_BLUE, COLOR_WHITE}, {COLOR_BLUE, COLOR_WHITE}, }; -static struct ascii_logo logo_kirin = { ASCII_KIRIN, 62, 19, {COLOR_WHITE, COLOR_RED}, {COLOR_WHITE, COLOR_RED} }; -static struct ascii_logo logo_broadcom = { ASCII_BROADCOM, 62, 19, {COLOR_WHITE, COLOR_RED}, {COLOR_WHITE, COLOR_RED} }; -static struct ascii_logo logo_arm = { ASCII_ARM, 62, 19, {COLOR_CYAN}, {COLOR_WHITE, COLOR_CYAN} }; -static struct ascii_logo logo_ibm = { ASCII_IBM, 62, 19, {COLOR_CYAN, COLOR_WHITE}, {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, 62, 19, {COLOR_CYAN}, {COLOR_WHITE, COLOR_CYAN} }; +static struct ascii_logo logo_ibm = { ASCII_IBM, 62, 19, {COLOR_CYAN, COLOR_WHITE}, {COLOR_CYAN, COLOR_WHITE}, }; static struct ascii_logo logo_unknown = { ASCII_UNKNOWN, 62, 19, {COLOR_BLUE}, {COLOR_BLUE} }; static struct ascii_logo* ASCII_ARRAY [] = { From 123b22e96809bf113ea63a59ec393e21d8209889 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Sun, 8 Aug 2021 20:34:39 +0200 Subject: [PATCH 08/21] [v0.99] New, shorter IBM logo --- src/common/ascii.h | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/src/common/ascii.h b/src/common/ascii.h index 6b03033..536e9ac 100644 --- a/src/common/ascii.h +++ b/src/common/ascii.h @@ -156,28 +156,18 @@ $C2 " \ " -// jp2a --height=17 ibm.jpg +// jp2a --width=50 ibm.jpg #define ASCII_IBM \ -" \ - \ - \ - ############ ################ ########## ########## \ - \ - ############ ################## ############ ############ \ - \ - ###### ###### ###### #################### \ - \ - ###### ############## #################### \ - \ - ###### ###### ###### ##### ###### ##### \ - \ - ############ ################## ######### #### ######### \ - \ - ############ ################ ######### ## ######### \ - \ - \ - " - +"$C1########## ############# ####### ####### \ +$C1########## ############## ###### ###### \ +$C1########## ############### ####### ####### \ +$C1 #### #### #### ######## ######## \ +$C1 #### ########### ################# \ +$C1 #### ########### ################# \ +$C1 #### #### ##### #### ####### #### \ +$C1########## ############### ###### ##### ###### \ +$C1########## ############## ###### ### ###### \ +$C1########## ############# ###### # ###### " #define ASCII_UNKNOWN \ " \ @@ -210,7 +200,7 @@ static struct ascii_logo logo_exynos = { ASCII_EXYNOS, 22, 13, {COLOR_BLUE, 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, 62, 19, {COLOR_CYAN}, {COLOR_WHITE, COLOR_CYAN} }; -static struct ascii_logo logo_ibm = { ASCII_IBM, 62, 19, {COLOR_CYAN, COLOR_WHITE}, {COLOR_CYAN, COLOR_WHITE}, }; +static struct ascii_logo logo_ibm = { ASCII_IBM, 50, 10, {COLOR_CYAN, COLOR_WHITE}, {COLOR_CYAN, COLOR_WHITE}, }; static struct ascii_logo logo_unknown = { ASCII_UNKNOWN, 62, 19, {COLOR_BLUE}, {COLOR_BLUE} }; static struct ascii_logo* ASCII_ARRAY [] = { From f3b1333a18ebf3110b359917780d9d18bb906631 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Sun, 8 Aug 2021 21:08:29 +0200 Subject: [PATCH 09/21] [v0.99] New, shorter arm logo. Change to a wider IBM logo --- src/common/ascii.h | 53 ++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/src/common/ascii.h b/src/common/ascii.h index 536e9ac..5fc922a 100644 --- a/src/common/ascii.h +++ b/src/common/ascii.h @@ -136,38 +136,27 @@ $C2 ############### \ $C2 " #define ASCII_ARM \ -" \ - \ - \ - \ - \ - \ - ############ ########## #### ###### ######## \ - ############### ######### ####################### \ - #### #### #### ##### ####### ##### \ - #### #### #### #### ##### #### \ - #### #### #### #### #### #### \ - #### ##### #### #### #### #### \ - ############### #### #### #### #### \ - ######## #### #### #### #### #### \ - \ - \ - \ - \ - " +"$C1 +###+ +## ####### ####### ###### \ +$C1 ### #### ### #### ### ### \ +$C1### ## ### ### ## ### \ +$C1 ## ## ### ### ## ### \ +$C1 ###### ### ### ### ## ### " -// jp2a --width=50 ibm.jpg +// jp2a --height=17 ibm.jpg #define ASCII_IBM \ -"$C1########## ############# ####### ####### \ -$C1########## ############## ###### ###### \ -$C1########## ############### ####### ####### \ -$C1 #### #### #### ######## ######## \ -$C1 #### ########### ################# \ -$C1 #### ########### ################# \ -$C1 #### #### ##### #### ####### #### \ -$C1########## ############### ###### ##### ###### \ -$C1########## ############## ###### ### ###### \ -$C1########## ############# ###### # ###### " +"$C1######### ################ ######### ######### \ +$C1 \ +$C1######### ################## ########## ########## \ +$C1 \ +$C1 ##### ###### ###### #################### \ +$C1 \ +$C1 ##### ############## #################### \ +$C1 \ +$C1 ##### ###### ###### ##### ###### ##### \ +$C1 \ +$C1######### ################## ######## #### ######## \ +$C1 \ +$C1######### ################ ######## ## ######## " #define ASCII_UNKNOWN \ " \ @@ -199,8 +188,8 @@ static struct ascii_logo logo_mtk = { ASCII_MTK, 59, 5, {COLOR_BLUE, 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, 62, 19, {COLOR_CYAN}, {COLOR_WHITE, COLOR_CYAN} }; -static struct ascii_logo logo_ibm = { ASCII_IBM, 50, 10, {COLOR_CYAN, COLOR_WHITE}, {COLOR_CYAN, COLOR_WHITE}, }; +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, 14, {COLOR_CYAN, COLOR_WHITE}, {COLOR_CYAN, COLOR_WHITE}, }; static struct ascii_logo logo_unknown = { ASCII_UNKNOWN, 62, 19, {COLOR_BLUE}, {COLOR_BLUE} }; static struct ascii_logo* ASCII_ARRAY [] = { From a7e34a14908d9d09a8268e9245d19959962163d3 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Sun, 8 Aug 2021 21:12:16 +0200 Subject: [PATCH 10/21] [v0.99] Add dummy unknown logo --- src/common/ascii.h | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/src/common/ascii.h b/src/common/ascii.h index 5fc922a..363098a 100644 --- a/src/common/ascii.h +++ b/src/common/ascii.h @@ -158,39 +158,18 @@ $C1######### ################## ######## #### ######## \ $C1 \ $C1######### ################ ######## ## ######## " -#define ASCII_UNKNOWN \ -" \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - " - // 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_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, 14, {COLOR_CYAN, COLOR_WHITE}, {COLOR_CYAN, COLOR_WHITE}, }; -static struct ascii_logo logo_unknown = { ASCII_UNKNOWN, 62, 19, {COLOR_BLUE}, {COLOR_BLUE} }; +static struct ascii_logo logo_ibm = { ASCII_IBM, 57, 14, {COLOR_CYAN, COLOR_WHITE}, {COLOR_CYAN, COLOR_WHITE} }; +static struct ascii_logo logo_unknown = { NULL, 0, 0, { }, {"", ""} }; static struct ascii_logo* ASCII_ARRAY [] = { &logo_amd, From 7ee36037c3dad558cf335cf16d6ee8e3800d8627 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Sun, 8 Aug 2021 21:39:44 +0200 Subject: [PATCH 11/21] [v0.99] Fix two bugs in the logo printing --- src/common/ascii.h | 4 ++-- src/common/printer.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/ascii.h b/src/common/ascii.h index 363098a..c3d76a2 100644 --- a/src/common/ascii.h +++ b/src/common/ascii.h @@ -168,8 +168,8 @@ static struct ascii_logo logo_exynos = { ASCII_EXYNOS, 22, 13, {COLOR_BLUE, 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, 14, {COLOR_CYAN, COLOR_WHITE}, {COLOR_CYAN, COLOR_WHITE} }; -static struct ascii_logo logo_unknown = { NULL, 0, 0, { }, {"", ""} }; +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, {"" }, {"", ""} }; static struct ascii_logo* ASCII_ARRAY [] = { &logo_amd, diff --git a/src/common/printer.c b/src/common/printer.c index 8f2248e..fa6dcee 100644 --- a/src/common/printer.c +++ b/src/common/printer.c @@ -330,7 +330,7 @@ void print_ascii_x86(struct ascii* art, uint32_t la) { printf("\n"); for(int32_t n=0; n < iters; n++) { // 1. Print logo - if(space_up > 0 || (space_up + n >= 0 && n + space_down < (int)logo->height)) { + 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); From 1717a96b273717de78fa1e9b5f3e18d9afdfa592 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Sun, 8 Aug 2021 21:49:00 +0200 Subject: [PATCH 12/21] [v0.99] Improve ARM logo --- src/common/ascii.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/ascii.h b/src/common/ascii.h index c3d76a2..df4f71a 100644 --- a/src/common/ascii.h +++ b/src/common/ascii.h @@ -136,11 +136,11 @@ $C2 ############### \ $C2 " #define ASCII_ARM \ -"$C1 +###+ +## ####### ####### ###### \ +"$C1 ##### ## # ##### ## #### ###### \ $C1 ### #### ### #### ### ### \ $C1### ## ### ### ## ### \ -$C1 ## ## ### ### ## ### \ -$C1 ###### ### ### ### ## ### " +$C1 ### #### ### ### ## ### \ +$C1 ###### ## ### ### ## ### " // jp2a --height=17 ibm.jpg #define ASCII_IBM \ From 0aff23f962880a7505222d5ab378edfd47bdd9d0 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Sun, 8 Aug 2021 22:25:46 +0200 Subject: [PATCH 13/21] [v0.99] Easy way to print logos with blocks instead of chars. Remove dead code --- src/common/ascii.h | 124 ++++++++++++++++++++++--------------------- src/common/printer.c | 50 ++++++----------- 2 files changed, 79 insertions(+), 95 deletions(-) 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 From 5d92814cd0205b39488a02403611a809181ea50d Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Sun, 8 Aug 2021 23:44:05 +0200 Subject: [PATCH 14/21] [v0.99] Add new, shorter Intel logo --- src/common/ascii.h | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/common/ascii.h b/src/common/ascii.h index c16d50d..f4b225f 100644 --- a/src/common/ascii.h +++ b/src/common/ascii.h @@ -54,25 +54,20 @@ $C1## ## ### ### ## ## \ $C1## ## ### ### ####### " #define ASCII_INTEL \ -"$C1 ################ \ -$C1 ####### ####### \ -$C1 #### #### \ -$C1 ### #### \ -$C1 ### ### \ -$C1 ### ### \ -$C1 # ### ### ### \ -$C1 ## ### ######### ###### ###### ### ### \ -$C1 ## ### ### ### ### #### #### ### ### \ -$C1 ## ### ### ### ### ### ### ### ### \ -$C1## ### ### ### ### ########## ### #### \ -$C1## ### ### ### ### ### ### ##### \ -$C1## ## ### ### ##### ######### ## ### \ -$C1### \ -$C1 ### \ -$C1 #### #### \ -$C1 ##### ########## \ -$C1 ########## ################ \ -$C1 ############################### " +"$C1 ################## \ +$C1 ####### ##### \ +$C1 ##### ### \ +$C1 ## ### \ +$C1 # ## ## ## ## \ +$C1 ## ###### #### ###### ## ## \ +$C1 ## ## ## ## ## ### ### ## ### \ +$C1## ## ## ## ## ######### ## ## \ +$C1## ## ## ## ## ## ## ## \ +$C1## ## ## ## #### ##### ## ## \ +$C1### \ +$C1 #### ##### \ +$C1 #### ############ \ +$C1 ############################ " #define ASCII_SNAPD \ " $C1@@$C2######## \ @@ -178,7 +173,7 @@ typedef struct ascii_logo asciiL; // | 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_intel = { ASCII_INTEL, 48, 14, 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} }; From 7c5e638c2f31513250e02dc5414b590fe4e6ad43 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Mon, 9 Aug 2021 12:12:14 +0200 Subject: [PATCH 15/21] [v0.99] Bring back long logos. Print long logos only when the terminal width is enough to display the output properly; if not, display the short logos --- src/common/ascii.h | 93 +++++++++++++++++++++++++++++++++++- src/common/printer.c | 109 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 186 insertions(+), 16 deletions(-) diff --git a/src/common/ascii.h b/src/common/ascii.h index f4b225f..6c2c817 100644 --- a/src/common/ascii.h +++ b/src/common/ascii.h @@ -36,6 +36,7 @@ struct ascii_logo { * CR: Color reset, gets replaced by the reset color by printer.c */ +// SHORT LOGOS // #define ASCII_AMD \ "$C2 '############### \ $C2 ,############# \ @@ -167,6 +168,91 @@ $C1 ###### ## ### ### ## ### " \ ######### ################ ######## ## ######## " +// --------------------- LONG LOGOS ------------------------- // +#define ASCII_AMD_L \ +" \ + \ + \ + \ + \ + \ + @@@@ @@@ @@@ @@@@@@@@ ############ \ + @@@@@@ @@@@@ @@@@@ @@@ @@@ ########## \ + @@@ @@@ @@@@@@@@@@@@@ @@@ @@ # ##### \ + @@@ @@@ @@@ @@@ @@@ @@@ @@ ### ##### \ + @@@@@@@@@@@@ @@@ @@@ @@@ @@@ ######### ### \ + @@@ @@@ @@@ @@@ @@@@@@@@@ ######## ## \ + \ + \ + \ + \ + \ + \ + " + +#define ASCII_INTEL_L \ +" ################ \ + ####### ####### \ + #### #### \ + ### #### \ + ### ### \ + ### ### \ + # ### ### ### \ + ## ### ######### ###### ###### ### ### \ + ## ### ### ### ### #### #### ### ### \ + ## ### ### ### ### ### ### ### ### \ +## ### ### ### ### ########## ### #### \ +## ### ### ### ### ### ### ##### \ +## ## ### ### ##### ######### ## ### \ +### \ + ### \ + #### #### \ + ##### ########## \ + ########## ################ \ + ############################### " + +#define ASCII_ARM_L \ +" \ + \ + \ + \ + \ + \ + ############ ########## #### ###### ######## \ + ############### ######### ####################### \ + #### #### #### ##### ####### ##### \ + #### #### #### #### ##### #### \ + #### #### #### #### #### #### \ + #### ##### #### #### #### #### \ + ############### #### #### #### #### \ + ######## #### #### #### #### #### \ + \ + \ + \ + \ + " + +#define ASCII_IBM_L \ +" \ + \ + \ + ############ ################ ########## ########## \ + \ + ############ ################## ############ ############ \ + \ + ###### ###### ###### #################### \ + \ + ###### ############## #################### \ + \ + ###### ###### ###### ##### ###### ##### \ + \ + ############ ################## ######### #### ######### \ + \ + ############ ################ ######### ## ######### \ + \ + \ + " + typedef struct ascii_logo asciiL; // ------------------------------------------------------------------------------------------------------ @@ -181,6 +267,11 @@ asciiL logo_kirin = { ASCII_KIRIN, 53, 12, false, {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} }; +// Long variants | ----------------------------------------------------------------------------------------------------| +asciiL logo_amd_l = { ASCII_AMD_L, 62, 19, false, {COLOR_FG_WHITE, COLOR_FG_GREEN}, {COLOR_FG_WHITE, COLOR_FG_GREEN} }; +asciiL logo_intel_l = { ASCII_INTEL_L, 62, 19, false, {COLOR_FG_CYAN}, {COLOR_FG_CYAN, COLOR_FG_WHITE} }; +asciiL logo_arm_l = { ASCII_ARM_L, 62, 19, true, {COLOR_FG_CYAN}, {COLOR_FG_WHITE, COLOR_FG_CYAN} }; +asciiL logo_ibm_l = { ASCII_IBM_L, 62, 19, 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 c92e5d8..d742505 100644 --- a/src/common/printer.c +++ b/src/common/printer.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "printer.h" #include "ascii.h" @@ -21,8 +22,14 @@ #endif #ifdef _WIN32 -#define NOMINMAX -#include + #define NOMINMAX + #include +#else + #ifdef __linux__ + #define _POSIX_C_SOURCE 199309L + #endif + #include + #include #endif #define max(a,b) (((a)>(b))?(a):(b)) @@ -86,6 +93,11 @@ static const char* ATTRIBUTE_FIELDS [] = { "Peak Performance:", }; +struct terminal { + int w; + int h; +}; + struct attribute { int type; char* value; @@ -246,15 +258,35 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct color** cs) { return NULL; } + return art; +} + +bool ascii_fits_screen(int termw, struct ascii_logo logo, int lf) { + return termw - ((int) logo.width + lf) >= 0; +} + +void choose_ascii_art(struct ascii* art, struct terminal* term, int lf) { #ifdef ARCH_X86 - if(art->vendor == CPU_VENDOR_INTEL) - art->art = &logo_intel; - else if(art->vendor == CPU_VENDOR_AMD) - art->art = &logo_amd; - else + if(art->vendor == CPU_VENDOR_INTEL) { + if(ascii_fits_screen(term->w, logo_intel_l, lf)) + art->art = &logo_intel_l; + else + art->art = &logo_intel; + } + else if(art->vendor == CPU_VENDOR_AMD) { + if(ascii_fits_screen(term->w, logo_amd_l, lf)) + art->art = &logo_amd_l; + else + art->art = &logo_amd; + } + else { art->art = &logo_unknown; + } #elif ARCH_PPC - art->art = &logo_ibm; + if(ascii_fits_screen(term->w, logo_ibm_l, lf)) + art->art = &logo_ibm_l; + else + art->art = &logo_ibm; #elif ARCH_ARM if(art->vendor == SOC_VENDOR_SNAPDRAGON) art->art = &logo_snapd; @@ -266,11 +298,13 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct color** cs) { art->art = &logo_kirin; else if(art->vendor == SOC_VENDOR_BROADCOM) art->art = &logo_broadcom; + else { + if(ascii_fits_screen(term->w, logo_arm_l, lf)) + art->art = &logo_arm_l; else - art->art = &logo_unknown; + art->art = &logo_arm; + } #endif - - return art; } uint32_t longest_attribute_length(struct ascii* art) { @@ -287,6 +321,22 @@ uint32_t longest_attribute_length(struct ascii* art) { return max; } +uint32_t longest_field_length(struct ascii* art, int la) { + uint32_t max = 0; + uint64_t len = 0; + + for(uint32_t i=0; i < art->n_attributes_set; i++) { + if(art->attributes[i]->value != NULL) { + // longest attribute + 1 (space) + longest value + len = la + 1 + strlen(art->attributes[i]->value); + + if(len > max) max = len; + } + } + + return max; +} + #ifdef ARCH_X86 void parse_print_color(struct ascii* art, uint32_t* logo_pos) { struct ascii_logo* logo = art->art; @@ -350,7 +400,7 @@ void print_ascii_x86(struct ascii* art, uint32_t la) { printf("\n"); } -bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs) { +bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs, struct terminal* term) { struct ascii* art = set_ascii(get_cpu_vendor(cpu), s, cs); if(art == NULL) return false; @@ -398,6 +448,9 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs) { setAttribute(art,ATTRIBUTE_PEAK,pp); uint32_t longest_attribute = longest_attribute_length(art); + uint32_t longest_field = longest_field_length(art, longest_attribute); + choose_ascii_art(art, term, longest_field); + print_ascii_x86(art, longest_attribute); free(manufacturing_process); @@ -717,12 +770,38 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct color** cs) { } #endif +struct terminal* get_terminal_size() { + struct terminal* term = emalloc(sizeof(struct terminal)); + +#ifdef _WIN32 + CONSOLE_SCREEN_BUFFER_INFO csbi; + if(GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi) == 0) { + printWarn("GetConsoleScreenBufferInfo failed"); + return NULL; + } + term->w = csbi.srWindow.Right - csbi.srWindow.Left + 1; + term->h = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; +#else + struct winsize w; + if(ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) == -1) { + printErr("ioctl: %s", strerror(errno)); + return NULL; + } + term->h = w.ws_row; + term->w = w.ws_col; +#endif + + return term; +} + bool print_cpufetch(struct cpuInfo* cpu, STYLE s, struct color** cs) { + struct terminal* term = get_terminal_size(); + #ifdef ARCH_X86 - return print_cpufetch_x86(cpu, s, cs); + return print_cpufetch_x86(cpu, s, cs, term); #elif ARCH_PPC - return print_cpufetch_ppc(cpu, s, cs); + return print_cpufetch_ppc(cpu, s, cs, term); #elif ARCH_ARM - return print_cpufetch_arm(cpu, s, cs); + return print_cpufetch_arm(cpu, s, cs, term); #endif } From 42149b8dffcc38dcba665f0c2d209f5888bfec56 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Mon, 9 Aug 2021 12:45:29 +0200 Subject: [PATCH 16/21] [v0.99] Recover original Intel and AMD logos by adding shadows and new replace_blocks protocol; # replaces by 1st color, @ by 2nd --- src/common/ascii.h | 95 ++++++++++++++++++++------------------------ src/common/printer.c | 9 ++++- 2 files changed, 50 insertions(+), 54 deletions(-) diff --git a/src/common/ascii.h b/src/common/ascii.h index 6c2c817..73b0181 100644 --- a/src/common/ascii.h +++ b/src/common/ascii.h @@ -30,10 +30,18 @@ struct ascii_logo { }; /* - * Brief explanation: + * ASCII logos brief documentation + * ---------------------------------------------------- * 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 + * CR: Color reset, gets replaced by the reset + * color by printer.c + * Logos with replace_blocks 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] */ // SHORT LOGOS // @@ -191,52 +199,38 @@ $C1 ###### ## ### ### ## ### " " #define ASCII_INTEL_L \ -" ################ \ - ####### ####### \ - #### #### \ - ### #### \ - ### ### \ - ### ### \ - # ### ### ### \ - ## ### ######### ###### ###### ### ### \ - ## ### ### ### ### #### #### ### ### \ - ## ### ### ### ### ### ### ### ### \ -## ### ### ### ### ########## ### #### \ -## ### ### ### ### ### ### ##### \ -## ## ### ### ##### ######### ## ### \ -### \ - ### \ - #### #### \ - ##### ########## \ - ########## ################ \ - ############################### " +" ###############@ \ + ######@ ######@ \ + ###@ ###@ \ + ##@ ###@ \ + ##@ ##@ \ + ##@ ##@ \ + @ ##@ ##@ ##@ \ + #@ ##@ ########@ #####@ #####@ ##@ ##@ \ + #@ ##@ ##@ ##@ ##@ ###@ ###@ ##@ ##@ \ + #@ ##@ ##@ ##@ ##@ ##@ ##@ ##@ ##@ \ + #@ ##@ ##@ ##@ ##@ #########@ ##@ ###@ \ + #@ ##@ ##@ ##@ ##@ ##@ ##@ ####@ \ + #@ #@ ##@ ##@ ####@ ########@ #@ ##@ \ + ##@ \ + ##@ \ + ###@ ###@ \ + ####@ #########@ \ + #########@ ###############@ \ + ##############################@ " #define ASCII_ARM_L \ -" \ - \ - \ - \ - \ - \ - ############ ########## #### ###### ######## \ - ############### ######### ####################### \ - #### #### #### ##### ####### ##### \ - #### #### #### #### ##### #### \ - #### #### #### #### #### #### \ - #### ##### #### #### #### #### \ - ############### #### #### #### #### \ - ######## #### #### #### #### #### \ - \ - \ - \ - \ - " +" ############ ########## #### ###### ######## \ + ############### ######### ####################### \ + #### #### #### ##### ####### ##### \ +#### #### #### #### ##### #### \ +#### #### #### #### #### #### \ + #### ##### #### #### #### #### \ + ############### #### #### #### #### \ + ######## #### #### #### #### #### " #define ASCII_IBM_L \ -" \ - \ - \ - ############ ################ ########## ########## \ +" ############ ################ ########## ########## \ \ ############ ################## ############ ############ \ \ @@ -248,10 +242,7 @@ $C1 ###### ## ### ### ## ### " \ ############ ################## ######### #### ######### \ \ - ############ ################ ######### ## ######### \ - \ - \ - " + ############ ################ ######### ## ######### " typedef struct ascii_logo asciiL; @@ -268,10 +259,10 @@ asciiL logo_broadcom = { ASCII_BROADCOM, 44, 19, false, {COLOR_FG_WHITE, COLOR_F 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} }; // Long variants | ----------------------------------------------------------------------------------------------------| -asciiL logo_amd_l = { ASCII_AMD_L, 62, 19, false, {COLOR_FG_WHITE, COLOR_FG_GREEN}, {COLOR_FG_WHITE, COLOR_FG_GREEN} }; -asciiL logo_intel_l = { ASCII_INTEL_L, 62, 19, false, {COLOR_FG_CYAN}, {COLOR_FG_CYAN, COLOR_FG_WHITE} }; -asciiL logo_arm_l = { ASCII_ARM_L, 62, 19, true, {COLOR_FG_CYAN}, {COLOR_FG_WHITE, COLOR_FG_CYAN} }; -asciiL logo_ibm_l = { ASCII_IBM_L, 62, 19, true, {COLOR_BG_CYAN, COLOR_FG_WHITE}, {COLOR_FG_CYAN, COLOR_FG_WHITE} }; +asciiL logo_amd_l = { ASCII_AMD_L, 62, 19, true, {COLOR_BG_WHITE, COLOR_BG_GREEN}, {COLOR_FG_WHITE, COLOR_FG_GREEN} }; +asciiL logo_intel_l = { ASCII_INTEL_L, 62, 19, true, {COLOR_BG_CYAN, COLOR_BG_WHITE}, {COLOR_FG_CYAN, COLOR_FG_WHITE} }; +asciiL logo_arm_l = { ASCII_ARM_L, 60, 8, true, {COLOR_BG_CYAN}, {COLOR_FG_WHITE, COLOR_FG_CYAN} }; +asciiL logo_ibm_l = { ASCII_IBM_L, 62, 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 d742505..cf071c7 100644 --- a/src/common/printer.c +++ b/src/common/printer.c @@ -305,6 +305,8 @@ void choose_ascii_art(struct ascii* art, struct terminal* term, int lf) { art->art = &logo_arm; } #endif + // change + art->art = &logo_ibm_l; } uint32_t longest_attribute_length(struct ascii* art) { @@ -372,8 +374,11 @@ void print_ascii_x86(struct ascii* art, uint32_t la) { if(logo->art[logo_pos] == '$' && logo->art[logo_pos+1] == 'C') { parse_print_color(art, &logo_pos); } - if(logo->replace_blocks && logo->art[logo_pos] == '#') - printf("%s%c%s", logo->color_ascii[0], ' ', art->reset); + if(logo->replace_blocks && logo->art[logo_pos] != ' ') { + if(logo->art[logo_pos] == '#') printf("%s%c%s", logo->color_ascii[0], ' ', art->reset); + else if(logo->art[logo_pos] == '@') printf("%s%c%s", logo->color_ascii[1], ' ', art->reset); + else printBug("ASCII art with replace_blocks has invalid character: '%c'", logo->art[logo_pos]); + } else printf("%c", logo->art[logo_pos]); From 5e3be4c45f8c552c8492f5edcc2d534c66c1f89e Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Mon, 9 Aug 2021 13:35:00 +0200 Subject: [PATCH 17/21] [v0.99][ARM] Fix compilation due to new logos in ARM, but needs refactoring and review --- src/common/printer.c | 172 ++++++++++++++++++++----------------------- 1 file changed, 79 insertions(+), 93 deletions(-) diff --git a/src/common/printer.c b/src/common/printer.c index cf071c7..34c715b 100644 --- a/src/common/printer.c +++ b/src/common/printer.c @@ -261,6 +261,21 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct color** cs) { return art; } +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]; + + 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; +} + bool ascii_fits_screen(int termw, struct ascii_logo logo, int lf) { return termw - ((int) logo.width + lf) >= 0; } @@ -268,13 +283,13 @@ bool ascii_fits_screen(int termw, struct ascii_logo logo, int lf) { void choose_ascii_art(struct ascii* art, struct terminal* term, int lf) { #ifdef ARCH_X86 if(art->vendor == CPU_VENDOR_INTEL) { - if(ascii_fits_screen(term->w, logo_intel_l, lf)) + if(term != NULL && ascii_fits_screen(term->w, logo_intel_l, lf)) art->art = &logo_intel_l; else art->art = &logo_intel; } else if(art->vendor == CPU_VENDOR_AMD) { - if(ascii_fits_screen(term->w, logo_amd_l, lf)) + if(term != NULL && ascii_fits_screen(term->w, logo_amd_l, lf)) art->art = &logo_amd_l; else art->art = &logo_amd; @@ -283,7 +298,7 @@ void choose_ascii_art(struct ascii* art, struct terminal* term, int lf) { art->art = &logo_unknown; } #elif ARCH_PPC - if(ascii_fits_screen(term->w, logo_ibm_l, lf)) + if(term != NULL && ascii_fits_screen(term->w, logo_ibm_l, lf)) art->art = &logo_ibm_l; else art->art = &logo_ibm; @@ -299,14 +314,12 @@ void choose_ascii_art(struct ascii* art, struct terminal* term, int lf) { else if(art->vendor == SOC_VENDOR_BROADCOM) art->art = &logo_broadcom; else { - if(ascii_fits_screen(term->w, logo_arm_l, lf)) - art->art = &logo_arm_l; - else - art->art = &logo_arm; + if(term != NULL && ascii_fits_screen(term->w, logo_arm_l, lf)) + art->art = &logo_arm_l; + else + art->art = &logo_arm; } #endif - // change - art->art = &logo_ibm_l; } uint32_t longest_attribute_length(struct ascii* art) { @@ -340,21 +353,6 @@ uint32_t longest_field_length(struct ascii* art, int la) { } #ifdef ARCH_X86 -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]; - - 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; -} - void print_ascii_x86(struct ascii* art, uint32_t la) { struct ascii_logo* logo = art->art; int attr_to_print = 0; @@ -377,7 +375,7 @@ void print_ascii_x86(struct ascii* art, uint32_t la) { if(logo->replace_blocks && logo->art[logo_pos] != ' ') { if(logo->art[logo_pos] == '#') printf("%s%c%s", logo->color_ascii[0], ' ', art->reset); else if(logo->art[logo_pos] == '@') printf("%s%c%s", logo->color_ascii[1], ' ', art->reset); - else printBug("ASCII art with replace_blocks has invalid character: '%c'", logo->art[logo_pos]); + else printf("%c", logo->art[logo_pos]); } else printf("%c", logo->art[logo_pos]); @@ -519,11 +517,10 @@ void print_ascii_ppc(struct ascii* art, uint32_t la) { printf("\n"); } -void print_ascii(struct ascii* art) { +/*void print_ascii(struct ascii* art) { uint32_t longest_attribute = longest_attribute_length(art); - print_ascii_ppc(art, longest_attribute); -} +}*/ bool print_cpufetch_ppc(struct cpuInfo* cpu, STYLE s, struct color** cs) { struct ascii* art = set_ascii(get_cpu_vendor(cpu), s, cs); @@ -581,72 +578,58 @@ bool print_cpufetch_ppc(struct cpuInfo* cpu, STYLE s, struct color** cs) { #endif #ifdef ARCH_ARM -void print_algorithm_snapd_mtk(struct ascii* art, int n) { - for(int i=0; i < LINE_SIZE; i++) { - if(art->art[n][i] == '@') - printf("%s%c%s", art->color1_ascii, art->ascii_chars[0], art->reset); - else if(art->art[n][i] == '#') - printf("%s%c%s", art->color2_ascii, art->ascii_chars[1], art->reset); - else - printf("%c",art->art[n][i]); - } -} - -void print_algorithm_samsung(struct ascii* art, int n) { - int y_margin = 2; - int x_margin = 2 * y_margin; - - for(int i=0; i < LINE_SIZE; i++) { - if(art->art[n][i] == '#') { - printf("%s%c%s", art->color1_ascii, art->ascii_chars[0], art->reset); - } - else if((n >= y_margin && n < NUMBER_OF_LINES-y_margin) && (i >= x_margin && i < LINE_SIZE-x_margin)) { - if(art->art[n][i] == '#') - printf("%s%c%s", art->color1_ascii, art->ascii_chars[0], art->reset); - else - printf("%s%c%s","\x1b[48;2;10;10;10m" COLOR_FG_WHITE, art->art[n][i], art->reset); - } - else - printf("%c", art->art[n][i]); - } -} - void print_algorithm_arm(struct ascii* art, int n) { - for(int i=0; i < LINE_SIZE; i++) { - if(art->art[n][i] == '#') - printf("%s%c%s", art->color1_ascii, art->ascii_chars[0], art->reset); - else - printf("%c",art->art[n][i]); - } + } void print_ascii_arm(struct ascii* art, uint32_t la, void (*callback_print_algorithm)(struct ascii* art, int n)) { + struct ascii_logo* logo = art->art; int attr_to_print = 0; int attr_type; char* attr_value; - uint32_t limit_up; - uint32_t limit_down; - + int32_t limit_up; + int32_t limit_down; + uint32_t logo_pos = 0; uint32_t space_right; - uint32_t space_up = (NUMBER_OF_LINES - art->n_attributes_set)/2; - uint32_t space_down = NUMBER_OF_LINES - art->n_attributes_set - space_up; - if(art->n_attributes_set > NUMBER_OF_LINES) { + int32_t space_up = ((int)logo->height - (int)art->n_attributes_set)/2; + int32_t space_down = (int)logo->height - (int)art->n_attributes_set - (int)space_up; + + if(art->n_attributes_set > logo->height) { limit_up = 0; limit_down = art->n_attributes_set; } else { limit_up = space_up; - limit_down = NUMBER_OF_LINES-space_down; + limit_down = logo->height - space_down; } bool add_space = false; - uint32_t len = max(art->n_attributes_set, NUMBER_OF_LINES); + int32_t iters = max(logo->height, art->n_attributes_set); - for(uint32_t n=0; n < len; n++) { - if(n >= art->additional_spaces && n < NUMBER_OF_LINES + art->additional_spaces) - callback_print_algorithm(art, n - art->additional_spaces); - else - printf("%*s", LINE_SIZE, ""); + for(int32_t n=0; n < iters; n++) { + // 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->replace_blocks && logo->art[logo_pos] != ' ') { + if(logo->art[logo_pos] == '#') printf("%s%c%s", logo->color_ascii[0], ' ', art->reset); + else if(logo->art[logo_pos] == '@') printf("%s%c%s", logo->color_ascii[1], ' ', art->reset); + else printf("%c", logo->art[logo_pos]); + } + else + printf("%c", logo->art[logo_pos]); + logo_pos++; + } + printf("%s", art->reset); + } + else { + // If logo should not be printed, fill with spaces + printf("%*c", logo->width, ' '); + } + + // 2. Print text if(n >= limit_up && n < limit_down) { attr_type = art->attributes[attr_to_print]->type; attr_value = art->attributes[attr_to_print]->value; @@ -656,17 +639,17 @@ void print_ascii_arm(struct ascii* art, uint32_t la, void (*callback_print_algor add_space = false; } if(attr_type == ATTRIBUTE_CPU_NUM) { - printf("%s%s%s\n", art->color1_text, attr_value, art->reset); + printf("%s%s%s\n", logo->color_text[0], attr_value, art->reset); add_space = true; } else { if(add_space) { space_right = 1 + (la - strlen(ATTRIBUTE_FIELDS[attr_type])); - printf(" %s%s%s%*s%s%s%s\n", art->color1_text, ATTRIBUTE_FIELDS[attr_type], art->reset, space_right, "", art->color2_text, attr_value, art->reset); + printf(" %s%s%s%*s%s%s%s\n", logo->color_text[0], ATTRIBUTE_FIELDS[attr_type], art->reset, space_right, "", logo->color_text[1], attr_value, art->reset); } else { space_right = 2 + 1 + (la - strlen(ATTRIBUTE_FIELDS[attr_type])); - printf("%s%s%s%*s%s%s%s\n", art->color1_text, ATTRIBUTE_FIELDS[attr_type], art->reset, space_right, "", art->color2_text, attr_value, art->reset); + printf("%s%s%s%*s%s%s%s\n", logo->color_text[0], ATTRIBUTE_FIELDS[attr_type], art->reset, space_right, "", logo->color_text[1], attr_value, art->reset); } } } @@ -675,22 +658,19 @@ void print_ascii_arm(struct ascii* art, uint32_t la, void (*callback_print_algor } -void print_ascii(struct ascii* art) { - uint32_t longest_attribute = longest_attribute_length(art); - +void print_ascii(struct ascii* art, uint32_t longest_attribute) { if(art->vendor == SOC_VENDOR_SNAPDRAGON || art->vendor == SOC_VENDOR_MEDIATEK || art->vendor == SOC_VENDOR_KIRIN || art->vendor == SOC_VENDOR_BROADCOM) - print_ascii_arm(art, longest_attribute, &print_algorithm_snapd_mtk); + print_ascii_arm(art, longest_attribute, &print_algorithm_arm); else if(art->vendor == SOC_VENDOR_EXYNOS) - print_ascii_arm(art, longest_attribute, &print_algorithm_samsung); + print_ascii_arm(art, longest_attribute, &print_algorithm_arm); else { if(art->vendor != SOC_VENDOR_UNKNOWN) printWarn("Invalid SOC vendor: %d\n", art->vendor); print_ascii_arm(art, longest_attribute, &print_algorithm_arm); } - } -bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct color** cs) { +bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct color** cs, struct terminal* term) { struct ascii* art = set_ascii(get_soc_vendor(cpu->soc), s, cs); if(art == NULL) return false; @@ -751,14 +731,20 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct color** cs) { } char* pp = get_str_peak_performance(cpu->peak_performance); setAttribute(art,ATTRIBUTE_PEAK,pp); - - if(art->n_attributes_set > NUMBER_OF_LINES) { - art->additional_spaces = (art->n_attributes_set - NUMBER_OF_LINES) / 2; - } - if(cpu->hv->present) + if(cpu->hv->present) { setAttribute(art, ATTRIBUTE_HYPERVISOR, cpu->hv->hv_name); + } - print_ascii(art); + uint32_t longest_attribute = longest_attribute_length(art); + uint32_t longest_field = longest_field_length(art, longest_attribute); + choose_ascii_art(art, term, longest_field); + + struct ascii_logo* logo = art->art; + if(art->n_attributes_set > logo->height) { + art->additional_spaces = (art->n_attributes_set - logo->height) / 2; + } + + print_ascii(art, longest_attribute); free(manufacturing_process); free(pp); From 590c3913806c08c1ef34b96c003918c4bc5ddfe5 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Mon, 9 Aug 2021 13:58:01 +0200 Subject: [PATCH 18/21] [v0.99][PPC] Fix compilation due to new logos in PPC --- src/common/printer.c | 63 +++++++++----------------------------------- 1 file changed, 13 insertions(+), 50 deletions(-) diff --git a/src/common/printer.c b/src/common/printer.c index 34c715b..36c44e9 100644 --- a/src/common/printer.c +++ b/src/common/printer.c @@ -26,7 +26,9 @@ #include #else #ifdef __linux__ - #define _POSIX_C_SOURCE 199309L + #ifndef _POSIX_C_SOURCE + #define _POSIX_C_SOURCE 199309L + #endif #endif #include #include @@ -168,7 +170,6 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct color** cs) { #elif ARCH_PPC COL_FANCY_1 = COLOR_BG_CYAN; COL_FANCY_2 = COLOR_BG_WHITE; - art->ascii_chars[0] = '#'; #elif ARCH_ARM if(art->vendor == SOC_VENDOR_SNAPDRAGON) { COL_FANCY_1 = COLOR_BG_RED; @@ -352,8 +353,8 @@ uint32_t longest_field_length(struct ascii* art, int la) { return max; } -#ifdef ARCH_X86 -void print_ascii_x86(struct ascii* art, uint32_t la) { +#if defined(ARCH_X86) || defined(ARCH_PPC) +void print_ascii_generic(struct ascii* art, uint32_t la) { struct ascii_logo* logo = art->art; int attr_to_print = 0; int attr_type; @@ -402,7 +403,9 @@ void print_ascii_x86(struct ascii* art, uint32_t la) { } printf("\n"); } +#endif +#ifdef ARCH_X86 bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs, struct terminal* term) { struct ascii* art = set_ascii(get_cpu_vendor(cpu), s, cs); if(art == NULL) @@ -454,7 +457,7 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs, struct uint32_t longest_field = longest_field_length(art, longest_attribute); choose_ascii_art(art, term, longest_field); - print_ascii_x86(art, longest_attribute); + print_ascii_generic(art, longest_attribute); free(manufacturing_process); free(max_frequency); @@ -483,46 +486,7 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs, struct #endif #ifdef ARCH_PPC -void print_algorithm_ppc(struct ascii* art, int n) { - for(int i=0; i < LINE_SIZE; i++) { - if(art->art[n][i] == '#') - printf("%s%c%s", art->color1_ascii, art->ascii_chars[0], art->reset); - else - printf("%c",art->art[n][i]); - } -} - -void print_ascii_ppc(struct ascii* art, uint32_t la) { - int attr_to_print = 0; - int attr_type; - char* attr_value; - uint32_t space_right; - uint32_t space_up = (NUMBER_OF_LINES - art->n_attributes_set)/2; - uint32_t space_down = NUMBER_OF_LINES - art->n_attributes_set - space_up; - - printf("\n"); - for(uint32_t n=0;n space_up-1 && n < NUMBER_OF_LINES-space_down) { - attr_type = art->attributes[attr_to_print]->type; - attr_value = art->attributes[attr_to_print]->value; - attr_to_print++; - - space_right = 1 + (la - strlen(ATTRIBUTE_FIELDS[attr_type])); - printf("%s%s%s%*s%s%s%s\n", art->color1_text, ATTRIBUTE_FIELDS[attr_type], art->reset, space_right, "", art->color2_text, attr_value, art->reset); - } - else printf("\n"); - } - printf("\n"); -} - -/*void print_ascii(struct ascii* art) { - uint32_t longest_attribute = longest_attribute_length(art); - print_ascii_ppc(art, longest_attribute); -}*/ - -bool print_cpufetch_ppc(struct cpuInfo* cpu, STYLE s, struct color** cs) { +bool print_cpufetch_ppc(struct cpuInfo* cpu, STYLE s, struct color** cs, struct terminal* term) { struct ascii* art = set_ascii(get_cpu_vendor(cpu), s, cs); if(art == NULL) return false; @@ -566,12 +530,11 @@ bool print_cpufetch_ppc(struct cpuInfo* cpu, STYLE s, struct color** cs) { } setAttribute(art,ATTRIBUTE_PEAK,pp); - if(art->n_attributes_set > NUMBER_OF_LINES) { - printBug("The number of attributes set is bigger than the max that can be displayed"); - return false; - } + uint32_t longest_attribute = longest_attribute_length(art); + uint32_t longest_field = longest_field_length(art, longest_attribute); + choose_ascii_art(art, term, longest_field); - print_ascii(art); + print_ascii_generic(art, longest_attribute); return true; } From 6a67b87abcc241b2d4f905698e6826ffa6d5b71d Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Tue, 10 Aug 2021 08:48:52 +0200 Subject: [PATCH 19/21] [v0.99] Partially recover --color and --style options --- src/common/ascii.h | 4 +- src/common/printer.c | 149 +++++++++++++------------------------------ 2 files changed, 45 insertions(+), 108 deletions(-) diff --git a/src/common/ascii.h b/src/common/ascii.h index 73b0181..2e5e56b 100644 --- a/src/common/ascii.h +++ b/src/common/ascii.h @@ -25,8 +25,8 @@ struct ascii_logo { uint32_t width; uint32_t height; bool replace_blocks; - char* color_ascii[8]; - char* color_text[2]; + char color_ascii[8][100]; + char color_text[2][100]; }; /* diff --git a/src/common/printer.c b/src/common/printer.c index 36c44e9..7edfb0b 100644 --- a/src/common/printer.c +++ b/src/common/printer.c @@ -140,9 +140,9 @@ char* rgb_to_ansi(struct color* c, bool background, bool bold) { return str; } -struct ascii* set_ascii(VENDOR vendor, STYLE style, struct color** cs) { - char *COL_FANCY_1, *COL_FANCY_2, *COL_RETRO_1, *COL_RETRO_2; +struct ascii* set_ascii(VENDOR vendor, STYLE style) { struct ascii* art = emalloc(sizeof(struct ascii)); + art->n_attributes_set = 0; art->additional_spaces = 0; art->vendor = vendor; @@ -152,53 +152,6 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct color** cs) { art->attributes[i]->type = 0; art->attributes[i]->value = NULL; } - strcpy(art->reset, COLOR_RESET); - -#ifdef ARCH_X86 - if(art->vendor == CPU_VENDOR_INTEL) { - COL_FANCY_1 = COLOR_FG_CYAN; - COL_FANCY_2 = COLOR_FG_WHITE; - } - else if(art->vendor == CPU_VENDOR_AMD) { - COL_FANCY_1 = COLOR_BG_WHITE; - COL_FANCY_2 = COLOR_BG_GREEN; - } - else { - printBug("Invalid CPU vendor in set_ascii (%d)", art->vendor); - return NULL; - } -#elif ARCH_PPC - COL_FANCY_1 = COLOR_BG_CYAN; - COL_FANCY_2 = COLOR_BG_WHITE; -#elif ARCH_ARM - if(art->vendor == SOC_VENDOR_SNAPDRAGON) { - COL_FANCY_1 = COLOR_BG_RED; - COL_FANCY_2 = COLOR_BG_WHITE; - } - else if(art->vendor == SOC_VENDOR_MEDIATEK) { - COL_FANCY_1 = COLOR_FG_WHITE; - COL_FANCY_2 = COLOR_FG_BLUE; - } - else if(art->vendor == SOC_VENDOR_EXYNOS) { - COL_FANCY_1 = COLOR_BG_BLUE; - COL_FANCY_2 = COLOR_BG_WHITE; - } - else if(art->vendor == SOC_VENDOR_KIRIN) { - COL_FANCY_1 = COLOR_BG_WHITE; - COL_FANCY_2 = COLOR_BG_RED; - } - else if(art->vendor == SOC_VENDOR_BROADCOM) { - COL_FANCY_1 = COLOR_BG_WHITE; - COL_FANCY_2 = COLOR_BG_RED; - } - else { - COL_FANCY_1 = COLOR_FG_WHITE; - COL_FANCY_2 = COLOR_FG_CYAN; - } -#endif - // TODO - COL_RETRO_1 = COL_FANCY_1; - COL_RETRO_2 = COL_FANCY_2; #ifdef _WIN32 // Old Windows do not define the flag @@ -229,36 +182,6 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct color** cs) { art->style = style; } - switch(art->style) { - case STYLE_LEGACY: - art->reset[0] = '\0'; - break; - case STYLE_FANCY: - if(cs != NULL) { - COL_FANCY_1 = rgb_to_ansi(cs[0], false, true); - COL_FANCY_2 = rgb_to_ansi(cs[1], false, true); - } - if(cs != NULL) { - free(COL_FANCY_1); - free(COL_FANCY_2); - } - break; - case STYLE_RETRO: - if(cs != NULL) { - COL_RETRO_1 = rgb_to_ansi(cs[0], false, true); - COL_RETRO_2 = rgb_to_ansi(cs[1], false, true); - } - if(cs != NULL) { - free(COL_RETRO_1); - free(COL_RETRO_2); - } - break; - case STYLE_INVALID: - default: - printBug("Found invalid style (%d)", art->style); - return NULL; - } - return art; } @@ -274,14 +197,15 @@ void parse_print_color(struct ascii* art, uint32_t* logo_pos) { printf("%s", logo->color_ascii[color_id]); } - *logo_pos+=3; + *logo_pos += 3; } bool ascii_fits_screen(int termw, struct ascii_logo logo, int lf) { return termw - ((int) logo.width + lf) >= 0; } -void choose_ascii_art(struct ascii* art, struct terminal* term, int lf) { +void choose_ascii_art(struct ascii* art, struct color** cs, struct terminal* term, int lf) { + // 1. Choose logo #ifdef ARCH_X86 if(art->vendor == CPU_VENDOR_INTEL) { if(term != NULL && ascii_fits_screen(term->w, logo_intel_l, lf)) @@ -321,6 +245,35 @@ void choose_ascii_art(struct ascii* art, struct terminal* term, int lf) { art->art = &logo_arm; } #endif + + // 2. Choose colors + struct ascii_logo* logo = art->art; + + switch(art->style) { + case STYLE_LEGACY: + logo->replace_blocks = false; + strcpy(logo->color_text[0], COLOR_NONE); + strcpy(logo->color_text[1], COLOR_NONE); + strcpy(logo->color_ascii[0], COLOR_NONE); + strcpy(logo->color_ascii[1], COLOR_NONE); + art->reset[0] = '\0'; + break; + case STYLE_RETRO: + logo->replace_blocks = false; + // fall through + case STYLE_FANCY: + if(cs != NULL) { + strcpy(logo->color_text[0], rgb_to_ansi(cs[2], false, true)); + strcpy(logo->color_text[1], rgb_to_ansi(cs[3], false, true)); + strcpy(logo->color_ascii[0], rgb_to_ansi(cs[0], true, true)); + strcpy(logo->color_ascii[1], rgb_to_ansi(cs[1], true, true)); + } + strcpy(art->reset, COLOR_RESET); + break; + case STYLE_INVALID: + default: + printBug("Found invalid style (%d)", art->style); + } } uint32_t longest_attribute_length(struct ascii* art) { @@ -370,7 +323,7 @@ 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+1] == 'C') { + if(logo->art[logo_pos] == '$' || logo->art[logo_pos] == '\x1b') { parse_print_color(art, &logo_pos); } if(logo->replace_blocks && logo->art[logo_pos] != ' ') { @@ -407,7 +360,7 @@ void print_ascii_generic(struct ascii* art, uint32_t la) { #ifdef ARCH_X86 bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs, struct terminal* term) { - struct ascii* art = set_ascii(get_cpu_vendor(cpu), s, cs); + struct ascii* art = set_ascii(get_cpu_vendor(cpu), s); if(art == NULL) return false; @@ -455,7 +408,7 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs, struct uint32_t longest_attribute = longest_attribute_length(art); uint32_t longest_field = longest_field_length(art, longest_attribute); - choose_ascii_art(art, term, longest_field); + choose_ascii_art(art, cs, term, longest_field); print_ascii_generic(art, longest_attribute); @@ -487,7 +440,7 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs, struct #ifdef ARCH_PPC bool print_cpufetch_ppc(struct cpuInfo* cpu, STYLE s, struct color** cs, struct terminal* term) { - struct ascii* art = set_ascii(get_cpu_vendor(cpu), s, cs); + struct ascii* art = set_ascii(get_cpu_vendor(cpu), s); if(art == NULL) return false; @@ -532,7 +485,7 @@ bool print_cpufetch_ppc(struct cpuInfo* cpu, STYLE s, struct color** cs, struct uint32_t longest_attribute = longest_attribute_length(art); uint32_t longest_field = longest_field_length(art, longest_attribute); - choose_ascii_art(art, term, longest_field); + choose_ascii_art(art, cs, term, longest_field); print_ascii_generic(art, longest_attribute); @@ -541,11 +494,7 @@ bool print_cpufetch_ppc(struct cpuInfo* cpu, STYLE s, struct color** cs, struct #endif #ifdef ARCH_ARM -void print_algorithm_arm(struct ascii* art, int n) { - -} - -void print_ascii_arm(struct ascii* art, uint32_t la, void (*callback_print_algorithm)(struct ascii* art, int n)) { +void print_ascii_arm(struct ascii* art, uint32_t la) { struct ascii_logo* logo = art->art; int attr_to_print = 0; int attr_type; @@ -621,20 +570,8 @@ void print_ascii_arm(struct ascii* art, uint32_t la, void (*callback_print_algor } -void print_ascii(struct ascii* art, uint32_t longest_attribute) { - if(art->vendor == SOC_VENDOR_SNAPDRAGON || art->vendor == SOC_VENDOR_MEDIATEK || art->vendor == SOC_VENDOR_KIRIN || art->vendor == SOC_VENDOR_BROADCOM) - print_ascii_arm(art, longest_attribute, &print_algorithm_arm); - else if(art->vendor == SOC_VENDOR_EXYNOS) - print_ascii_arm(art, longest_attribute, &print_algorithm_arm); - else { - if(art->vendor != SOC_VENDOR_UNKNOWN) - printWarn("Invalid SOC vendor: %d\n", art->vendor); - print_ascii_arm(art, longest_attribute, &print_algorithm_arm); - } -} - bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct color** cs, struct terminal* term) { - struct ascii* art = set_ascii(get_soc_vendor(cpu->soc), s, cs); + struct ascii* art = set_ascii(get_soc_vendor(cpu->soc), s); if(art == NULL) return false; @@ -700,14 +637,14 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct color** cs, struct uint32_t longest_attribute = longest_attribute_length(art); uint32_t longest_field = longest_field_length(art, longest_attribute); - choose_ascii_art(art, term, longest_field); + choose_ascii_art(art, cs, term, longest_field); struct ascii_logo* logo = art->art; if(art->n_attributes_set > logo->height) { art->additional_spaces = (art->n_attributes_set - logo->height) / 2; } - print_ascii(art, longest_attribute); + print_ascii_arm(art, longest_attribute); free(manufacturing_process); free(pp); From 7cd578b889ca03990d032ee60bff0b99eb17613f Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Tue, 10 Aug 2021 10:32:08 +0200 Subject: [PATCH 20/21] [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); From 3cc56c5900e7f79cb66108f7e3310588b30c9576 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Tue, 10 Aug 2021 11:22:30 +0200 Subject: [PATCH 21/21] [v0.99][ARM] Special case of longest_field_length for ARM, which adds two spaces in some fields --- src/common/printer.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/common/printer.c b/src/common/printer.c index a3d42db..3a7026f 100644 --- a/src/common/printer.c +++ b/src/common/printer.c @@ -515,6 +515,27 @@ bool print_cpufetch_ppc(struct cpuInfo* cpu, STYLE s, struct color** cs, struct #endif #ifdef ARCH_ARM +uint32_t longest_field_length_arm(struct ascii* art, int la) { + uint32_t max = 0; + uint64_t len = 0; + + for(uint32_t i=0; i < art->n_attributes_set; i++) { + if(art->attributes[i]->value != NULL) { + // longest attribute + 1 (space) + longest value + len = la + 1 + strlen(art->attributes[i]->value); + if(art->attributes[i]->type == ATTRIBUTE_UARCH || + art->attributes[i]->type == ATTRIBUTE_FREQUENCY || + art->attributes[i]->type == ATTRIBUTE_NCORES || + art->attributes[i]->type == ATTRIBUTE_FEATURES) { + len += 2; + } + if(len > max) max = len; + } + } + + return max; +} + void print_ascii_arm(struct ascii* art, uint32_t la) { struct ascii_logo* logo = art->art; int attr_to_print = 0; @@ -658,7 +679,7 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct color** cs, struct } uint32_t longest_attribute = longest_attribute_length(art); - uint32_t longest_field = longest_field_length(art, longest_attribute); + uint32_t longest_field = longest_field_length_arm(art, longest_attribute); choose_ascii_art(art, cs, term, longest_field); struct ascii_logo* logo = art->art;