[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

This commit is contained in:
Dr-Noob
2021-08-09 12:12:14 +02:00
parent 5d92814cd0
commit 7c5e638c2f
2 changed files with 186 additions and 16 deletions

View File

@@ -36,6 +36,7 @@ struct ascii_logo {
* CR: Color reset, gets replaced by the reset color by printer.c * CR: Color reset, gets replaced by the reset color by printer.c
*/ */
// SHORT LOGOS //
#define ASCII_AMD \ #define ASCII_AMD \
"$C2 '############### \ "$C2 '############### \
$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; 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_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_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_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_unknown = { NULL, 0, 0, false, {COLOR_NONE}, {COLOR_NONE, COLOR_NONE} }; asciiL logo_unknown = { NULL, 0, 0, false, {COLOR_NONE}, {COLOR_NONE, COLOR_NONE} };
#endif #endif

View File

@@ -2,6 +2,7 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#include <errno.h>
#include "printer.h" #include "printer.h"
#include "ascii.h" #include "ascii.h"
@@ -23,6 +24,12 @@
#ifdef _WIN32 #ifdef _WIN32
#define NOMINMAX #define NOMINMAX
#include <Windows.h> #include <Windows.h>
#else
#ifdef __linux__
#define _POSIX_C_SOURCE 199309L
#endif
#include <sys/ioctl.h>
#include <unistd.h>
#endif #endif
#define max(a,b) (((a)>(b))?(a):(b)) #define max(a,b) (((a)>(b))?(a):(b))
@@ -86,6 +93,11 @@ static const char* ATTRIBUTE_FIELDS [] = {
"Peak Performance:", "Peak Performance:",
}; };
struct terminal {
int w;
int h;
};
struct attribute { struct attribute {
int type; int type;
char* value; char* value;
@@ -246,14 +258,34 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct color** cs) {
return NULL; 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 #ifdef ARCH_X86
if(art->vendor == CPU_VENDOR_INTEL) if(art->vendor == CPU_VENDOR_INTEL) {
art->art = &logo_intel; if(ascii_fits_screen(term->w, logo_intel_l, lf))
else if(art->vendor == CPU_VENDOR_AMD) art->art = &logo_intel_l;
art->art = &logo_amd;
else 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; art->art = &logo_unknown;
}
#elif ARCH_PPC #elif ARCH_PPC
if(ascii_fits_screen(term->w, logo_ibm_l, lf))
art->art = &logo_ibm_l;
else
art->art = &logo_ibm; art->art = &logo_ibm;
#elif ARCH_ARM #elif ARCH_ARM
if(art->vendor == SOC_VENDOR_SNAPDRAGON) if(art->vendor == SOC_VENDOR_SNAPDRAGON)
@@ -266,11 +298,13 @@ struct ascii* set_ascii(VENDOR vendor, STYLE style, struct color** cs) {
art->art = &logo_kirin; art->art = &logo_kirin;
else if(art->vendor == SOC_VENDOR_BROADCOM) else if(art->vendor == SOC_VENDOR_BROADCOM)
art->art = &logo_broadcom; art->art = &logo_broadcom;
else {
if(ascii_fits_screen(term->w, logo_arm_l, lf))
art->art = &logo_arm_l;
else else
art->art = &logo_unknown; art->art = &logo_arm;
}
#endif #endif
return art;
} }
uint32_t longest_attribute_length(struct ascii* art) { uint32_t longest_attribute_length(struct ascii* art) {
@@ -287,6 +321,22 @@ uint32_t longest_attribute_length(struct ascii* art) {
return max; 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 #ifdef ARCH_X86
void parse_print_color(struct ascii* art, uint32_t* logo_pos) { void parse_print_color(struct ascii* art, uint32_t* logo_pos) {
struct ascii_logo* logo = art->art; struct ascii_logo* logo = art->art;
@@ -350,7 +400,7 @@ void print_ascii_x86(struct ascii* art, uint32_t la) {
printf("\n"); 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); struct ascii* art = set_ascii(get_cpu_vendor(cpu), s, cs);
if(art == NULL) if(art == NULL)
return false; return false;
@@ -398,6 +448,9 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs) {
setAttribute(art,ATTRIBUTE_PEAK,pp); setAttribute(art,ATTRIBUTE_PEAK,pp);
uint32_t longest_attribute = longest_attribute_length(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);
print_ascii_x86(art, longest_attribute); print_ascii_x86(art, longest_attribute);
free(manufacturing_process); free(manufacturing_process);
@@ -717,12 +770,38 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct color** cs) {
} }
#endif #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) { bool print_cpufetch(struct cpuInfo* cpu, STYLE s, struct color** cs) {
struct terminal* term = get_terminal_size();
#ifdef ARCH_X86 #ifdef ARCH_X86
return print_cpufetch_x86(cpu, s, cs); return print_cpufetch_x86(cpu, s, cs, term);
#elif ARCH_PPC #elif ARCH_PPC
return print_cpufetch_ppc(cpu, s, cs); return print_cpufetch_ppc(cpu, s, cs, term);
#elif ARCH_ARM #elif ARCH_ARM
return print_cpufetch_arm(cpu, s, cs); return print_cpufetch_arm(cpu, s, cs, term);
#endif #endif
} }