Signed-off-by: Daniel Wallace <[email protected]>
---
 src/pacman/sync.c | 151 ++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 119 insertions(+), 32 deletions(-)

diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 532a667..2174a5d 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -36,6 +36,7 @@
 #include "util.h"
 #include "package.h"
 #include "conf.h"
+#include "color.h"
 
 static int unlink_verbose(const char *pathname, int ignore_missing)
 {
@@ -144,7 +145,11 @@ static int sync_cleandb_all(void)
        int ret = 0;
 
        dbpath = alpm_option_get_dbpath(config->handle);
-       printf(_("Database directory: %s\n"), dbpath);
+       if (config->color) {
+               color_printf(COLOR_WHITE_COLON, _("Database directory: %s\n"), 
dbpath);
+       } else {
+               printf(_("Database directory: %s\n"), dbpath);
+       }
        if(!yesno(_("Do you want to remove unused repositories?"))) {
                return 0;
        }
@@ -178,7 +183,11 @@ static int sync_cleancache(int level)
        }
 
        if(level == 1) {
-               printf(_("Packages to keep:\n"));
+               if (config->color) {
+                       color_printf(COLOR_WHITE_COLON, _("Packages to 
keep:\n"));
+               } else {
+                       printf(_("Packages to keep:\n"));
+               }
                if(config->cleanmethod & PM_CLEAN_KEEPINST) {
                        printf(_("  All locally installed packages\n"));
                }
@@ -193,7 +202,11 @@ static int sync_cleancache(int level)
                DIR *dir;
                struct dirent *ent;
 
-               printf(_("Cache directory: %s\n"), (const char *)i->data);
+               if (config->color) {
+                       color_printf(COLOR_WHITE_COLON, _("Cache directory: 
%s\n"), (const char *)i->data);
+               } else {
+                       printf(_("Cache directory: %s\n"), (const char 
*)i->data);
+               }
 
                if(level == 1) {
                        if(!yesno(_("Do you want to remove all other packages 
from cache?"))) {
@@ -360,9 +373,17 @@ static void print_installed(alpm_db_t *db_local, 
alpm_pkg_t *pkg)
        if(lpkg) {
                const char *lpkgver = alpm_pkg_get_version(lpkg);
                if(strcmp(lpkgver,pkgver) == 0) {
-                       printf(" [%s]", _("installed"));
+                       if (config->color) {
+                               color_printf(COLOR_CYAN_ALL, " [%s]", 
_("installed"));
+                       } else {
+                               printf(" [%s]", _("installed"));
+                       }
                } else {
-                       printf(" [%s: %s]", _("installed"), lpkgver);
+                       if (config->color) {
+                               color_printf(COLOR_CYAN_ALL, " [%s: %s]", 
_("installed"), lpkgver);
+                       } else {
+                               printf(" [%s: %s]", _("installed"), lpkgver);
+                       }
                }
        }
 }
@@ -397,8 +418,14 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t 
*targets)
                        alpm_pkg_t *pkg = j->data;
 
                        if(!config->quiet) {
-                               printf("%s/%s %s", alpm_db_get_name(db), 
alpm_pkg_get_name(pkg),
-                                                        
alpm_pkg_get_version(pkg));
+                               if (config->color) {
+                                       color_printf(COLOR_MAGENTA_ALL, "%s/", 
alpm_db_get_name(db));
+                                       color_printf(COLOR_WHITE_ALL, "%s ", 
alpm_pkg_get_name(pkg));
+                                       color_printf(COLOR_GREEN_ALL, "%s", 
alpm_pkg_get_version(pkg));
+                               } else {
+                                       printf("%s/%s %s", 
alpm_db_get_name(db), alpm_pkg_get_name(pkg),
+                                                                
alpm_pkg_get_version(pkg));
+                               }
                        } else {
                                fputs(alpm_pkg_get_name(pkg), stdout);
                        }
@@ -406,16 +433,25 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t 
*targets)
                        if(!config->quiet) {
                                if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
                                        alpm_list_t *k;
-                                       fputs(" (", stdout);
-                                       for(k = grp; k; k = alpm_list_next(k)) {
-                                               const char *group = k->data;
-                                               fputs(group, stdout);
-                                               if(alpm_list_next(k)) {
-                                                       /* only print a spacer 
if there are more groups */
-                                                       putchar(' ');
+                                       if (config->color) {
+                                               fputs(" (", stdout);
+                                               for(k = grp; k; k = 
alpm_list_next(k)) {
+                                                       const char *group = 
k->data;
+                                                       
color_printf(COLOR_BLUE_ALL, "%s%s", group,
+                                                                       
(alpm_list_next(k) ? " " : ")"));
                                                }
+                                       } else {
+                                               fputs(" (", stdout);
+                                               for(k = grp; k; k = 
alpm_list_next(k)) {
+                                                       const char *group = 
k->data;
+                                                       fputs(group, stdout);
+                                                       if(alpm_list_next(k)) {
+                                                               /* only print a 
spacer if there are more groups */
+                                                               putchar(' ');
+                                                       }
+                                               }
+                                               putchar(')');
                                        }
-                                       putchar(')');
                                }
 
                                print_installed(db_local, pkg);
@@ -450,8 +486,13 @@ static int sync_group(int level, alpm_list_t *syncs, 
alpm_list_t *targets)
                                        /* get names of packages in group */
                                        for(k = grp->packages; k; k = 
alpm_list_next(k)) {
                                                if(!config->quiet) {
-                                                       printf("%s %s\n", 
grpname,
-                                                                       
alpm_pkg_get_name(k->data));
+                                                       if (config->color) {
+                                                               
color_printf(COLOR_BLUE_ALL, "%s ", grpname);
+                                                               
color_printf(COLOR_WHITE_ALL, "%s", alpm_pkg_get_name(k->data));
+                                                       } else {
+                                                               printf("%s 
%s\n", grpname,
+                                                                               
alpm_pkg_get_name(k->data));
+                                                       }
                                                } else {
                                                        printf("%s\n", 
alpm_pkg_get_name(k->data));
                                                }
@@ -591,8 +632,14 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t 
*targets)
                        alpm_pkg_t *pkg = j->data;
 
                        if(!config->quiet) {
-                               printf("%s %s %s", alpm_db_get_name(db), 
alpm_pkg_get_name(pkg),
-                                               alpm_pkg_get_version(pkg));
+                               if (config->color) {
+                                       color_printf(COLOR_MAGENTA_ALL, "%s ", 
alpm_db_get_name(db));
+                                       color_printf(COLOR_WHITE_ALL, "%s ", 
alpm_pkg_get_name(pkg));
+                                       color_printf(COLOR_GREEN_ALL, "%s ", 
alpm_pkg_get_version(pkg));
+                               } else {
+                                       printf("%s %s %s", 
alpm_db_get_name(db), alpm_pkg_get_name(pkg),
+                                                       
alpm_pkg_get_version(pkg));
+                               }
                                print_installed(db_local, pkg);
                                printf("\n");
                        } else {
@@ -661,8 +708,13 @@ static int process_group(alpm_list_t *dbs, const char 
*group, int error)
        }
 
        if(config->print == 0) {
-               printf(_(":: There are %d members in group %s:\n"), count,
-                               group);
+               if (config->color) {
+                       color_printf(COLOR_DOUBLECOLON, _(":: There are %d 
members in group %s:\n"), count,
+                                       group);
+               } else {
+                       printf(_(":: There are %d members in group %s:\n"), 
count,
+                                       group);
+               }
                select_display(pkgs);
                char *array = malloc(count);
                if(!array) {
@@ -786,7 +838,11 @@ static int sync_trans(alpm_list_t *targets)
        }
 
        if(config->op_s_upgrade) {
-               printf(_(":: Starting full system upgrade...\n"));
+               if (config->color) {
+                       color_printf(COLOR_DOUBLECOLON, _(":: Starting full 
system upgrade...\n"));
+               } else {
+                       printf(_(":: Starting full system upgrade...\n"));
+               }
                alpm_logaction(config->handle, "starting full system 
upgrade\n");
                if(alpm_sync_sysupgrade(config->handle, config->op_s_upgrade >= 
2) == -1) {
                        pm_printf(ALPM_LOG_ERROR, "%s\n", 
alpm_strerror(alpm_errno(config->handle)));
@@ -812,14 +868,22 @@ int sync_prepare_execute(void)
                        case ALPM_ERR_PKG_INVALID_ARCH:
                                for(i = data; i; i = alpm_list_next(i)) {
                                        const char *pkg = i->data;
-                                       printf(_(":: package %s does not have a 
valid architecture\n"), pkg);
+                                       if (config->color) {
+                                               color_printf(COLOR_DOUBLECOLON, 
_(":: package %s does not have a valid architecture\n"), pkg);
+                                       } else {
+                                               printf(_(":: package %s does 
not have a valid architecture\n"), pkg);
+                                       }
                                }
                                break;
                        case ALPM_ERR_UNSATISFIED_DEPS:
                                for(i = data; i; i = alpm_list_next(i)) {
                                        alpm_depmissing_t *miss = i->data;
                                        char *depstring = 
alpm_dep_compute_string(miss->depend);
-                                       printf(_(":: %s: requires %s\n"), 
miss->target, depstring);
+                                       if (config->color) {
+                                               color_printf(COLOR_DOUBLECOLON, 
_(":: %s: requires %s\n"), miss->target, depstring);
+                                       } else {
+                                               printf(_(":: %s: requires 
%s\n"), miss->target, depstring);
+                                       }
                                        free(depstring);
                                }
                                break;
@@ -828,12 +892,22 @@ int sync_prepare_execute(void)
                                        alpm_conflict_t *conflict = i->data;
                                        /* only print reason if it contains new 
information */
                                        if(conflict->reason->mod == 
ALPM_DEP_MOD_ANY) {
-                                               printf(_(":: %s and %s are in 
conflict\n"),
-                                                               
conflict->package1, conflict->package2);
+                                               if (config->color) {
+                                                       
color_printf(COLOR_DOUBLECOLON, _(":: %s and %s are in conflict\n"),
+                                                                       
conflict->package1, conflict->package2);
+                                               } else {
+                                                       printf(_(":: %s and %s 
are in conflict\n"),
+                                                                       
conflict->package1, conflict->package2);
+                                               }
                                        } else {
                                                char *reason = 
alpm_dep_compute_string(conflict->reason);
-                                               printf(_(":: %s and %s are in 
conflict (%s)\n"),
-                                                               
conflict->package1, conflict->package2, reason);
+                                               if (config->color) {
+                                                       
color_printf(COLOR_DOUBLECOLON, _(":: %s and %s are in conflict (%s)\n"),
+                                                                       
conflict->package1, conflict->package2, reason);
+                                               } else {
+                                                       printf(_(":: %s and %s 
are in conflict (%s)\n"),
+                                                                       
conflict->package1, conflict->package2, reason);
+                                               }
                                                free(reason);
                                        }
                                }
@@ -887,8 +961,13 @@ int sync_prepare_execute(void)
                                                                        
conflict->file, conflict->target, conflict->ctarget);
                                                        break;
                                                case 
ALPM_FILECONFLICT_FILESYSTEM:
-                                                       printf(_("%s: %s exists 
in filesystem\n"),
-                                                                       
conflict->target, conflict->file);
+                                                       if (config->color) {
+                                                               
color_printf(COLOR_WHITE_COLON, _("%s: %s exists in filesystem\n"),
+                                                                               
conflict->target, conflict->file);
+                                                       } else {
+                                                               printf(_("%s: 
%s exists in filesystem\n"),
+                                                                               
conflict->target, conflict->file);
+                                                       }
                                                        break;
                                        }
                                }
@@ -906,7 +985,11 @@ int sync_prepare_execute(void)
                                break;
                }
                /* TODO: stderr? */
-               printf(_("Errors occurred, no packages were upgraded.\n"));
+               if (config->color) {
+                       color_printf(COLOR_RED_ALL, _("Errors occurred, no 
packages were upgraded.\n"));
+               } else {
+                       printf(_("Errors occurred, no packages were 
upgraded.\n"));
+               }
                retval = 1;
                goto cleanup;
        }
@@ -953,7 +1036,11 @@ int pacman_sync(alpm_list_t *targets)
 
        if(config->op_s_sync) {
                /* grab a fresh package list */
-               printf(_(":: Synchronizing package databases...\n"));
+               if (config->color) {
+                       color_printf(COLOR_DOUBLECOLON, _(":: Synchronizing 
package databases...\n"));
+               } else {
+                       printf(_(":: Synchronizing package databases...\n"));
+               }
                alpm_logaction(config->handle, "synchronizing package lists\n");
                if(!sync_synctree(config->op_s_sync, sync_dbs)) {
                        return 1;
-- 
1.7.11.4


Reply via email to