FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor


 
 
LinkBack Thread Tools
 
Old 08-05-2012, 09:46 AM
Daniel Wallace
 
Default add color to query.c

Signed-off-by: Daniel Wallace <daniel.wallace@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
", grp->name, alpm_pkg_get_name(pkg));
+ if (config->color) {
+ color_printf(COLOR_BLUE_ALL, "%s ", grp->name);
+ color_printf(COLOR_WHITE_ALL, "%s
", alpm_pkg_get_name(pkg));
+ } else {
+ printf("%s %s
", 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
", 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
", grpname,
+ alpm_pkg_get_name(p->data));
+ }
} else {
printf("%s
", 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
", 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
", alpm_pkg_get_version(pkg));
+ } else {
+ printf("%s %s
", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
+ }
} else {
printf("%s
", alpm_pkg_get_name(pkg));
}
--
1.7.11.4
 

Thread Tools




All times are GMT. The time now is 06:54 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org