[v0.99] Set colors in the logo struct, instead of deducing them from the CPU manufacturer

This commit is contained in:
Dr-Noob
2021-08-08 11:47:03 +02:00
parent 783785e312
commit 1326314103
2 changed files with 118 additions and 145 deletions

View File

@@ -1,10 +1,21 @@
#ifndef __ASCII__ #ifndef __ASCII__
#define __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 { struct ascii_logo {
char* art; char* art;
uint32_t width; uint32_t width;
uint32_t height; uint32_t height;
char* color_ascii[8];
char* color_text[2];
}; };
#define ASCII_AMD \ #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 // 1 2 3 4 5 6
//3456789012345678901234567890123456789012345678901234567890 // 123456789012345678901234567890123456789012345678901234567890
#define ASCII_INTEL \ #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 \ #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 {
\ \
\ \
\ \
## ## ## \ $C1## ## ## \
## ## \ $C1## ## \
## \ $C1## \
## ## \ $C1## ## \
## ## ## \ $C1## ## ## \
\ \
SAMSUNG \ $C2SAMSUNG \
Exynos \ $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 }; // LOGO W H COLORS LOGO (>0 && <10) COLORS TEXT (=2)
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_amd = { ASCII_AMD, 62, 19, {COLOR_WHITE, COLOR_GREEN}, {COLOR_WHITE, COLOR_GREEN} };
static struct ascii_logo logo_mtk = { ASCII_MTK, 62, 19 }; static struct ascii_logo logo_intel = { ASCII_INTEL, 62, 19, {COLOR_CYAN}, {COLOR_CYAN, COLOR_WHITE} };
static struct ascii_logo logo_exynos = { ASCII_EXYNOS, 62, 19 }; static struct ascii_logo logo_snapd = { ASCII_SNAPD, 62, 19, {COLOR_RED, COLOR_WHITE}, {COLOR_RED, COLOR_WHITE} };
static struct ascii_logo logo_kirin = { ASCII_KIRIN, 62, 19 }; static struct ascii_logo logo_mtk = { ASCII_MTK, 62, 19, {COLOR_BLUE, COLOR_YELLOW}, {COLOR_BLUE, COLOR_YELLOW} };
static struct ascii_logo logo_broadcom = { ASCII_BROADCOM, 62, 19 }; static struct ascii_logo logo_exynos = { ASCII_EXYNOS, 62, 19, {COLOR_BLUE, COLOR_WHITE}, {COLOR_BLUE, COLOR_WHITE}, };
static struct ascii_logo logo_arm = { ASCII_ARM, 62, 19 }; static struct ascii_logo logo_kirin = { ASCII_KIRIN, 62, 19, {COLOR_WHITE, COLOR_RED}, {COLOR_WHITE, COLOR_RED} };
static struct ascii_logo logo_ibm = { ASCII_IBM, 62, 19 }; static struct ascii_logo logo_broadcom = { ASCII_BROADCOM, 62, 19, {COLOR_WHITE, COLOR_RED}, {COLOR_WHITE, COLOR_RED} };
static struct ascii_logo logo_unknown = { ASCII_UNKNOWN, 62, 19 }; 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 [] = { static struct ascii_logo* ASCII_ARRAY [] = {
&logo_amd, &logo_amd,

View File

@@ -112,11 +112,6 @@ struct attribute {
struct ascii { struct ascii {
struct ascii_logo* art; 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]; char reset[100];
struct attribute** attributes; struct attribute** attributes;
uint32_t n_attributes_set; 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) { 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)); struct ascii* art = emalloc(sizeof(struct ascii));
art->n_attributes_set = 0; art->n_attributes_set = 0;
art->additional_spaces = 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) { if(art->vendor == CPU_VENDOR_INTEL) {
COL_FANCY_1 = COLOR_FG_CYAN; COL_FANCY_1 = COLOR_FG_CYAN;
COL_FANCY_2 = COLOR_FG_WHITE; 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) { else if(art->vendor == CPU_VENDOR_AMD) {
COL_FANCY_1 = COLOR_BG_WHITE; COL_FANCY_1 = COLOR_BG_WHITE;
COL_FANCY_2 = COLOR_BG_GREEN; COL_FANCY_2 = COLOR_BG_GREEN;
COL_FANCY_3 = COLOR_FG_WHITE;
COL_FANCY_4 = COLOR_FG_GREEN;
art->ascii_chars[0] = '@';
} }
else { else {
printBug("Invalid CPU vendor in set_ascii (%d)", art->vendor); 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 #elif ARCH_PPC
COL_FANCY_1 = COLOR_BG_CYAN; COL_FANCY_1 = COLOR_BG_CYAN;
COL_FANCY_2 = COLOR_BG_WHITE; COL_FANCY_2 = COLOR_BG_WHITE;
COL_FANCY_3 = COLOR_FG_CYAN;
COL_FANCY_4 = COLOR_FG_WHITE;
art->ascii_chars[0] = '#'; art->ascii_chars[0] = '#';
#elif ARCH_ARM #elif ARCH_ARM
if(art->vendor == SOC_VENDOR_SNAPDRAGON) { if(art->vendor == SOC_VENDOR_SNAPDRAGON) {
COL_FANCY_1 = COLOR_BG_RED; COL_FANCY_1 = COLOR_BG_RED;
COL_FANCY_2 = COLOR_BG_WHITE; 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) { else if(art->vendor == SOC_VENDOR_MEDIATEK) {
COL_FANCY_1 = COLOR_BG_BLUE; COL_FANCY_1 = COLOR_FG_WHITE;
COL_FANCY_2 = COLOR_BG_YELLOW; COL_FANCY_2 = COLOR_FG_BLUE;
COL_FANCY_3 = COLOR_FG_WHITE;
COL_FANCY_4 = COLOR_FG_BLUE;
art->ascii_chars[0] = '@';
} }
else if(art->vendor == SOC_VENDOR_EXYNOS) { else if(art->vendor == SOC_VENDOR_EXYNOS) {
COL_FANCY_1 = COLOR_BG_BLUE; COL_FANCY_1 = COLOR_BG_BLUE;
COL_FANCY_2 = COLOR_BG_WHITE; 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) { else if(art->vendor == SOC_VENDOR_KIRIN) {
COL_FANCY_1 = COLOR_BG_WHITE; COL_FANCY_1 = COLOR_BG_WHITE;
COL_FANCY_2 = COLOR_BG_RED; 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) { else if(art->vendor == SOC_VENDOR_BROADCOM) {
COL_FANCY_1 = COLOR_BG_WHITE; COL_FANCY_1 = COLOR_BG_WHITE;
COL_FANCY_2 = COLOR_BG_RED; COL_FANCY_2 = COLOR_BG_RED;
COL_FANCY_3 = COLOR_FG_WHITE;
COL_FANCY_4 = COLOR_FG_RED;
art->ascii_chars[0] = '@';
} }
else { else {
COL_FANCY_1 = COLOR_BG_CYAN; COL_FANCY_1 = COLOR_FG_WHITE;
COL_FANCY_2 = COLOR_BG_CYAN; COL_FANCY_2 = COLOR_FG_CYAN;
COL_FANCY_3 = COLOR_FG_WHITE;
COL_FANCY_4 = COLOR_FG_CYAN;
art->ascii_chars[0] = '#';
} }
#endif #endif
COL_RETRO_1 = COL_FANCY_3; // TODO
COL_RETRO_2 = COL_FANCY_4; COL_RETRO_1 = COL_FANCY_1;
COL_RETRO_3 = COL_RETRO_1; COL_RETRO_2 = COL_FANCY_2;
COL_RETRO_4 = COL_RETRO_2;
art->ascii_chars[1] = '#';
#ifdef _WIN32 #ifdef _WIN32
// Old Windows do not define the flag // 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) { switch(art->style) {
case STYLE_LEGACY: 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'; art->reset[0] = '\0';
break; break;
case STYLE_FANCY: case STYLE_FANCY:
if(cs != NULL) { if(cs != NULL) {
COL_FANCY_1 = rgb_to_ansi(cs[0], false, true); COL_FANCY_1 = rgb_to_ansi(cs[0], false, true);
COL_FANCY_2 = rgb_to_ansi(cs[1], 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) { if(cs != NULL) {
free(COL_FANCY_1); free(COL_FANCY_1);
free(COL_FANCY_2); free(COL_FANCY_2);
free(COL_FANCY_3);
free(COL_FANCY_4);
} }
break; break;
case STYLE_RETRO: case STYLE_RETRO:
if(cs != NULL) { if(cs != NULL) {
COL_RETRO_1 = rgb_to_ansi(cs[0], false, true); COL_RETRO_1 = rgb_to_ansi(cs[0], false, true);
COL_RETRO_2 = rgb_to_ansi(cs[1], 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) { if(cs != NULL) {
free(COL_RETRO_1); free(COL_RETRO_1);
free(COL_RETRO_2); free(COL_RETRO_2);
free(COL_RETRO_3);
free(COL_RETRO_4);
} }
break; break;
case STYLE_INVALID: case STYLE_INVALID:
@@ -362,6 +307,15 @@ uint32_t longest_attribute_length(struct ascii* art) {
} }
#ifdef ARCH_X86 #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) { void print_ascii_x86(struct ascii* art, uint32_t la) {
struct ascii_logo* logo = art->art; struct ascii_logo* logo = art->art;
int attr_to_print = 0; 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_right;
uint32_t space_up = (logo->height - art->n_attributes_set)/2; 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 space_down = logo->height - art->n_attributes_set - space_up;
uint32_t logo_pos = 0;
printf("\n"); printf("\n");
for(uint32_t n=0; n < logo->height; n++) { for(uint32_t n=0; n < logo->height; n++) {
for(uint32_t i=0; i < logo->width; i++) { 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) { if(n > space_up-1 && n < logo->height - space_down) {
attr_type = art->attributes[attr_to_print]->type; 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++; attr_to_print++;
space_right = 1 + (la - strlen(ATTRIBUTE_FIELDS[attr_type])); 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"); 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) { bool print_cpufetch(struct cpuInfo* cpu, STYLE s, struct color** cs) {
// Sanity check of ASCII arts // 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++) { for(int i=0; i < len; i++) {
const struct ascii_logo* logo = ASCII_ARRAY[i]; const struct ascii_logo* logo = ASCII_ARRAY[i];
if(strlen(logo->art) != (logo->width * logo->height)) { 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); i, strlen(logo->art), logo->height * logo->width);
return false; return false;
} }
} }*/
#ifdef ARCH_X86 #ifdef ARCH_X86
return print_cpufetch_x86(cpu, s, cs); return print_cpufetch_x86(cpu, s, cs);