[v0.99] Refactor cut text and add support for ARM too

This commit is contained in:
Dr-Noob
2021-08-14 19:08:22 +02:00
parent 4e29e481b7
commit f8f81c3222
3 changed files with 28 additions and 22 deletions

View File

@@ -73,6 +73,10 @@ int max(int a, int b) {
return a > b ? a : b; return a > b ? a : b;
} }
int min(int a, int b) {
return a < b ? a : b;
}
char *strremove(char *str, const char *sub) { char *strremove(char *str, const char *sub) {
char *p, *q, *r; char *p, *q, *r;
if (*sub && (q = r = strstr(str, sub)) != NULL) { if (*sub && (q = r = strstr(str, sub)) != NULL) {

View File

@@ -10,6 +10,7 @@ void set_log_level(bool verbose);
void printWarn(const char *fmt, ...); void printWarn(const char *fmt, ...);
void printErr(const char *fmt, ...); void printErr(const char *fmt, ...);
void printBug(const char *fmt, ...); void printBug(const char *fmt, ...);
int min(int a, int b);
int max(int a, int b); int max(int a, int b);
char *strremove(char *str, const char *sub); char *strremove(char *str, const char *sub);
void* emalloc(size_t size); void* emalloc(size_t size);

View File

@@ -364,12 +364,11 @@ void print_ascii_generic(struct ascii* art, uint32_t la, int32_t text_space, con
int attr_type; int attr_type;
char* attr_value; char* attr_value;
int32_t current_space; int32_t current_space;
uint32_t space_right; int32_t space_right;
int32_t space_up = ((int)logo->height - (int)art->n_attributes_set)/2; 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; int32_t space_down = (int)logo->height - (int)art->n_attributes_set - (int)space_up;
uint32_t logo_pos = 0; uint32_t logo_pos = 0;
int32_t iters = max(logo->height, art->n_attributes_set); int32_t iters = max(logo->height, art->n_attributes_set);
char* text_output = emalloc(sizeof(char) * 1024);
printf("\n"); printf("\n");
for(int32_t n=0; n < iters; n++) { for(int32_t n=0; n < iters; n++) {
@@ -406,23 +405,16 @@ void print_ascii_generic(struct ascii* art, uint32_t la, int32_t text_space, con
space_right = 1 + (la - strlen(attribute_fields[attr_type])); space_right = 1 + (la - strlen(attribute_fields[attr_type]));
current_space = max(0, text_space); current_space = max(0, text_space);
snprintf(text_output, 1024, "%s", attribute_fields[attr_type]); printf("%s%.*s%s", logo->color_text[0], current_space, attribute_fields[attr_type], art->reset);
printf("%s%.*s%s", logo->color_text[0], current_space, text_output, art->reset); current_space = max(0, current_space - (int) strlen(attribute_fields[attr_type]));
current_space -= strlen(attribute_fields[attr_type]); printf("%*s", min(current_space, space_right), "");
current_space = max(0, current_space); current_space = max(0, current_space - min(current_space, space_right));
snprintf(text_output, 1024, "%*s", space_right, ""); printf("%s%.*s%s", logo->color_text[1], current_space, attr_value, art->reset);
printf("%.*s", current_space, text_output);
current_space -= space_right;
current_space = max(0, current_space);
snprintf(text_output, 1024, "%s", attr_value);
printf("%s%.*s%s", logo->color_text[1], current_space, text_output, art->reset);
printf("\n"); printf("\n");
} }
else printf("\n"); else printf("\n");
} }
printf("\n"); printf("\n");
free(text_output);
} }
#endif #endif
@@ -599,7 +591,7 @@ uint32_t longest_field_length_arm(struct ascii* art, int la) {
return max; return max;
} }
void print_ascii_arm(struct ascii* art, uint32_t la, const char** attribute_fields) { void print_ascii_arm(struct ascii* art, uint32_t la, int32_t text_space, const char** attribute_fields) {
struct ascii_logo* logo = art->art; struct ascii_logo* logo = art->art;
int attr_to_print = 0; int attr_to_print = 0;
int attr_type; int attr_type;
@@ -608,6 +600,8 @@ void print_ascii_arm(struct ascii* art, uint32_t la, const char** attribute_fiel
int32_t limit_down; int32_t limit_down;
uint32_t logo_pos = 0; uint32_t logo_pos = 0;
uint32_t space_right; uint32_t space_right;
int32_t beg_space;
int32_t current_space;
int32_t space_up = ((int)logo->height - (int)art->n_attributes_set)/2; 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; int32_t space_down = (int)logo->height - (int)art->n_attributes_set - (int)space_up;
@@ -662,14 +656,21 @@ void print_ascii_arm(struct ascii* art, uint32_t la, const char** attribute_fiel
add_space = true; add_space = true;
} }
else { else {
if(add_space) { beg_space = 0;
space_right = 1 + (la - strlen(attribute_fields[attr_type]));
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])); space_right = 2 + 1 + (la - strlen(attribute_fields[attr_type]));
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); if(add_space) {
space_right -= 2;
if(text_space >= 0) beg_space = 2;
} }
//TODO: Cut text buggy
current_space = max(0, text_space);
printf("%*s%s%.*s%s", beg_space, "", logo->color_text[0], current_space, attribute_fields[attr_type], art->reset);
current_space = max(0, current_space - ((int) strlen(attribute_fields[attr_type]) + beg_space));
printf("%*s", min(current_space, space_right), "");
current_space = max(0, current_space - min(current_space, space_right));
printf("%s%.*s%s", logo->color_text[1], current_space, attr_value, art->reset);
printf("\n");
} }
} }
else printf("\n"); else printf("\n");
@@ -759,7 +760,7 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct color** cs, struct
longest_attribute = longest_attribute_length(art, attribute_fields); longest_attribute = longest_attribute_length(art, attribute_fields);
} }
print_ascii_arm(art, longest_attribute, attribute_fields); print_ascii_arm(art, longest_attribute, term->w - art->art->width, attribute_fields);
free(manufacturing_process); free(manufacturing_process);
free(pp); free(pp);