[pacman-dev] [PATCH 07/11] add color to query.c
Daniel Wallace
daniel.wallace at gatech.edu
Sun Aug 5 05:46:43 EDT 2012
Signed-off-by: Daniel Wallace <daniel.wallace at gatech.edu>
---
src/pacman/query.c | 57 +++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 44 insertions(+), 13 deletions(-)
diff --git a/src/pacman/query.c b/src/pacman/query.c
index 9b1ea6f..1155b42 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -35,6 +35,7 @@
#include "package.h"
#include "conf.h"
#include "util.h"
+#include "color.h"
#define LOCAL_PREFIX "local/"
@@ -270,7 +271,13 @@ static int query_search(alpm_list_t *targets)
alpm_pkg_t *pkg = i->data;
if(!config->quiet) {
- printf(LOCAL_PREFIX "%s %s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
+ if (config->color) {
+ color_printf(COLOR_MAGENTA_ALL, LOCAL_PREFIX);
+ color_printf(COLOR_WHITE_ALL, "%s ", alpm_pkg_get_name(pkg));
+ color_printf(COLOR_GREEN_ALL, "%s",alpm_pkg_get_version(pkg));
+ } else {
+ printf(LOCAL_PREFIX "%s %s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
+ }
} else {
fputs(alpm_pkg_get_name(pkg), stdout);
}
@@ -279,16 +286,25 @@ static int query_search(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) {
+ color_printf(COLOR_BLUE_ALL, " (");
+ 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(')');
}
/* we need a newline and initial indent first */
@@ -319,7 +335,12 @@ static int query_group(alpm_list_t *targets)
for(p = grp->packages; p; p = alpm_list_next(p)) {
alpm_pkg_t *pkg = p->data;
- printf("%s %s\n", grp->name, alpm_pkg_get_name(pkg));
+ if (config->color) {
+ color_printf(COLOR_BLUE_ALL, "%s ", grp->name);
+ color_printf(COLOR_WHITE_ALL, "%s\n", alpm_pkg_get_name(pkg));
+ } else {
+ printf("%s %s\n", grp->name, alpm_pkg_get_name(pkg));
+ }
}
}
} else {
@@ -331,8 +352,13 @@ static int query_group(alpm_list_t *targets)
const alpm_list_t *p;
for(p = grp->packages; p; p = alpm_list_next(p)) {
if(!config->quiet) {
- printf("%s %s\n", grpname,
- alpm_pkg_get_name(p->data));
+ if (config->color) {
+ color_printf(COLOR_BLUE_ALL, "%s ", grpname);
+ color_printf(COLOR_WHITE_ALL, "%s", alpm_pkg_get_name(p->data));
+ } else {
+ printf("%s %s\n", grpname,
+ alpm_pkg_get_name(p->data));
+ }
} else {
printf("%s\n", alpm_pkg_get_name(p->data));
}
@@ -482,7 +508,12 @@ static int display(alpm_pkg_t *pkg)
if(!config->op_q_info && !config->op_q_list
&& !config->op_q_changelog && !config->op_q_check) {
if(!config->quiet) {
- printf("%s %s\n", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
+ if (config->color) {
+ color_printf(COLOR_WHITE_ALL, "%s ", alpm_pkg_get_name(pkg));
+ color_printf(COLOR_GREEN_ALL, "%s\n", alpm_pkg_get_version(pkg));
+ } else {
+ printf("%s %s\n", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
+ }
} else {
printf("%s\n", alpm_pkg_get_name(pkg));
}
--
1.7.11.4
More information about the pacman-dev
mailing list