Colorize [installed] and [pending] when printing optional dependencies. FS#34920 Signed-off-by: Michael Straube <michael.straube@posteo.de> --- src/pacman/package.c | 3 +-- src/pacman/util.c | 14 ++++++++++++-- src/pacman/util.h | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/pacman/package.c b/src/pacman/package.c index d8880837..d85a8834 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -172,8 +172,7 @@ static void optdeplist_display(alpm_pkg_t *pkg, unsigned short cols) if(alpm_pkg_get_origin(pkg) == ALPM_PKG_FROM_LOCALDB) { if(alpm_find_satisfier(alpm_db_get_pkgcache(localdb), depstring)) { const char *installed = _(" [installed]"); - depstring = realloc(depstring, strlen(depstring) + strlen(installed) + 1); - strcpy(depstring + strlen(depstring), installed); + optstring_append_status(&depstring, installed); } } text = alpm_list_add(text, depstring); diff --git a/src/pacman/util.c b/src/pacman/util.c index 74e1037d..7e7e080e 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1214,6 +1214,17 @@ static int depend_cmp(const void *d1, const void *d2) return ret; } +void optstring_append_status(char **optstring, const char *status) +{ + const colstr_t *colstr = &config->colstr; + size_t len; + + len = strlen(colstr->meta) + strlen(status) + strlen(colstr->nocolor); + *optstring = realloc(*optstring, strlen(*optstring) + len + 1); + snprintf(*optstring + strlen(*optstring), len + 1, "%s%s%s", + colstr->meta, status, colstr->nocolor); +} + static char *make_optstring(alpm_depend_t *optdep) { alpm_db_t *localdb = alpm_get_localdb(config->handle); @@ -1225,8 +1236,7 @@ static char *make_optstring(alpm_depend_t *optdep) status = _(" [pending]"); } if(status) { - optstring = realloc(optstring, strlen(optstring) + strlen(status) + 1); - strcpy(optstring + strlen(optstring), status); + optstring_append_status(&optstring, status); } return optstring; } diff --git a/src/pacman/util.h b/src/pacman/util.h index a1fbef46..0f0d506b 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -67,6 +67,7 @@ void signature_display(const char *title, alpm_siglist_t *siglist, unsigned short maxcols); void display_targets(void); int str_cmp(const void *s1, const void *s2); +void optstring_append_status(char **optstring, const char *status); void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg); void display_optdepends(alpm_pkg_t *pkg); void print_packages(const alpm_list_t *packages); -- 2.19.2