Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/src/pacman/util.c
diff options
context:
space:
mode:
authorCarson Black <uhhadd@gmail.com>2020-04-14 20:51:03 -0400
committerAllan McRae <allan@archlinux.org>2020-04-15 11:05:55 +1000
commitb323528491470ff77815fea97289c2cbf7e29689 (patch)
tree3307d4ba9eb8a920f5fdde9360617e67e75cd00e /src/pacman/util.c
parent6ba250e4001740ca428226abf157b25aa121c7bf (diff)
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: Carson Black <uhhadd@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'src/pacman/util.c')
-rw-r--r--src/pacman/util.c46
1 files changed, 34 insertions, 12 deletions
diff --git a/src/pacman/util.c b/src/pacman/util.c
index a3a85bb9..6693ec75 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -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);
}