From: Xavion <Xavion (dot) 0 (at) Gmail (dot) com>

Specifically, the following changes have been made:
* The repository is in 'magenta'
* The package name is in 'bold'
* The version is in 'green'
* The group is in 'blue'

Signed-off-by: Xavion <Xavion (dot) 0 (at) Gmail (dot) com>
---
 src/pacman/callback.c |  3 ++-
 src/pacman/package.c  | 55 ++++++++++++++++++++++++++-------------------------
 src/pacman/pacman.c   |  3 ++-
 src/pacman/util.c     | 21 ++++++++++++--------
 src/pacman/util.h     |  4 ++--
 5 files changed, 47 insertions(+), 39 deletions(-)

diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 1e1a4cd..3e4d7fa 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -427,6 +427,7 @@ void cb_question(alpm_question_t *question)
                                alpm_question_remove_pkgs_t *q = 
&question->remove_pkgs;
                                alpm_list_t *namelist = NULL, *i;
                                size_t count = 0;
+                               const colstr_t *colstr = &config->colstr;
                                for(i = q->packages; i; i = i->next) {
                                        namelist = alpm_list_add(namelist,
                                                        (char 
*)alpm_pkg_get_name(i->data));
@@ -436,7 +437,7 @@ void cb_question(alpm_question_t *question)
                                                        "The following package 
cannot be upgraded due to unresolvable dependencies:\n",
                                                        "The following packages 
cannot be upgraded due to unresolvable dependencies:\n",
                                                        count));
-                               list_display("     ", namelist, getcols());
+                               list_display("     ", namelist, 
colstr->nocolor, getcols());
                                printf("\n");
                                q->skip = noyes(_n(
                                                        "Do you want to skip 
the above package for this upgrade?",
diff --git a/src/pacman/package.c b/src/pacman/package.c
index 3ab9abc..92f6b37 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -148,14 +148,14 @@ static void make_aligned_titles(void)
  * @param deps a list with items of type alpm_depend_t
  */
 static void deplist_display(const char *title,
-               alpm_list_t *deps, unsigned short cols)
+               alpm_list_t *deps, const char *colour, unsigned short cols)
 {
        alpm_list_t *i, *text = NULL;
        for(i = deps; i; i = alpm_list_next(i)) {
                alpm_depend_t *dep = i->data;
                text = alpm_list_add(text, alpm_dep_compute_string(dep));
        }
-       list_display(title, text, cols);
+       list_display(title, text, colour, cols);
        FREELIST(text);
 }
 
@@ -198,6 +198,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
        char bdatestr[50] = "", idatestr[50] = "";
        const char *label, *reason;
        alpm_list_t *validation = NULL, *requiredby = NULL, *optionalfor = NULL;
+       const colstr_t *colstr = &config->colstr;
 
        /* make aligned titles once only */
        static int need_alignment = 1;
@@ -260,25 +261,25 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
        /* actual output */
        if(from == ALPM_PKG_FROM_SYNCDB) {
                string_display(titles[T_REPOSITORY],
-                               alpm_db_get_name(alpm_pkg_get_db(pkg)), cols);
+                               alpm_db_get_name(alpm_pkg_get_db(pkg)), 
colstr->repo, cols);
        }
-       string_display(titles[T_NAME], alpm_pkg_get_name(pkg), cols);
-       string_display(titles[T_VERSION], alpm_pkg_get_version(pkg), cols);
-       string_display(titles[T_DESCRIPTION], alpm_pkg_get_desc(pkg), cols);
-       string_display(titles[T_ARCHITECTURE], alpm_pkg_get_arch(pkg), cols);
-       string_display(titles[T_URL], alpm_pkg_get_url(pkg), cols);
-       list_display(titles[T_LICENSES], alpm_pkg_get_licenses(pkg), cols);
-       list_display(titles[T_GROUPS], alpm_pkg_get_groups(pkg), cols);
-       deplist_display(titles[T_PROVIDES], alpm_pkg_get_provides(pkg), cols);
-       deplist_display(titles[T_DEPENDS_ON], alpm_pkg_get_depends(pkg), cols);
+       string_display(titles[T_NAME], alpm_pkg_get_name(pkg), colstr->title, 
cols);
+       string_display(titles[T_VERSION], alpm_pkg_get_version(pkg), 
colstr->version, cols);
+       string_display(titles[T_DESCRIPTION], alpm_pkg_get_desc(pkg), 
colstr->nocolor, cols);
+       string_display(titles[T_ARCHITECTURE], alpm_pkg_get_arch(pkg), 
colstr->nocolor, cols);
+       string_display(titles[T_URL], alpm_pkg_get_url(pkg), colstr->nocolor, 
cols);
+       list_display(titles[T_LICENSES], alpm_pkg_get_licenses(pkg), 
colstr->nocolor, cols);
+       list_display(titles[T_GROUPS], alpm_pkg_get_groups(pkg), 
colstr->groups, cols);
+       deplist_display(titles[T_PROVIDES], alpm_pkg_get_provides(pkg), 
colstr->nocolor, cols);
+       deplist_display(titles[T_DEPENDS_ON], alpm_pkg_get_depends(pkg), 
colstr->nocolor, cols);
        optdeplist_display(pkg, cols);
 
        if(extra || from == ALPM_PKG_FROM_LOCALDB) {
-               list_display(titles[T_REQUIRED_BY], requiredby, cols);
-               list_display(titles[T_OPTIONAL_FOR], optionalfor, cols);
+               list_display(titles[T_REQUIRED_BY], requiredby, 
colstr->nocolor, cols);
+               list_display(titles[T_OPTIONAL_FOR], optionalfor, 
colstr->nocolor, cols);
        }
-       deplist_display(titles[T_CONFLICTS_WITH], alpm_pkg_get_conflicts(pkg), 
cols);
-       deplist_display(titles[T_REPLACES], alpm_pkg_get_replaces(pkg), cols);
+       deplist_display(titles[T_CONFLICTS_WITH], alpm_pkg_get_conflicts(pkg), 
colstr->nocolor, cols);
+       deplist_display(titles[T_REPLACES], alpm_pkg_get_replaces(pkg), 
colstr->nocolor, cols);
 
        size = humanize_size(alpm_pkg_get_size(pkg), '\0', 2, &label);
        if(from == ALPM_PKG_FROM_SYNCDB) {
@@ -296,15 +297,15 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
        printf("%s%s%s %.2f %s\n", config->colstr.title, 
titles[T_INSTALLED_SIZE],
                        config->colstr.nocolor, size, label);
 
-       string_display(titles[T_PACKAGER], alpm_pkg_get_packager(pkg), cols);
-       string_display(titles[T_BUILD_DATE], bdatestr, cols);
+       string_display(titles[T_PACKAGER], alpm_pkg_get_packager(pkg), 
colstr->nocolor, cols);
+       string_display(titles[T_BUILD_DATE], bdatestr, colstr->nocolor, cols);
        if(from == ALPM_PKG_FROM_LOCALDB) {
-               string_display(titles[T_INSTALL_DATE], idatestr, cols);
-               string_display(titles[T_INSTALL_REASON], reason, cols);
+               string_display(titles[T_INSTALL_DATE], idatestr, 
colstr->nocolor, cols);
+               string_display(titles[T_INSTALL_REASON], reason, 
colstr->nocolor, cols);
        }
        if(from == ALPM_PKG_FROM_FILE || from == ALPM_PKG_FROM_LOCALDB) {
                string_display(titles[T_INSTALL_SCRIPT],
-                               alpm_pkg_has_scriptlet(pkg) ? _("Yes") : 
_("No"), cols);
+                               alpm_pkg_has_scriptlet(pkg) ? _("Yes") : 
_("No"), colstr->nocolor, cols);
        }
 
        if(from == ALPM_PKG_FROM_SYNCDB && extra) {
@@ -321,25 +322,25 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
                        keys = alpm_list_add(keys, _("None"));
                }
 
-               string_display(titles[T_MD5_SUM], alpm_pkg_get_md5sum(pkg), 
cols);
-               string_display(titles[T_SHA_256_SUM], 
alpm_pkg_get_sha256sum(pkg), cols);
-               list_display(titles[T_SIGNATURES], keys, cols);
+               string_display(titles[T_MD5_SUM], alpm_pkg_get_md5sum(pkg), 
colstr->nocolor, cols);
+               string_display(titles[T_SHA_256_SUM], 
alpm_pkg_get_sha256sum(pkg), colstr->nocolor, cols);
+               list_display(titles[T_SIGNATURES], keys, colstr->nocolor, cols);
 
                if(base64_sig) {
                        FREELIST(keys);
                }
        } else {
-               list_display(titles[T_VALIDATED_BY], validation, cols);
+               list_display(titles[T_VALIDATED_BY], validation, 
colstr->nocolor, cols);
        }
 
        if(from == ALPM_PKG_FROM_FILE) {
                alpm_siglist_t siglist;
                int err = alpm_pkg_check_pgp_signature(pkg, &siglist);
                if(err && alpm_errno(config->handle) == ALPM_ERR_SIG_MISSING) {
-                       string_display(titles[T_SIGNATURES], _("None"), cols);
+                       string_display(titles[T_SIGNATURES], _("None"), 
colstr->nocolor, cols);
                } else if(err) {
                        string_display(titles[T_SIGNATURES],
-                                       
alpm_strerror(alpm_errno(config->handle)), cols);
+                                       
alpm_strerror(alpm_errno(config->handle)), colstr->err, cols);
                } else {
                        signature_display(titles[T_SIGNATURES], &siglist, cols);
                }
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index be52d1b..b2d2735 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -1221,6 +1221,7 @@ int main(int argc, char *argv[])
 
        if(config->verbose > 0) {
                alpm_list_t *j;
+               const colstr_t *colstr = &config->colstr;
                printf("Root      : %s\n", 
alpm_option_get_root(config->handle));
                printf("Conf File : %s\n", config->configfile);
                printf("DB Path   : %s\n", 
alpm_option_get_dbpath(config->handle));
@@ -1237,7 +1238,7 @@ int main(int argc, char *argv[])
                printf("Lock File : %s\n", 
alpm_option_get_lockfile(config->handle));
                printf("Log File  : %s\n", 
alpm_option_get_logfile(config->handle));
                printf("GPG Dir   : %s\n", 
alpm_option_get_gpgdir(config->handle));
-               list_display("Targets   :", pm_targets, 0);
+               list_display("Targets   :", pm_targets, colstr->nocolor, 0);
        }
 
        /* Log command line */
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 0862de0..b4e8dff 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -473,7 +473,7 @@ static void add_transaction_sizes_row(alpm_list_t **rows, 
char *label, off_t siz
        *rows = alpm_list_add(*rows, row);
 }
 
-void string_display(const char *title, const char *string, unsigned short cols)
+void string_display(const char *title, const char *string, const char *colour, 
unsigned short cols)
 {
        if(title) {
                printf("%s%s%s ", config->colstr.title, title, 
config->colstr.nocolor);
@@ -483,7 +483,10 @@ void string_display(const char *title, const char *string, 
unsigned short cols)
        } else {
                /* compute the length of title + a space */
                size_t len = string_length(title) + 1;
-               indentprint(string, (unsigned short)len, cols);
+               char *clrd_str = NULL;
+               pm_asprintf(&clrd_str, "%s%s", colour, string);
+               indentprint(clrd_str, (unsigned short)len, cols);
+               free(clrd_str);
        }
        printf("\n");
 }
@@ -654,7 +657,7 @@ cleanup:
 }
 
 void list_display(const char *title, const alpm_list_t *list,
-               unsigned short maxcols)
+               const char *colour, unsigned short maxcols)
 {
        const alpm_list_t *i;
        size_t len = 0;
@@ -669,7 +672,7 @@ void list_display(const char *title, const alpm_list_t 
*list,
        } else {
                size_t cols = len;
                const char *str = list->data;
-               fputs(str, stdout);
+               fprintf(stdout, "%s%s", colour, str);
                cols += string_length(str);
                for(i = alpm_list_next(list); i; i = alpm_list_next(i)) {
                        str = i->data;
@@ -687,7 +690,7 @@ void list_display(const char *title, const alpm_list_t 
*list,
                                printf("  ");
                                cols += 2;
                        }
-                       fputs(str, stdout);
+                       fprintf(stdout, "%s%s", colour, str);
                        cols += s;
                }
                putchar('\n');
@@ -873,6 +876,7 @@ static void _display_targets(alpm_list_t *targets, int 
verbose)
        off_t isize = 0, rsize = 0, dlsize = 0;
        unsigned short cols;
        alpm_list_t *i, *names = NULL, *header = NULL, *rows = NULL;
+       const colstr_t *colstr = &config->colstr;
 
        if(!targets) {
                return;
@@ -922,10 +926,10 @@ static void _display_targets(alpm_list_t *targets, int 
verbose)
                header = create_verbose_header(alpm_list_count(targets));
                if(table_display(header, rows, cols) != 0) {
                        /* fallback to list display if table wouldn't fit */
-                       list_display(str, names, cols);
+                       list_display(str, names, colstr->nocolor, cols);
                }
        } else {
-               list_display(str, names, cols);
+               list_display(str, names, colstr->nocolor, cols);
        }
        printf("\n");
 
@@ -1255,9 +1259,10 @@ static void display_repo_list(const char *dbname, 
alpm_list_t *list,
                unsigned short cols)
 {
        const char *prefix = "  ";
+       const colstr_t *colstr = &config->colstr;
 
        colon_printf(_("Repository %s\n"), dbname);
-       list_display(prefix, list, cols);
+       list_display(prefix, list, colstr->nocolor, cols);
 }
 
 void select_display(const alpm_list_t *pkglist)
diff --git a/src/pacman/util.h b/src/pacman/util.h
index f5e37c8..86aa204 100644
--- a/src/pacman/util.h
+++ b/src/pacman/util.h
@@ -55,10 +55,10 @@ void columns_cache_reset(void);
 int rmrf(const char *path);
 void indentprint(const char *str, unsigned short indent, unsigned short cols);
 char *strreplace(const char *str, const char *needle, const char *replace);
-void string_display(const char *title, const char *string, unsigned short 
cols);
+void string_display(const char *title, const char *string, const char *colour, 
unsigned short cols);
 double humanize_size(off_t bytes, const char target_unit, int precision,
                const char **label);
-void list_display(const char *title, const alpm_list_t *list,
+void list_display(const char *title, const alpm_list_t *list, const char 
*colour,
                unsigned short maxcols);
 void list_display_linebreak(const char *title, const alpm_list_t *list,
                unsigned short maxcols);
-- 
2.7.4

Reply via email to