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;
#define BOLDMAGENTA "\033[1;35m"
#define BOLDCYAN "\033[1;36m"
#define BOLDWHITE "\033[1;37m"
#define GREY46 "\033[38;5;243m"
void enable_colors(int colors)
{
......@@ -76,6 +77,7 @@ void enable_colors(int colors)
colstr->meta = BOLDCYAN;
colstr->warn = BOLDYELLOW;
colstr->err = BOLDRED;
colstr->faint = GREY46;
colstr->nocolor = NOCOLOR;
} else {
colstr->colon = ":: ";
......@@ -86,6 +88,7 @@ void enable_colors(int colors)
colstr->meta = "";
colstr->warn = "";
colstr->err = "";
colstr->faint = "";
colstr->nocolor = "";
}
}
......@@ -119,6 +122,7 @@ config_t *config_new(void)
newconfig->colstr.meta = "";
newconfig->colstr.warn = "";
newconfig->colstr.err = "";
newconfig->colstr.faint = "";
newconfig->colstr.nocolor = "";
return newconfig;
......
......@@ -31,6 +31,7 @@ typedef struct __colstr_t {
const char *meta;
const char *warn;
const char *err;
const char *faint;
const char *nocolor;
} colstr_t;
......
......@@ -415,12 +415,34 @@ static size_t string_length(const char *s)
if(!s || s[0] == '\0') {
return 0;
}
/* 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);
if(strstr(s, "\033")) {
char* replaced = malloc(sizeof(char) * strlen(s));
int iter = 0;
for(; *s; s++) {
if(*s == '\033') {
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;
}
......@@ -905,14 +927,14 @@ static void _display_targets(alpm_list_t *targets, int verbose)
}
if(target->install) {
pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->install),
alpm_pkg_get_version(target->install));
pm_asprintf(&str, "%s%s-%s%s", alpm_pkg_get_name(target->install), config->colstr.faint,
alpm_pkg_get_version(target->install), config->colstr.nocolor);
} else if(isize == 0) {
pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->remove),
alpm_pkg_get_version(target->remove));
pm_asprintf(&str, "%s%s-%s%s", alpm_pkg_get_name(target->remove), config->colstr.faint,
alpm_pkg_get_version(target->remove), config->colstr.nocolor);
} else {
pm_asprintf(&str, "%s-%s [%s]", alpm_pkg_get_name(target->remove),
alpm_pkg_get_version(target->remove), _("removal"));
pm_asprintf(&str, "%s%s-%s %s[%s]%s", alpm_pkg_get_name(target->remove), config->colstr.faint,
alpm_pkg_get_version(target->remove), config->colstr.nocolor, _("removal"), config->colstr.nocolor);
}
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