mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 07:50:40 +01:00
[v0.99] Create structs for all logos and remove width/height constants
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;n<NUMBER_OF_LINES;n++) {
|
||||
callback_print_algorithm(art, n, &flag);
|
||||
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(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);
|
||||
|
||||
Reference in New Issue
Block a user