Signed-off-by: Daniel Wallace <[email protected]>
---
 src/pacman/color.c   |  46 ++++++++++++-
 src/pacman/color.h   |   8 ++-
 src/pacman/package.c | 190 ++++++++++++++++++++++++++++++++++++---------------
 3 files changed, 188 insertions(+), 56 deletions(-)

diff --git a/src/pacman/color.c b/src/pacman/color.c
index d1b2d5e..235d47b 100644
--- a/src/pacman/color.c
+++ b/src/pacman/color.c
@@ -419,6 +419,33 @@ int color_pm_vfprintf(FILE *stream, alpm_loglevel_t level, 
const char *format, v
        return ret;
 }
 
+
+/** Turn a depends list into a text list.
+ * @param deps a list with items of type alpm_depend_t
+ */
+void color_deplist_display(const colordata_t *colors_title, const char *title,
+               alpm_list_t *deps, 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));
+       }
+       color_list_display(colors_title, title, text, cols);
+       FREELIST(text);
+}
+
+void color_optdeplist_display(const colordata_t *color_title, const char 
*title,
+               alpm_list_t *optdeps, unsigned short cols)
+{
+       alpm_list_t *i, *text = NULL;
+       for(i = optdeps; i; i = alpm_list_next(i)) {
+               alpm_depend_t *optdep = i->data;
+               text = alpm_list_add(text, alpm_dep_compute_string(optdep));
+       }
+       color_list_display_linebreak(color_title, title, text, cols);
+       FREELIST(text);
+}
 /* pacman-color */
 
 int _set_color_sequence(const char* name, char* dest)
@@ -653,7 +680,24 @@ int color_printf(const colordata_t* colors, const char* 
format, ...)
        return(ret);
 }
 
-void color_string_display(const colordata_t* colors_title, const char* title, 
const colordata_t* colors_string, const char* string)
+
+void color_string_display(const colordata_t *colors_title, const char *title, 
const char *string,
+               unsigned short cols)
+{
+       if(title) {
+               color_printf(colors_title, "%s ", title);
+       }
+       if(string == NULL || string[0] == '\0') {
+               printf(_("None"));
+       } else {
+               /* compute the length of title + a space */
+               size_t len = string_length(title) + 1;
+               indentprint(string, len, cols);
+       }
+       printf("\n");
+}
+void colored_string_display(const colordata_t* colors_title, const char* 
title, 
+               const colordata_t* colors_string, const char* string)
 {
        if(title) {
                color_printf(colors_title, "%s ", title);
diff --git a/src/pacman/color.h b/src/pacman/color.h
index c833e2e..057f64b 100644
--- a/src/pacman/color.h
+++ b/src/pacman/color.h
@@ -56,6 +56,10 @@ int color_yesno(const colordata_t *colors, char *fmt, ...);
 int color_noyes(const colordata_t *colors, char *fmt, ...);
 int color_pm_vasprintf(char **string, alpm_loglevel_t level, const char 
*format, va_list args);
 int color_pm_vfprintf(FILE *stream, alpm_loglevel_t level, const char *format, 
va_list args);
+void color_deplist_display(const colordata_t *colors_title, const char *title,
+               alpm_list_t *deps, unsigned short cols);
+void color_optdeplist_display(const colordata_t *color_title, const char 
*title,
+               alpm_list_t *optdeps, unsigned short cols);
 int _set_color_sequence(const char* name, char* dest);
 void _insert_color(FILE* stream, color_t color);
 int parsecolorconfig();
@@ -64,7 +68,9 @@ int color_printf(const colordata_t* colors, const char* 
format, ...) __attribute
 
 int color_vfprintf(FILE* stream, const colordata_t* colors, const char* 
format, va_list args) __attribute__((format(printf,3,0)));
 
-void color_string_display(const colordata_t* colors_title, const char* title, 
const colordata_t* colors_string, const char* string);
+void color_string_display(const colordata_t *colors_title, const char *title, 
const char *string,
+               unsigned short cols);
+void colored_string_display(const colordata_t* colors_title, const char* 
title, const colordata_t* colors_string, const char* string);
 
 #endif
 /* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/package.c b/src/pacman/package.c
index fe04d40..01489b2 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -32,6 +32,7 @@
 /* pacman */
 #include "package.h"
 #include "util.h"
+#include "color.h"
 #include "conf.h"
 
 #define CLBUF_SIZE 4096
@@ -136,69 +137,142 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
 
        /* actual output */
        if(from == ALPM_PKG_FROM_SYNCDB) {
-               string_display(_("Repository     :"),
-                               alpm_db_get_name(alpm_pkg_get_db(pkg)), cols);
-       }
-       string_display(_("Name           :"), alpm_pkg_get_name(pkg), cols);
-       string_display(_("Version        :"), alpm_pkg_get_version(pkg), cols);
-       string_display(_("URL            :"), alpm_pkg_get_url(pkg), cols);
-       list_display(_("Licenses       :"), alpm_pkg_get_licenses(pkg), cols);
-       list_display(_("Groups         :"), alpm_pkg_get_groups(pkg), cols);
-       deplist_display(_("Provides       :"), alpm_pkg_get_provides(pkg), 
cols);
-       deplist_display(_("Depends On     :"), alpm_pkg_get_depends(pkg), cols);
-       optdeplist_display(_("Optional Deps  :"), alpm_pkg_get_optdepends(pkg), 
cols);
-       if(extra || from == ALPM_PKG_FROM_LOCALDB) {
-               list_display(_("Required By    :"), requiredby, cols);
+               if (config->color) {
+                       colored_string_display(COLOR_WHITE_ALL,
+                                       _("Repository     :"),
+                                       COLOR_MAGENTA_ALL,
+                                       alpm_db_get_name(alpm_pkg_get_db(pkg)));
+               } else {
+                       string_display(_("Repository     :"),
+                                       alpm_db_get_name(alpm_pkg_get_db(pkg)), 
cols);
+               }
        }
-       deplist_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg), 
cols);
-       deplist_display(_("Replaces       :"), alpm_pkg_get_replaces(pkg), 
cols);
+       if (config->color) {
+               colored_string_display(COLOR_WHITE_ALL, _("Name           :"),
+                               COLOR_WHITE_ALL, alpm_pkg_get_name(pkg));
+               colored_string_display(COLOR_WHITE_ALL, _("Version        :"),
+                               COLOR_GREEN_ALL, alpm_pkg_get_version(pkg));
+               colored_string_display(COLOR_WHITE_ALL, _("URL            :"),
+                               COLOR_CYAN_ALL, alpm_pkg_get_url(pkg));
+               color_list_display(COLOR_WHITE_ALL, _("Licenses       :"), 
alpm_pkg_get_licenses(pkg), cols);
+               color_list_display(COLOR_WHITE_ALL, _("Groups         :"), 
alpm_pkg_get_groups(pkg), cols);
+               color_deplist_display(COLOR_WHITE_ALL, _("Provides       :"), 
alpm_pkg_get_provides(pkg), cols);
+               color_deplist_display(COLOR_WHITE_ALL, _("Depends On     :"), 
alpm_pkg_get_depends(pkg), cols);
+               color_optdeplist_display(COLOR_WHITE_ALL, _("Optional Deps  
:"), alpm_pkg_get_optdepends(pkg), cols);
+               if(extra || from == ALPM_PKG_FROM_LOCALDB) {
+                       color_list_display(COLOR_WHITE_ALL, _("Required By    
:"), requiredby, cols);
+               }
+               color_deplist_display(COLOR_WHITE_ALL, _("Conflicts With :"), 
alpm_pkg_get_conflicts(pkg), cols);
+               color_deplist_display(COLOR_WHITE_ALL, _("Replaces       :"), 
alpm_pkg_get_replaces(pkg), cols);
+
+               size = humanize_size(alpm_pkg_get_size(pkg), 'K', 2, &label);
+               if(from == ALPM_PKG_FROM_SYNCDB) {
+                       color_printf(COLOR_WHITE_COLON, _("Download Size  : 
%6.2f %s\n"), size, label);
+               } else if(from == ALPM_PKG_FROM_FILE) {
+                       color_printf(COLOR_WHITE_COLON, _("Compressed Size: 
%6.2f %s\n"), size, label);
+               }
 
-       size = humanize_size(alpm_pkg_get_size(pkg), 'K', 2, &label);
-       if(from == ALPM_PKG_FROM_SYNCDB) {
-               printf(_("Download Size  : %6.2f %s\n"), size, label);
-       } else if(from == ALPM_PKG_FROM_FILE) {
-               printf(_("Compressed Size: %6.2f %s\n"), size, label);
-       }
+               size = humanize_size(alpm_pkg_get_isize(pkg), 'K', 2, &label);
+               color_printf(COLOR_WHITE_COLON, _("Installed Size : %6.2f 
%s\n"), size, label);
 
-       size = humanize_size(alpm_pkg_get_isize(pkg), 'K', 2, &label);
-       printf(_("Installed Size : %6.2f %s\n"), size, label);
+               color_string_display(COLOR_WHITE_ALL, _("Packager       :"), 
alpm_pkg_get_packager(pkg), cols);
+               color_string_display(COLOR_WHITE_ALL, _("Architecture   :"), 
alpm_pkg_get_arch(pkg), cols);
+               color_string_display(COLOR_WHITE_ALL, _("Build Date     :"), 
bdatestr, cols);
+               if(from == ALPM_PKG_FROM_LOCALDB) {
+                       color_string_display(COLOR_WHITE_ALL, _("Install Date   
:"), idatestr, cols);
+                       color_string_display(COLOR_WHITE_ALL, _("Install Reason 
:"), reason, cols);
+               }
+               if(from == ALPM_PKG_FROM_FILE || from == ALPM_PKG_FROM_LOCALDB) 
{
+                       color_string_display(COLOR_WHITE_ALL, _("Install Script 
:"),
+                                       alpm_pkg_has_scriptlet(pkg) ?  _("Yes") 
: _("No"), cols);
+               }
 
-       string_display(_("Packager       :"), alpm_pkg_get_packager(pkg), cols);
-       string_display(_("Architecture   :"), alpm_pkg_get_arch(pkg), cols);
-       string_display(_("Build Date     :"), bdatestr, cols);
-       if(from == ALPM_PKG_FROM_LOCALDB) {
-               string_display(_("Install Date   :"), idatestr, cols);
-               string_display(_("Install Reason :"), reason, cols);
-       }
-       if(from == ALPM_PKG_FROM_FILE || from == ALPM_PKG_FROM_LOCALDB) {
-               string_display(_("Install Script :"),
-                               alpm_pkg_has_scriptlet(pkg) ?  _("Yes") : 
_("No"), cols);
-       }
+               if(from == ALPM_PKG_FROM_SYNCDB && extra) {
+                       color_string_display(COLOR_WHITE_ALL, _("MD5 Sum        
:"), alpm_pkg_get_md5sum(pkg), cols);
+                       color_string_display(COLOR_WHITE_ALL, _("SHA256 Sum     
:"), alpm_pkg_get_sha256sum(pkg), cols);
+                       color_string_display(COLOR_WHITE_ALL, _("Signatures     
:"),
+                                       alpm_pkg_get_base64_sig(pkg) ? _("Yes") 
: _("None"), cols);
+               } else {
+                       color_list_display(COLOR_WHITE_ALL, _("Validated By   
:"), validation, 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) {
+                               color_string_display(COLOR_WHITE_ALL, 
_("Signatures     :"), _("None"), cols);
+                       } else if(err) {
+                               color_string_display(COLOR_WHITE_ALL, 
_("Signatures     :"),
+                                               
alpm_strerror(alpm_errno(config->handle)), cols);
+                       } else {
+                               signature_display(_("Signatures     :"), 
&siglist, cols);
+                       }
+                       alpm_siglist_cleanup(&siglist);
+               }
 
-       if(from == ALPM_PKG_FROM_SYNCDB && extra) {
-               string_display(_("MD5 Sum        :"), alpm_pkg_get_md5sum(pkg), 
cols);
-               string_display(_("SHA256 Sum     :"), 
alpm_pkg_get_sha256sum(pkg), cols);
-               string_display(_("Signatures     :"),
-                               alpm_pkg_get_base64_sig(pkg) ? _("Yes") : 
_("None"), cols);
+               color_string_display(COLOR_WHITE_ALL, _("Description    :"), 
alpm_pkg_get_desc(pkg), cols);
        } else {
-               list_display(_("Validated By   :"), validation, cols);
-       }
+               string_display(_("Name           :"), alpm_pkg_get_name(pkg), 
cols);
+               string_display(_("Version        :"), 
alpm_pkg_get_version(pkg), cols);
+               string_display(_("URL            :"), alpm_pkg_get_url(pkg), 
cols);
+               list_display(_("Licenses       :"), alpm_pkg_get_licenses(pkg), 
cols);
+               list_display(_("Groups         :"), alpm_pkg_get_groups(pkg), 
cols);
+               deplist_display(_("Provides       :"), 
alpm_pkg_get_provides(pkg), cols);
+               deplist_display(_("Depends On     :"), 
alpm_pkg_get_depends(pkg), cols);
+               optdeplist_display(_("Optional Deps  :"), 
alpm_pkg_get_optdepends(pkg), cols);
+               if(extra || from == ALPM_PKG_FROM_LOCALDB) {
+                       list_display(_("Required By    :"), requiredby, cols);
+               }
+               deplist_display(_("Conflicts With :"), 
alpm_pkg_get_conflicts(pkg), cols);
+               deplist_display(_("Replaces       :"), 
alpm_pkg_get_replaces(pkg), cols);
+
+               size = humanize_size(alpm_pkg_get_size(pkg), 'K', 2, &label);
+               if(from == ALPM_PKG_FROM_SYNCDB) {
+                       printf(_("Download Size  : %6.2f %s\n"), size, label);
+               } else if(from == ALPM_PKG_FROM_FILE) {
+                       printf(_("Compressed Size: %6.2f %s\n"), size, label);
+               }
+
+               size = humanize_size(alpm_pkg_get_isize(pkg), 'K', 2, &label);
+               printf(_("Installed Size : %6.2f %s\n"), size, label);
+
+               string_display(_("Packager       :"), 
alpm_pkg_get_packager(pkg), cols);
+               string_display(_("Architecture   :"), alpm_pkg_get_arch(pkg), 
cols);
+               string_display(_("Build Date     :"), bdatestr, cols);
+               if(from == ALPM_PKG_FROM_LOCALDB) {
+                       string_display(_("Install Date   :"), idatestr, cols);
+                       string_display(_("Install Reason :"), reason, cols);
+               }
+               if(from == ALPM_PKG_FROM_FILE || from == ALPM_PKG_FROM_LOCALDB) 
{
+                       string_display(_("Install Script :"),
+                                       alpm_pkg_has_scriptlet(pkg) ?  _("Yes") 
: _("No"), 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(_("Signatures     :"), _("None"), cols);
-               } else if(err) {
+               if(from == ALPM_PKG_FROM_SYNCDB && extra) {
+                       string_display(_("MD5 Sum        :"), 
alpm_pkg_get_md5sum(pkg), cols);
+                       string_display(_("SHA256 Sum     :"), 
alpm_pkg_get_sha256sum(pkg), cols);
                        string_display(_("Signatures     :"),
-                                       
alpm_strerror(alpm_errno(config->handle)), cols);
+                                       alpm_pkg_get_base64_sig(pkg) ? _("Yes") 
: _("None"), cols);
                } else {
-                       signature_display(_("Signatures     :"), &siglist, 
cols);
+                       list_display(_("Validated By   :"), validation, 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(_("Signatures     :"), 
_("None"), cols);
+                       } else if(err) {
+                               string_display(_("Signatures     :"),
+                                               
alpm_strerror(alpm_errno(config->handle)), cols);
+                       } else {
+                               signature_display(_("Signatures     :"), 
&siglist, cols);
+                       }
+                       alpm_siglist_cleanup(&siglist);
                }
-               alpm_siglist_cleanup(&siglist);
-       }
 
-       string_display(_("Description    :"), alpm_pkg_get_desc(pkg), cols);
+               string_display(_("Description    :"), alpm_pkg_get_desc(pkg), 
cols);
+       }
 
        /* Print additional package info if info flag passed more than once */
        if(from == ALPM_PKG_FROM_LOCALDB && extra) {
@@ -258,7 +332,11 @@ void dump_pkg_backups(alpm_pkg_t *pkg)
 {
        alpm_list_t *i;
        const char *root = alpm_option_get_root(config->handle);
-       printf(_("Backup Files:\n"));
+       if (config->color) {
+               color_printf(COLOR_WHITE_ALL, _("Backup Files:\n"));
+       } else {
+               printf(_("Backup Files:\n"));
+       }
        if(alpm_pkg_get_backup(pkg)) {
                /* package has backup files, so print them */
                for(i = alpm_pkg_get_backup(pkg); i; i = alpm_list_next(i)) {
@@ -294,7 +372,11 @@ void dump_pkg_files(alpm_pkg_t *pkg, int quiet)
                 * Quiet  : '<root><filepath>\n'
                 */
                if(!quiet) {
-                       fputs(pkgname, stdout);
+                       if (config->color) {
+                               color_printf(COLOR_WHITE_ALL, "%s", pkgname);
+                       } else {
+                               fputs(pkgname, stdout);
+                       }
                        putchar(' ');
                }
                fputs(root, stdout);
-- 
1.7.11.4


Reply via email to