[pacman-dev] [PATCH 06/11] Add color to pacman.c

Daniel Wallace daniel.wallace at gatech.edu
Sun Aug 5 05:46:42 EDT 2012


including special color_version
Signed-off-by: Daniel Wallace <daniel.wallace at gatech.edu>
---
 src/pacman/color.c  | 24 +++++++++++++++++
 src/pacman/color.h  |  1 +
 src/pacman/pacman.c | 75 ++++++++++++++++++++++++++++++++++++-----------------
 3 files changed, 76 insertions(+), 24 deletions(-)

diff --git a/src/pacman/color.c b/src/pacman/color.c
index 235d47b..588852a 100644
--- a/src/pacman/color.c
+++ b/src/pacman/color.c
@@ -446,6 +446,30 @@ void color_optdeplist_display(const colordata_t *color_title, const char *title,
 	color_list_display_linebreak(color_title, title, text, cols);
 	FREELIST(text);
 }
+
+void color_version(char *package_version)
+{
+	color_printf(COLOR_YELLOW_ALL, " .--. ");
+	printf("        ");
+	color_printf(COLOR_RED_ALL, " .---. ");
+	printf("  Pacman-color v%s - libalpm v%s\n", package_version, alpm_version());
+	color_printf(COLOR_YELLOW_ALL, "/ _.-'");
+	color_printf(COLOR_WHITE_ALL, " .-.  .-");
+	color_printf(COLOR_RED_ALL, "|O O  |");
+	printf("  Copyright (C) 2006-2012 Pacman Development Team\n");
+	color_printf(COLOR_YELLOW_ALL, "\\  '-.");
+	color_printf(COLOR_WHITE_ALL, " '-'  '-");
+	color_printf(COLOR_RED_ALL, "|~~~  |");
+	printf("  Copyright (C) 2002-2006 Judd Vinet\n");
+	color_printf(COLOR_YELLOW_ALL, " '--' ");
+	printf("        ");
+	color_printf(COLOR_RED_ALL, "|.-.-.|");
+	printf("\n");
+	printf(_("                       This program may be freely redistributed under\n"
+	         "                       the terms of the GNU General Public License.\n"));
+	printf("\n");
+}
+
 /* pacman-color */
 
 int _set_color_sequence(const char* name, char* dest)
diff --git a/src/pacman/color.h b/src/pacman/color.h
index 057f64b..90f377a 100644
--- a/src/pacman/color.h
+++ b/src/pacman/color.h
@@ -60,6 +60,7 @@ 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);
+void color_version(char *package_version);
 int _set_color_sequence(const char* name, char* dest);
 void _insert_color(FILE* stream, color_t color);
 int parsecolorconfig();
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 0708dbf..421c4a3 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -216,14 +216,18 @@ static void usage(int op, const char * const myname)
  */
 static void version(void)
 {
-	printf("\n");
-	printf(" .--.                  Pacman v%s - libalpm v%s\n", PACKAGE_VERSION, alpm_version());
-	printf("/ _.-' .-.  .-.  .-.   Copyright (C) 2006-2012 Pacman Development Team\n");
-	printf("\\  '-. '-'  '-'  '-'   Copyright (C) 2002-2006 Judd Vinet\n");
-	printf(" '--'\n");
-	printf(_("                       This program may be freely redistributed under\n"
-	         "                       the terms of the GNU General Public License.\n"));
-	printf("\n");
+	if (config->color) {
+		color_version(PACKAGE_VERSION);
+	} else {
+		printf("\n");
+		printf(" .--.                  Pacman v%s - libalpm v%s\n", PACKAGE_VERSION, alpm_version());
+		printf("/ _.-' .-.  .-.  .-.   Copyright (C) 2006-2012 Pacman Development Team\n");
+		printf("\\  '-. '-'  '-'  '-'   Copyright (C) 2002-2006 Judd Vinet\n");
+		printf(" '--'\n");
+		printf(_("                       This program may be freely redistributed under\n"
+				 "                       the terms of the GNU General Public License.\n"));
+		printf("\n");
+	}
 }
 
 /** Sets up gettext localization. Safe to call multiple times.
@@ -658,10 +662,6 @@ static int parseargs(int argc, char *argv[])
 		usage(config->op, mbasename(argv[0]));
 		return 2;
 	}
-	if(config->version) {
-		version();
-		return 2;
-	}
 
 	/* parse all other options */
 	optind = 1;
@@ -873,6 +873,11 @@ int main(int argc, char *argv[])
 	if (config->color) {
 		parsecolorconfig();
 	}
+
+	if(config->version) {
+		version();
+		return 2;
+	}
 	/* noask is meant to be non-interactive */
 	if(config->noask) {
 		config->noconfirm = 1;
@@ -894,21 +899,43 @@ int main(int argc, char *argv[])
 		cleanup(EXIT_FAILURE);
 	}
 #endif
-
+	unsigned short cols = getcols(fileno(stdout));
 	if(config->verbose > 0) {
 		alpm_list_t *j;
-		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));
-		printf("Cache Dirs: ");
-		for(j = alpm_option_get_cachedirs(config->handle); j; j = alpm_list_next(j)) {
-			printf("%s  ", (const char *)j->data);
+		if (config->color) {
+			color_string_display(COLOR_WHITE_ALL,
+					"Root      : %s\n", alpm_option_get_root(config->handle), cols);
+			color_string_display(COLOR_WHITE_ALL,
+					"Conf File : %s\n", config->configfile, cols);
+			color_string_display(COLOR_WHITE_ALL,
+					"DB Path   : %s\n", alpm_option_get_dbpath(config->handle), cols);
+			color_printf(COLOR_WHITE_ALL, "Cache Dirs: ");
+			for(j = alpm_option_get_cachedirs(config->handle); j; j = alpm_list_next(j)) {
+				printf("%s  ", (const char *)j->data);
+			}
+			printf("\n");
+			color_string_display(COLOR_WHITE_ALL,
+					"Lock File : %s\n", alpm_option_get_lockfile(config->handle), cols);
+			color_string_display(COLOR_WHITE_ALL,
+					"Log File  : %s\n", alpm_option_get_logfile(config->handle), cols);
+			color_string_display(COLOR_WHITE_ALL,
+					"GPG Dir   : %s\n", alpm_option_get_gpgdir(config->handle), cols);
+			color_list_display(COLOR_WHITE_ALL,
+					"Targets   :", pm_targets, 0);
+		} else {
+			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));
+			printf("Cache Dirs: ");
+			for(j = alpm_option_get_cachedirs(config->handle); j; j = alpm_list_next(j)) {
+				printf("%s  ", (const char *)j->data);
+			}
+			printf("\n");
+			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);
 		}
-		printf("\n");
-		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);
 	}
 
 	/* Log command line */
-- 
1.7.11.4



More information about the pacman-dev mailing list