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 pacman.c

including special color_version
Signed-off-by: Daniel Wallace <daniel.wallace@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
", 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
");
+ color_printf(COLOR_YELLOW_ALL, " '-.");
+ color_printf(COLOR_WHITE_ALL, " '-' '-");
+ color_printf(COLOR_RED_ALL, "|~~~ |");
+ printf(" Copyright (C) 2002-2006 Judd Vinet
");
+ color_printf(COLOR_YELLOW_ALL, " '--' ");
+ printf(" ");
+ color_printf(COLOR_RED_ALL, "|.-.-.|");
+ printf("
");
+ printf(_(" This program may be freely redistributed under
"
+ " the terms of the GNU General Public License.
"));
+ printf("
");
+}
+
/* 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("
");
- printf(" .--. Pacman v%s - libalpm v%s
", PACKAGE_VERSION, alpm_version());
- printf("/ _.-' .-. .-. .-. Copyright (C) 2006-2012 Pacman Development Team
");
- printf(" '-. '-' '-' '-' Copyright (C) 2002-2006 Judd Vinet
");
- printf(" '--'
");
- printf(_(" This program may be freely redistributed under
"
- " the terms of the GNU General Public License.
"));
- printf("
");
+ if (config->color) {
+ color_version(PACKAGE_VERSION);
+ } else {
+ printf("
");
+ printf(" .--. Pacman v%s - libalpm v%s
", PACKAGE_VERSION, alpm_version());
+ printf("/ _.-' .-. .-. .-. Copyright (C) 2006-2012 Pacman Development Team
");
+ printf(" '-. '-' '-' '-' Copyright (C) 2002-2006 Judd Vinet
");
+ printf(" '--'
");
+ printf(_(" This program may be freely redistributed under
"
+ " the terms of the GNU General Public License.
"));
+ printf("
");
+ }
}

/** 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
", alpm_option_get_root(config->handle));
- printf("Conf File : %s
", config->configfile);
- printf("DB Path : %s
", 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
", alpm_option_get_root(config->handle), cols);
+ color_string_display(COLOR_WHITE_ALL,
+ "Conf File : %s
", config->configfile, cols);
+ color_string_display(COLOR_WHITE_ALL,
+ "DB Path : %s
", 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("
");
+ color_string_display(COLOR_WHITE_ALL,
+ "Lock File : %s
", alpm_option_get_lockfile(config->handle), cols);
+ color_string_display(COLOR_WHITE_ALL,
+ "Log File : %s
", alpm_option_get_logfile(config->handle), cols);
+ color_string_display(COLOR_WHITE_ALL,
+ "GPG Dir : %s
", alpm_option_get_gpgdir(config->handle), cols);
+ color_list_display(COLOR_WHITE_ALL,
+ "Targets :", pm_targets, 0);
+ } else {
+ printf("Root : %s
", alpm_option_get_root(config->handle));
+ printf("Conf File : %s
", config->configfile);
+ printf("DB Path : %s
", 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("
");
+ printf("Lock File : %s
", alpm_option_get_lockfile(config->handle));
+ printf("Log File : %s
", alpm_option_get_logfile(config->handle));
+ printf("GPG Dir : %s
", alpm_option_get_gpgdir(config->handle));
+ list_display("Targets :", pm_targets, 0);
}
- printf("
");
- printf("Lock File : %s
", alpm_option_get_lockfile(config->handle));
- printf("Log File : %s
", alpm_option_get_logfile(config->handle));
- printf("GPG Dir : %s
", alpm_option_get_gpgdir(config->handle));
- list_display("Targets :", pm_targets, 0);
}

/* Log command line */
--
1.7.11.4
 

Thread Tools




All times are GMT. The time now is 07:34 AM.

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