Commit b3235284 authored by Carson Black's avatar Carson Black Committed by Allan McRae
Browse files

Dull version colour numbers in summary



Version colour numbers are dulled in the non-verbose transaction summary
when colours are enabled.

To prevent a regression, this patch also adds handling of strings with
ANSI codes to string_length as to not break the transaction summary's
output functions when colour codes are in the package name strings.
Signed-off-by: default avatarCarson Black <uhhadd@gmail.com>
Signed-off-by: Allan McRae's avatarAllan McRae <allan@archlinux.org>
parent 6ba250e4
...@@ -62,6 +62,7 @@ config_t *config = NULL; ...@@ -62,6 +62,7 @@ config_t *config = NULL;
#define BOLDMAGENTA "\033[1;35m" #define BOLDMAGENTA "\033[1;35m"
#define BOLDCYAN "\033[1;36m" #define BOLDCYAN "\033[1;36m"
#define BOLDWHITE "\033[1;37m" #define BOLDWHITE "\033[1;37m"
#define GREY46 "\033[38;5;243m"
void enable_colors(int colors) void enable_colors(int colors)
{ {
...@@ -76,6 +77,7 @@ void enable_colors(int colors) ...@@ -76,6 +77,7 @@ void enable_colors(int colors)
colstr->meta = BOLDCYAN; colstr->meta = BOLDCYAN;
colstr->warn = BOLDYELLOW; colstr->warn = BOLDYELLOW;
colstr->err = BOLDRED; colstr->err = BOLDRED;
colstr->faint = GREY46;
colstr->nocolor = NOCOLOR; colstr->nocolor = NOCOLOR;
} else { } else {
colstr->colon = ":: "; colstr->colon = ":: ";
...@@ -86,6 +88,7 @@ void enable_colors(int colors) ...@@ -86,6 +88,7 @@ void enable_colors(int colors)
colstr->meta = ""; colstr->meta = "";
colstr->warn = ""; colstr->warn = "";
colstr->err = ""; colstr->err = "";
colstr->faint = "";
colstr->nocolor = ""; colstr->nocolor = "";
} }
} }
...@@ -119,6 +122,7 @@ config_t *config_new(void) ...@@ -119,6 +122,7 @@ config_t *config_new(void)
newconfig->colstr.meta = ""; newconfig->colstr.meta = "";
newconfig->colstr.warn = ""; newconfig->colstr.warn = "";
newconfig->colstr.err = ""; newconfig->colstr.err = "";
newconfig->colstr.faint = "";
newconfig->colstr.nocolor = ""; newconfig->colstr.nocolor = "";
return newconfig; return newconfig;
......
...@@ -31,6 +31,7 @@ typedef struct __colstr_t { ...@@ -31,6 +31,7 @@ typedef struct __colstr_t {
const char *meta; const char *meta;
const char *warn; const char *warn;
const char *err; const char *err;
const char *faint;
const char *nocolor; const char *nocolor;
} colstr_t; } colstr_t;
......
...@@ -415,12 +415,34 @@ static size_t string_length(const char *s) ...@@ -415,12 +415,34 @@ static size_t string_length(const char *s)
if(!s || s[0] == '\0') { if(!s || s[0] == '\0') {
return 0; return 0;
} }
/* len goes from # bytes -> # chars -> # cols */ if(strstr(s, "\033")) {
len = strlen(s) + 1; char* replaced = malloc(sizeof(char) * strlen(s));
wcstr = calloc(len, sizeof(wchar_t)); int iter = 0;
len = mbstowcs(wcstr, s, len); for(; *s; s++) {
len = wcswidth(wcstr, len); if(*s == '\033') {
free(wcstr); while(*s != 'm') {
s++;
}
} else {
replaced[iter] = *s;
iter++;
}
}
replaced[iter] = '\0';
len = iter;
wcstr = calloc(len, sizeof(wchar_t));
len = mbstowcs(wcstr, replaced, len);
len = wcswidth(wcstr, len);
free(wcstr);
free(replaced);
} else {
/* len goes from # bytes -> # chars -> # cols */
len = strlen(s) + 1;
wcstr = calloc(len, sizeof(wchar_t));
len = mbstowcs(wcstr, s, len);
len = wcswidth(wcstr, len);
free(wcstr);
}
return len; return len;
} }
...@@ -905,14 +927,14 @@ static void _display_targets(alpm_list_t *targets, int verbose) ...@@ -905,14 +927,14 @@ static void _display_targets(alpm_list_t *targets, int verbose)
} }
if(target->install) { if(target->install) {
pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->install), pm_asprintf(&str, "%s%s-%s%s", alpm_pkg_get_name(target->install), config->colstr.faint,
alpm_pkg_get_version(target->install)); alpm_pkg_get_version(target->install), config->colstr.nocolor);
} else if(isize == 0) { } else if(isize == 0) {
pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->remove), pm_asprintf(&str, "%s%s-%s%s", alpm_pkg_get_name(target->remove), config->colstr.faint,
alpm_pkg_get_version(target->remove)); alpm_pkg_get_version(target->remove), config->colstr.nocolor);
} else { } else {
pm_asprintf(&str, "%s-%s [%s]", alpm_pkg_get_name(target->remove), pm_asprintf(&str, "%s%s-%s %s[%s]%s", alpm_pkg_get_name(target->remove), config->colstr.faint,
alpm_pkg_get_version(target->remove), _("removal")); alpm_pkg_get_version(target->remove), config->colstr.nocolor, _("removal"), config->colstr.nocolor);
} }
names = alpm_list_add(names, str); names = alpm_list_add(names, str);
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment