[pacman-dev] [PATCH 00/15] Colour support in pacman V2!
I believe I've addressed all the current concerns with the patchset. Submitting again for further review. https://github.com/vodik/pacman/ https://github.com/vodik/pacman/compare/cb2edc60cf...master Simon Gomizelj (15): refactor common code in query_search/sync_search remove :: prefix from all message split "Packages (%zd):" message remove format from statistic messages standardize format functions add a config settings and flag for colours introduce colstr for colourizing colourize colon_printf and question colourize warnings and errors colourize table output colourize the output if -Qi/Si colourize -Ss/-Qs colourize -Sl/-Ql colourize -Q update documentation and config files doc/pacman.8.txt | 5 +++ doc/pacman.conf.5.txt | 3 ++ etc/pacman.conf.in | 1 + src/pacman/callback.c | 26 ++++++------ src/pacman/conf.c | 52 ++++++++++++++++++++++++ src/pacman/conf.h | 25 +++++++++++- src/pacman/package.c | 107 ++++++++++++++++++++++++++++++++++++++++++++----- src/pacman/package.h | 3 ++ src/pacman/pacman.c | 16 ++++++++ src/pacman/query.c | 60 ++-------------------------- src/pacman/remove.c | 2 +- src/pacman/sync.c | 95 +++++++------------------------------------- src/pacman/util.c | 108 ++++++++++++++++++++++++++++++++++++++------------ src/pacman/util.h | 5 ++- 14 files changed, 320 insertions(+), 188 deletions(-) -- 1.8.1.5
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- src/pacman/package.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/pacman/package.h | 3 ++ src/pacman/query.c | 56 +---------------------------------- src/pacman/sync.c | 75 ++-------------------------------------------- 4 files changed, 91 insertions(+), 127 deletions(-) diff --git a/src/pacman/package.c b/src/pacman/package.c index 330f7ab..e94c295 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -341,4 +341,88 @@ void dump_pkg_changelog(alpm_pkg_t *pkg) } } +void print_installed(alpm_db_t *db_local, alpm_pkg_t *pkg) +{ + const char *pkgname = alpm_pkg_get_name(pkg); + const char *pkgver = alpm_pkg_get_version(pkg); + alpm_pkg_t *lpkg = alpm_db_get_pkg(db_local, pkgname); + if(lpkg) { + const char *lpkgver = alpm_pkg_get_version(lpkg); + if(strcmp(lpkgver, pkgver) == 0) { + printf(" [%s]", _("installed")); + } else { + printf(" [%s: %s]", _("installed"), lpkgver); + } + } +} + +/** + * Display the defails of a search. + * @param db the database we're searching + * @param targets the targets we're searching for + * @param show_status show if the package is also in the local db + */ +int dump_pkg_search(alpm_db_t *db, alpm_list_t *targets, int show_status) +{ + int freelist = 0; + alpm_list_t *i, *searchlist; + unsigned short cols; + + /* if we have a targets list, search for packages matching it */ + if(targets) { + searchlist = alpm_db_search(db, targets); + freelist = 1; + } else { + searchlist = alpm_db_get_pkgcache(db); + freelist = 0; + } + if(searchlist == NULL) { + return 1; + } + + cols = getcols(fileno(stdout)); + for(i = searchlist; i; i = alpm_list_next(i)) { + alpm_list_t *grp; + alpm_pkg_t *pkg = i->data; + + if(config->quiet) { + fputs(alpm_pkg_get_name(pkg), stdout); + } else { + printf("%s/%s %s", alpm_db_get_name(db), + alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg)); + + 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(' '); + } + } + putchar(')'); + } + + if(show_status) { + alpm_db_t *db_local = alpm_get_localdb(config->handle); + print_installed(db_local, pkg); + } + + /* we need a newline and initial indent first */ + fputs("\n ", stdout); + indentprint(alpm_pkg_get_desc(pkg), 4, cols); + } + fputc('\n', stdout); + } + + /* we only want to free if the list was a search list */ + if(freelist) { + alpm_list_free(searchlist); + } + + return 0; +} + /* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman/package.h b/src/pacman/package.h index 47fbcad..65eea87 100644 --- a/src/pacman/package.h +++ b/src/pacman/package.h @@ -28,6 +28,9 @@ void dump_pkg_backups(alpm_pkg_t *pkg); void dump_pkg_files(alpm_pkg_t *pkg, int quiet); void dump_pkg_changelog(alpm_pkg_t *pkg); +void print_installed(alpm_db_t *db_local, alpm_pkg_t *pkg); +int dump_pkg_search(alpm_db_t *db, alpm_list_t *targets, int show_status); + #endif /* _PM_PACKAGE_H */ /* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman/query.c b/src/pacman/query.c index 1247c3d..ba8d7bc 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -262,62 +262,8 @@ targcleanup: /* search the local database for a matching package */ static int query_search(alpm_list_t *targets) { - alpm_list_t *i, *searchlist; - int freelist; alpm_db_t *db_local = alpm_get_localdb(config->handle); - unsigned short cols; - - /* if we have a targets list, search for packages matching it */ - if(targets) { - searchlist = alpm_db_search(db_local, targets); - freelist = 1; - } else { - searchlist = alpm_db_get_pkgcache(db_local); - freelist = 0; - } - if(searchlist == NULL) { - return 1; - } - - cols = getcols(fileno(stdout)); - for(i = searchlist; i; i = alpm_list_next(i)) { - alpm_list_t *grp; - alpm_pkg_t *pkg = i->data; - - if(!config->quiet) { - printf(LOCAL_PREFIX "%s %s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg)); - } else { - fputs(alpm_pkg_get_name(pkg), stdout); - } - - - 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(' '); - } - } - putchar(')'); - } - - /* we need a newline and initial indent first */ - fputs("\n ", stdout); - indentprint(alpm_pkg_get_desc(pkg), 4, cols); - } - fputc('\n', stdout); - } - - /* we only want to free if the list was a search list */ - if(freelist) { - alpm_list_free(searchlist); - } - return 0; + return dump_pkg_search(db_local, targets, 0); } static int query_group(alpm_list_t *targets) diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 924cdf5..8d38edf 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -352,87 +352,18 @@ static int sync_synctree(int level, alpm_list_t *syncs) return (success > 0); } -static void print_installed(alpm_db_t *db_local, alpm_pkg_t *pkg) -{ - const char *pkgname = alpm_pkg_get_name(pkg); - const char *pkgver = alpm_pkg_get_version(pkg); - alpm_pkg_t *lpkg = alpm_db_get_pkg(db_local, pkgname); - if(lpkg) { - const char *lpkgver = alpm_pkg_get_version(lpkg); - if(strcmp(lpkgver, pkgver) == 0) { - printf(" [%s]", _("installed")); - } else { - printf(" [%s: %s]", _("installed"), lpkgver); - } - } -} - /* search the sync dbs for a matching package */ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets) { - alpm_list_t *i, *j, *ret; - int freelist; + alpm_list_t *i; int found = 0; - alpm_db_t *db_local = alpm_get_localdb(config->handle); for(i = syncs; i; i = alpm_list_next(i)) { alpm_db_t *db = i->data; - unsigned short cols; - /* if we have a targets list, search for packages matching it */ - if(targets) { - ret = alpm_db_search(db, targets); - freelist = 1; - } else { - ret = alpm_db_get_pkgcache(db); - freelist = 0; - } - if(ret == NULL) { - continue; - } else { - found = 1; - } - cols = getcols(fileno(stdout)); - for(j = ret; j; j = alpm_list_next(j)) { - alpm_list_t *grp; - 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)); - } else { - fputs(alpm_pkg_get_name(pkg), stdout); - } - - 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(' '); - } - } - putchar(')'); - } - - print_installed(db_local, pkg); - - /* we need a newline and initial indent first */ - fputs("\n ", stdout); - indentprint(alpm_pkg_get_desc(pkg), 4, cols); - } - fputc('\n', stdout); - } - /* we only want to free if the list was a search list */ - if(freelist) { - alpm_list_free(ret); - } + found += !dump_pkg_search(db, targets, 1); } - return !found; + return (found == 0); } static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets) -- 1.8.1.5
On 07/03/13 03:51, Simon Gomizelj wrote:
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- src/pacman/package.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/pacman/package.h | 3 ++ src/pacman/query.c | 56 +---------------------------------- src/pacman/sync.c | 75 ++-------------------------------------------- 4 files changed, 91 insertions(+), 127 deletions(-)
diff --git a/src/pacman/package.c b/src/pacman/package.c index 330f7ab..e94c295 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -341,4 +341,88 @@ void dump_pkg_changelog(alpm_pkg_t *pkg) } }
+void print_installed(alpm_db_t *db_local, alpm_pkg_t *pkg) +{ + const char *pkgname = alpm_pkg_get_name(pkg); + const char *pkgver = alpm_pkg_get_version(pkg); + alpm_pkg_t *lpkg = alpm_db_get_pkg(db_local, pkgname); + if(lpkg) { + const char *lpkgver = alpm_pkg_get_version(lpkg); + if(strcmp(lpkgver, pkgver) == 0) { + printf(" [%s]", _("installed")); + } else { + printf(" [%s: %s]", _("installed"), lpkgver); + } + } +} + +/** + * Display the defails of a search. + * @param db the database we're searching + * @param targets the targets we're searching for + * @param show_status show if the package is also in the local db + */ +int dump_pkg_search(alpm_db_t *db, alpm_list_t *targets, int show_status) +{ + int freelist = 0; + alpm_list_t *i, *searchlist; + unsigned short cols; + + /* if we have a targets list, search for packages matching it */ + if(targets) { + searchlist = alpm_db_search(db, targets); + freelist = 1; + } else { + searchlist = alpm_db_get_pkgcache(db); + freelist = 0; + } + if(searchlist == NULL) { + return 1; + } + + cols = getcols(fileno(stdout)); + for(i = searchlist; i; i = alpm_list_next(i)) { + alpm_list_t *grp; + alpm_pkg_t *pkg = i->data; + + if(config->quiet) { + fputs(alpm_pkg_get_name(pkg), stdout); + } else { + printf("%s/%s %s", alpm_db_get_name(db), + alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg)); + + 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(' '); + } + } + putchar(')'); + } + + if(show_status) { + alpm_db_t *db_local = alpm_get_localdb(config->handle);
We don't need to do this for every package... Declare it at the start and do a "if(show_status && !config->quiet)" after the initial checks.
+ print_installed(db_local, pkg); + } + + /* we need a newline and initial indent first */ + fputs("\n ", stdout); + indentprint(alpm_pkg_get_desc(pkg), 4, cols); + } + fputc('\n', stdout); + } + + /* we only want to free if the list was a search list */ + if(freelist) { + alpm_list_free(searchlist); + } + + return 0; +} +
Will do. FWIW if(show_status) is enough, the parent if already checks for !config->quiet > We don't need to do this for every package... Declare it at the start > and do a "if(show_status && !config->quiet)" after the initial > checks.
Derp. if(show_status) if enough since the code only runs if its not quiet already. On Thu, Mar 7, 2013 at 12:28 AM, Simon Gomizelj <simongmzlj@gmail.com> wrote:
Will do.
FWIW if(show_status) is enough, the parent if already checks for !config->quiet > We don't need to do this for every package... Declare it at the start > and do a "if(show_status && !config->quiet)" after the initial > checks.
This will substantially simplify the logic to add colours to messages. Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- src/pacman/callback.c | 26 +++++++++++++------------- src/pacman/remove.c | 2 +- src/pacman/sync.c | 14 +++++++------- src/pacman/util.c | 17 +++++++++++++++-- src/pacman/util.h | 1 + 5 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/pacman/callback.c b/src/pacman/callback.c index edd5b39..d0887cb 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -244,7 +244,7 @@ void cb_event(alpm_event_t event, void *data1, void *data2) fputs((const char *)data1, stdout); break; case ALPM_EVENT_RETRIEVE_START: - printf(_(":: Retrieving packages ...\n")); + colon_printf(_("Retrieving packages ...\n")); break; case ALPM_EVENT_DISKSPACE_START: if(config->noprogressbar) { @@ -252,7 +252,7 @@ void cb_event(alpm_event_t event, void *data1, void *data2) } break; case ALPM_EVENT_OPTDEP_REQUIRED: - printf(_(":: %s optionally requires %s\n"), alpm_pkg_get_name(data1), + colon_printf(_("%s optionally requires %s\n"), alpm_pkg_get_name(data1), alpm_dep_compute_string(data2)); break; case ALPM_EVENT_DATABASE_MISSING: @@ -290,14 +290,14 @@ void cb_question(alpm_question_t event, void *data1, void *data2, switch(event) { case ALPM_QUESTION_INSTALL_IGNOREPKG: if(!config->op_s_downloadonly) { - *response = yesno(_(":: %s is in IgnorePkg/IgnoreGroup. Install anyway?"), + *response = yesno(_("%s is in IgnorePkg/IgnoreGroup. Install anyway?"), alpm_pkg_get_name(data1)); } else { *response = 1; } break; case ALPM_QUESTION_REPLACE_PKG: - *response = yesno(_(":: Replace %s with %s/%s?"), + *response = yesno(_("Replace %s with %s/%s?"), alpm_pkg_get_name(data1), (char *)data3, alpm_pkg_get_name(data2)); @@ -306,12 +306,12 @@ void cb_question(alpm_question_t event, void *data1, void *data2, /* data parameters: target package, local package, conflict (strings) */ /* print conflict only if it contains new information */ if(strcmp(data1, data3) == 0 || strcmp(data2, data3) == 0) { - *response = noyes(_(":: %s and %s are in conflict. Remove %s?"), + *response = noyes(_("%s and %s are in conflict. Remove %s?"), (char *)data1, (char *)data2, (char *)data2); } else { - *response = noyes(_(":: %s and %s are in conflict (%s). Remove %s?"), + *response = noyes(_("%s and %s are in conflict (%s). Remove %s?"), (char *)data1, (char *)data2, (char *)data3, @@ -328,9 +328,9 @@ void cb_question(alpm_question_t event, void *data1, void *data2, (char *)alpm_pkg_get_name(i->data)); count++; } - printf(_n( - ":: The following package cannot be upgraded due to unresolvable dependencies:\n", - ":: The following packages cannot be upgraded due to unresolvable dependencies:\n", + colon_printf(_n( + "The following package cannot be upgraded due to unresolvable dependencies:\n", + "The following packages cannot be upgraded due to unresolvable dependencies:\n", count)); list_display(" ", namelist, getcols(fileno(stdout))); printf("\n"); @@ -346,7 +346,7 @@ void cb_question(alpm_question_t event, void *data1, void *data2, alpm_list_t *providers = data1; size_t count = alpm_list_count(providers); char *depstring = alpm_dep_compute_string((alpm_depend_t *)data2); - printf(_(":: There are %zd providers available for %s:\n"), count, + colon_printf(_("There are %zd providers available for %s:\n"), count, depstring); free(depstring); select_display(providers); @@ -355,7 +355,7 @@ void cb_question(alpm_question_t event, void *data1, void *data2, break; case ALPM_QUESTION_LOCAL_NEWER: if(!config->op_s_downloadonly) { - *response = yesno(_(":: %s-%s: local version is newer. Upgrade anyway?"), + *response = yesno(_("%s-%s: local version is newer. Upgrade anyway?"), alpm_pkg_get_name(data1), alpm_pkg_get_version(data1)); } else { @@ -363,7 +363,7 @@ void cb_question(alpm_question_t event, void *data1, void *data2, } break; case ALPM_QUESTION_CORRUPTED_PKG: - *response = yesno(_(":: File %s is corrupted (%s).\n" + *response = yesno(_("File %s is corrupted (%s).\n" "Do you want to delete it?"), (char *)data1, alpm_strerror(*(alpm_errno_t *)data2)); @@ -380,7 +380,7 @@ void cb_question(alpm_question_t event, void *data1, void *data2, revoked = " (revoked)"; } - *response = yesno(_(":: Import PGP key %d%c/%s, \"%s\", created: %s%s?"), + *response = yesno(_("Import PGP key %d%c/%s, \"%s\", created: %s%s?"), key->length, key->pubkey_algo, key->fingerprint, key->uid, created, revoked); } break; diff --git a/src/pacman/remove.c b/src/pacman/remove.c index 943a555..8cf3ebc 100644 --- a/src/pacman/remove.c +++ b/src/pacman/remove.c @@ -119,7 +119,7 @@ int pacman_remove(alpm_list_t *targets) 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); + colon_printf(_("%s: requires %s\n"), miss->target, depstring); free(depstring); } break; diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 8d38edf..7b54cba 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -592,7 +592,7 @@ 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, + colon_printf(_("There are %d members in group %s:\n"), count, group); select_display(pkgs); char *array = malloc(count); @@ -717,7 +717,7 @@ static int sync_trans(alpm_list_t *targets) } if(config->op_s_upgrade) { - printf(_(":: Starting full system upgrade...\n")); + colon_printf(_("Starting full system upgrade...\n")); alpm_logaction(config->handle, PACMAN_CALLER_PREFIX, "starting full system upgrade\n"); if(alpm_sync_sysupgrade(config->handle, config->op_s_upgrade >= 2) == -1) { @@ -744,14 +744,14 @@ 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); + colon_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); + colon_printf(_("%s: requires %s\n"), miss->target, depstring); free(depstring); } break; @@ -760,11 +760,11 @@ 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"), + colon_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"), + colon_printf(_("%s and %s are in conflict (%s)\n"), conflict->package1, conflict->package2, reason); free(reason); } @@ -889,7 +889,7 @@ int pacman_sync(alpm_list_t *targets) if(config->op_s_sync) { /* grab a fresh package list */ - printf(_(":: Synchronizing package databases...\n")); + colon_printf(_("Synchronizing package databases...\n")); alpm_logaction(config->handle, PACMAN_CALLER_PREFIX, "synchronizing package lists\n"); if(!sync_synctree(config->op_s_sync, sync_dbs)) { diff --git a/src/pacman/util.c b/src/pacman/util.c index 3270c74..182450b 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1219,8 +1219,7 @@ static void display_repo_list(const char *dbname, alpm_list_t *list, { const char *prefix = " "; - printf(":: "); - printf(_("Repository %s\n"), dbname); + colon_printf(_("Repository %s\n"), dbname); list_display(prefix, list, cols); } @@ -1461,6 +1460,7 @@ static int question(short preset, char *fmt, va_list args) fflush(stdout); fflush(stderr); + fprintf(stream, ":: "); vfprintf(stream, fmt, args); if(preset) { @@ -1522,6 +1522,19 @@ int noyes(char *fmt, ...) return ret; } +int colon_printf(const char *fmt, ...) +{ + int ret; + va_list args; + + fputs(":: ", stdout); + va_start(args, fmt); + ret = vprintf(fmt, args); + va_end(args); + + return ret; +} + int pm_printf(alpm_loglevel_t level, const char *format, ...) { int ret; diff --git a/src/pacman/util.h b/src/pacman/util.h index 2d1e698..f579b7e 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -72,6 +72,7 @@ void print_packages(const alpm_list_t *packages); void select_display(const alpm_list_t *pkglist); int select_question(int count); int multiselect_question(char *array, int count); +int colon_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); int yesno(char *fmt, ...) __attribute__((format(printf, 1, 2))); int noyes(char *fmt, ...) __attribute__((format(printf, 1, 2))); -- 1.8.1.5
Basically all translation messages that need colouring but _also_ happen to be format strings need to be split up. This makes it easy to conditionally embed colour codes into the output at runtime. Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- src/pacman/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pacman/util.c b/src/pacman/util.c index 182450b..90892af 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -871,7 +871,7 @@ static void _display_targets(alpm_list_t *targets, int verbose) } /* print to screen */ - pm_asprintf(&str, _("Packages (%zd):"), alpm_list_count(targets)); + pm_asprintf(&str, "%s (%zd):", _("Packages"), alpm_list_count(targets)); printf("\n"); cols = getcols(fileno(stdout)); -- 1.8.1.5
Remove the format component of the "Total Download Size" and related messages. The heading will be colourized, the size won't. However since the length of these messages can vary by language, we need a pretty printer to format them nicely. Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- src/pacman/util.c | 56 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/src/pacman/util.c b/src/pacman/util.c index 90892af..aa352e3 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -47,6 +47,11 @@ #include "callback.h" +struct table_row_t { + const char *label; + int size; +}; + int trans_init(alpm_transflag_t flags, int check_valid) { int ret; @@ -824,15 +829,48 @@ static alpm_list_t *create_verbose_row(pm_target_t *target) return ret; } +static void add_table_row(alpm_list_t **rows, const char *label, int size) +{ + struct table_row_t *row = malloc(sizeof(struct table_row_t)); + + row->label = label; + row->size = size; + + *rows = alpm_list_add(*rows, row); +} + +static void display_transaction_sizes(alpm_list_t *table) +{ + alpm_list_t *i; + int max_len = 0; + + for(i = table; i; i = alpm_list_next(i)) { + struct table_row_t *row = i->data; + int len = string_length(row->label); + + if(len > max_len) + max_len = len; + } + + max_len += 2; + + for(i = table; i; i = alpm_list_next(i)) { + struct table_row_t *row = i->data; + const char *units; + double s = humanize_size(row->size, 'M', 2, &units); + + printf("%-*s %.2f %s\n", max_len, row->label, s, units); + } +} + /* prepare a list of pkgs to display */ static void _display_targets(alpm_list_t *targets, int verbose) { char *str; - const char *label; - double size; off_t isize = 0, rsize = 0, dlsize = 0; unsigned short cols; alpm_list_t *i, *rows = NULL, *names = NULL; + alpm_list_t *table = NULL; if(!targets) { return; @@ -897,24 +935,22 @@ static void _display_targets(alpm_list_t *targets, int verbose) free(str); if(dlsize > 0 || config->op_s_downloadonly) { - size = humanize_size(dlsize, 'M', 2, &label); - printf(_("Total Download Size: %.2f %s\n"), size, label); + add_table_row(&table, _("Total Download Size:"), dlsize); } if(!config->op_s_downloadonly) { if(isize > 0) { - size = humanize_size(isize, 'M', 2, &label); - printf(_("Total Installed Size: %.2f %s\n"), size, label); + add_table_row(&table, _("Total Installed Size:"), isize); } if(rsize > 0 && isize == 0) { - size = humanize_size(rsize, 'M', 2, &label); - printf(_("Total Removed Size: %.2f %s\n"), size, label); + add_table_row(&table, _("Total Removed Size:"), rsize); } /* only show this net value if different from raw installed size */ if(isize > 0 && rsize > 0) { - size = humanize_size(isize - rsize, 'M', 2, &label); - printf(_("Net Upgrade Size: %.2f %s\n"), size, label); + add_table_row(&table, _("Net Upgrade Size:"), isize - rsize); } } + display_transaction_sizes(table); + FREELIST(table); } static int target_cmp(const void *p1, const void *p2) -- 1.8.1.5
On 07/03/13 03:51, Simon Gomizelj wrote:
Remove the format component of the "Total Download Size" and related messages. The heading will be colourized, the size won't.
However since the length of these messages can vary by language, we need a pretty printer to format them nicely.
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- src/pacman/util.c | 56 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 10 deletions(-)
diff --git a/src/pacman/util.c b/src/pacman/util.c index 90892af..aa352e3 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -47,6 +47,11 @@ #include "callback.h"
+struct table_row_t { + const char *label; + int size; +}; + int trans_init(alpm_transflag_t flags, int check_valid) { int ret; @@ -824,15 +829,48 @@ static alpm_list_t *create_verbose_row(pm_target_t *target) return ret; }
+static void add_table_row(alpm_list_t **rows, const char *label, int size)
I'd like a more descriptive name for this. How about add_transaction_sizes_row()? Also, can we change "rows" to "table". This makes the variable names more distinct.
+{ + struct table_row_t *row = malloc(sizeof(struct table_row_t)); + + row->label = label; + row->size = size; + + *rows = alpm_list_add(*rows, row); +} + +static void display_transaction_sizes(alpm_list_t *table) +{ + alpm_list_t *i; + int max_len = 0; + + for(i = table; i; i = alpm_list_next(i)) { + struct table_row_t *row = i->data; + int len = string_length(row->label); + + if(len > max_len) + max_len = len; + } + + max_len += 2; + + for(i = table; i; i = alpm_list_next(i)) { + struct table_row_t *row = i->data; + const char *units; + double s = humanize_size(row->size, 'M', 2, &units); + + printf("%-*s %.2f %s\n", max_len, row->label, s, units); + } +} + /* prepare a list of pkgs to display */ static void _display_targets(alpm_list_t *targets, int verbose) { char *str; - const char *label; - double size; off_t isize = 0, rsize = 0, dlsize = 0; unsigned short cols; alpm_list_t *i, *rows = NULL, *names = NULL; + alpm_list_t *table = NULL;
Combine into above line.
if(!targets) { return; @@ -897,24 +935,22 @@ static void _display_targets(alpm_list_t *targets, int verbose) free(str);
if(dlsize > 0 || config->op_s_downloadonly) { - size = humanize_size(dlsize, 'M', 2, &label); - printf(_("Total Download Size: %.2f %s\n"), size, label); + add_table_row(&table, _("Total Download Size:"), dlsize); } if(!config->op_s_downloadonly) { if(isize > 0) { - size = humanize_size(isize, 'M', 2, &label); - printf(_("Total Installed Size: %.2f %s\n"), size, label); + add_table_row(&table, _("Total Installed Size:"), isize); } if(rsize > 0 && isize == 0) { - size = humanize_size(rsize, 'M', 2, &label); - printf(_("Total Removed Size: %.2f %s\n"), size, label); + add_table_row(&table, _("Total Removed Size:"), rsize); } /* only show this net value if different from raw installed size */ if(isize > 0 && rsize > 0) { - size = humanize_size(isize - rsize, 'M', 2, &label); - printf(_("Net Upgrade Size: %.2f %s\n"), size, label); + add_table_row(&table, _("Net Upgrade Size:"), isize - rsize); } } + display_transaction_sizes(table); + FREELIST(table); }
static int target_cmp(const void *p1, const void *p2)
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- src/pacman/util.c | 16 ++++++++-------- src/pacman/util.h | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/pacman/util.c b/src/pacman/util.c index aa352e3..f326849 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1479,7 +1479,7 @@ int select_question(int count) /* presents a prompt and gets a Y/N answer */ __attribute__((format(printf, 2, 0))) -static int question(short preset, char *fmt, va_list args) +static int question(short preset, const char *format, va_list args) { char response[32]; FILE *stream; @@ -1497,7 +1497,7 @@ static int question(short preset, char *fmt, va_list args) fflush(stderr); fprintf(stream, ":: "); - vfprintf(stream, fmt, args); + vfprintf(stream, format, args); if(preset) { fprintf(stream, " %s ", _("[Y/n]")); @@ -1534,25 +1534,25 @@ static int question(short preset, char *fmt, va_list args) return 0; } -int yesno(char *fmt, ...) +int yesno(const char *format, ...) { int ret; va_list args; - va_start(args, fmt); - ret = question(1, fmt, args); + va_start(args, format); + ret = question(1, format, args); va_end(args); return ret; } -int noyes(char *fmt, ...) +int noyes(const char *format, ...) { int ret; va_list args; - va_start(args, fmt); - ret = question(0, fmt, args); + va_start(args, format); + ret = question(0, format, args); va_end(args); return ret; diff --git a/src/pacman/util.h b/src/pacman/util.h index f579b7e..0a2a6f7 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -72,9 +72,9 @@ void print_packages(const alpm_list_t *packages); void select_display(const alpm_list_t *pkglist); int select_question(int count); int multiselect_question(char *array, int count); -int colon_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); -int yesno(char *fmt, ...) __attribute__((format(printf, 1, 2))); -int noyes(char *fmt, ...) __attribute__((format(printf, 1, 2))); +int colon_printf(const char *format, ...) __attribute__((format(printf, 1, 2))); +int yesno(const char *format, ...) __attribute__((format(printf, 1, 2))); +int noyes(const char *format, ...) __attribute__((format(printf, 1, 2))); int pm_printf(alpm_loglevel_t level, const char *format, ...) __attribute__((format(printf,2,3))); int pm_asprintf(char **string, const char *format, ...) __attribute__((format(printf,2,3))); -- 1.8.1.5
Colours can be enabled in two ways: - Add Color to pacman.conf. This enables colours automatically. - Use --color=WHEN where WHEN is none/auto/always. WHEN as 'never' disables colours (overrides config file), as 'auto' enables colours when stdout is a tty, and 'always' enables colours no matter what. Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- src/pacman/conf.c | 4 ++++ src/pacman/conf.h | 9 ++++++++- src/pacman/pacman.c | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 218ffb4..dca6e3e 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -436,6 +436,10 @@ static int _parse_options(const char *key, char *value, pm_printf(ALPM_LOG_DEBUG, "config: totaldownload\n"); } else if(strcmp(key, "CheckSpace") == 0) { config->checkspace = 1; + } else if(strcmp(key, "Color") == 0) { + if(config->color == PM_COLOR_UNSET) { + config->color = isatty(fileno(stdout)) ? PM_COLOR_ON : PM_COLOR_OFF; + } } else { pm_printf(ALPM_LOG_WARNING, _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"), diff --git a/src/pacman/conf.h b/src/pacman/conf.h index d85d11f..6cabd33 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -34,6 +34,7 @@ typedef struct __config_t { unsigned short print; unsigned short checkspace; unsigned short usesyslog; + unsigned short color; double deltaratio; char *arch; char *print_format; @@ -129,7 +130,8 @@ enum { OP_PRINTFORMAT, OP_GPGDIR, OP_DBONLY, - OP_FORCE + OP_FORCE, + OP_COLOR }; /* clean method */ @@ -145,6 +147,11 @@ enum { PKG_LOCALITY_FOREIGN = (1 << 1) }; +enum { + PM_COLOR_UNSET = 0, + PM_COLOR_OFF, + PM_COLOR_ON +}; /* global config variable */ extern config_t *config; diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 38b28e1..bb8b439 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -197,6 +197,7 @@ static void usage(int op, const char * const myname) addlist(_(" -v, --verbose be verbose\n")); addlist(_(" --arch <arch> set an alternate architecture\n")); addlist(_(" --cachedir <dir> set an alternate package cache location\n")); + addlist(_(" --color <when> colorize the output\n")); addlist(_(" --config <path> set an alternate configuration file\n")); addlist(_(" --debug display debug messages\n")); addlist(_(" --gpgdir <path> set an alternate home directory for GnuPG\n")); @@ -394,6 +395,19 @@ static int parsearg_global(int opt) check_optarg(); config->cachedirs = alpm_list_add(config->cachedirs, strdup(optarg)); break; + case OP_COLOR: + if(strcmp("never", optarg) == 0) { + config->color = PM_COLOR_OFF; + } else if(strcmp("auto", optarg) == 0) { + config->color = isatty(fileno(stdout)) ? PM_COLOR_ON : PM_COLOR_OFF; + } else if(strcmp("always", optarg) == 0) { + config->color = PM_COLOR_ON; + } else { + pm_printf(ALPM_LOG_ERROR, _("invalid agument '%s' for %s\n"), + optarg, "--color"); + return 1; + } + break; case OP_CONFIG: check_optarg(); if(config->configfile) { @@ -632,6 +646,7 @@ static int parseargs(int argc, char *argv[]) {"print-format", required_argument, 0, OP_PRINTFORMAT}, {"gpgdir", required_argument, 0, OP_GPGDIR}, {"dbonly", no_argument, 0, OP_DBONLY}, + {"color", required_argument, 0, OP_COLOR}, {0, 0, 0, 0} }; -- 1.8.1.5
colstr_t colstr will hold the colourizing agents. Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- src/pacman/conf.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/pacman/conf.h | 16 ++++++++++++++++ src/pacman/pacman.c | 1 + 3 files changed, 65 insertions(+) diff --git a/src/pacman/conf.c b/src/pacman/conf.c index dca6e3e..815df95 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -39,6 +39,43 @@ /* global config variable */ config_t *config = NULL; +#define NOCOLOR "\033[0m" + +#define BLACK "\033[0;30m" +#define RED "\033[0;31m" +#define GREEN "\033[0;32m" +#define YELLOW "\033[0;33m" +#define BLUE "\033[0;34m" +#define MAGENTA "\033[0;35m" +#define CYAN "\033[0;36m" +#define WHITE "\033[0;37m" + +#define BOLDBLACK "\033[1;30m" +#define BOLDRED "\033[1;31m" +#define BOLDGREEN "\033[1;32m" +#define BOLDYELLOW "\033[1;33m" +#define BOLDBLUE "\033[1;34m" +#define BOLDMAGENTA "\033[1;35m" +#define BOLDCYAN "\033[1;36m" +#define BOLDWHITE "\033[1;37m" + +void enable_colors(int colors) +{ + colstr_t *colstr = &config->colstr; + + if(colors == PM_COLOR_ON) { + colstr->colon = BOLDBLUE "::" BOLDWHITE " "; + colstr->title = BOLDWHITE; + colstr->repo = BOLDMAGENTA; + colstr->version = BOLDGREEN; + colstr->groups = BOLDBLUE; + colstr->meta = BOLDCYAN; + colstr->warn = BOLDYELLOW; + colstr->err = BOLDRED; + colstr->nocolor = NOCOLOR; + } +} + config_t *config_new(void) { config_t *newconfig = calloc(1, sizeof(config_t)); @@ -60,6 +97,16 @@ config_t *config_new(void) newconfig->remotefilesiglevel = ALPM_SIG_USE_DEFAULT; } + newconfig->colstr.colon = ":: "; + newconfig->colstr.title = ""; + newconfig->colstr.repo = ""; + newconfig->colstr.version = ""; + newconfig->colstr.groups = ""; + newconfig->colstr.meta = ""; + newconfig->colstr.warn = ""; + newconfig->colstr.err = ""; + newconfig->colstr.nocolor = ""; + return newconfig; } @@ -439,6 +486,7 @@ static int _parse_options(const char *key, char *value, } else if(strcmp(key, "Color") == 0) { if(config->color == PM_COLOR_UNSET) { config->color = isatty(fileno(stdout)) ? PM_COLOR_ON : PM_COLOR_OFF; + enable_colors(config->color); } } else { pm_printf(ALPM_LOG_WARNING, diff --git a/src/pacman/conf.h b/src/pacman/conf.h index 6cabd33..dcd3204 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -22,6 +22,18 @@ #include <alpm.h> +typedef struct __colstr_t { + const char *colon; + const char *title; + const char *repo; + const char *version; + const char *groups; + const char *meta; + const char *warn; + const char *err; + const char *nocolor; +} colstr_t; + typedef struct __config_t { unsigned short op; unsigned short quiet; @@ -98,6 +110,9 @@ typedef struct __config_t { alpm_list_t *explicit_adds; alpm_list_t *explicit_removes; + + /* Color strings for output */ + colstr_t colstr; } config_t; /* Operations */ @@ -156,6 +171,7 @@ enum { /* global config variable */ extern config_t *config; +void enable_colors(int colors); config_t *config_new(void); int config_free(config_t *oldconfig); diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index bb8b439..a6ea14f 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -407,6 +407,7 @@ static int parsearg_global(int opt) optarg, "--color"); return 1; } + enable_colors(config->color); break; case OP_CONFIG: check_optarg(); -- 1.8.1.5
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- src/pacman/util.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/pacman/util.c b/src/pacman/util.c index f326849..bbc2d88 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1496,7 +1496,7 @@ static int question(short preset, const char *format, va_list args) fflush(stdout); fflush(stderr); - fprintf(stream, ":: "); + fputs(config->colstr.colon, stream); vfprintf(stream, format, args); if(preset) { @@ -1505,6 +1505,9 @@ static int question(short preset, const char *format, va_list args) fprintf(stream, " %s ", _("[y/N]")); } + fputs(config->colstr.nocolor, stream); + fflush(stream); + if(config->noconfirm) { fprintf(stream, "\n"); return preset; @@ -1563,11 +1566,13 @@ int colon_printf(const char *fmt, ...) int ret; va_list args; - fputs(":: ", stdout); va_start(args, fmt); + fputs(config->colstr.colon, stdout); ret = vprintf(fmt, args); + fputs(config->colstr.nocolor, stdout); va_end(args); + fflush(stdout); return ret; } -- 1.8.1.5
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- src/pacman/util.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pacman/util.c b/src/pacman/util.c index bbc2d88..e94b6ad 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1669,10 +1669,12 @@ int pm_vfprintf(FILE *stream, alpm_loglevel_t level, const char *format, va_list /* print a prefix to the message */ switch(level) { case ALPM_LOG_ERROR: - fprintf(stream, _("error: ")); + fprintf(stream, "%s%s%s", config->colstr.err, _("error: "), + config->colstr.nocolor); break; case ALPM_LOG_WARNING: - fprintf(stream, _("warning: ")); + fprintf(stream, "%s%s%s", config->colstr.warn, _("warning: "), + config->colstr.nocolor); break; case ALPM_LOG_DEBUG: fprintf(stream, "debug: "); -- 1.8.1.5
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- src/pacman/util.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pacman/util.c b/src/pacman/util.c index e94b6ad..8008c33 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -857,9 +857,11 @@ static void display_transaction_sizes(alpm_list_t *table) for(i = table; i; i = alpm_list_next(i)) { struct table_row_t *row = i->data; const char *units; + const colstr_t *colstr = &config->colstr; double s = humanize_size(row->size, 'M', 2, &units); - printf("%-*s %.2f %s\n", max_len, row->label, s, units); + printf("%s%-*s%s %.2f %s\n", colstr->title, max_len, row->label, + colstr->nocolor, s, units); } } -- 1.8.1.5
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- src/pacman/package.c | 12 ++++++++---- src/pacman/util.c | 6 +++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/pacman/package.c b/src/pacman/package.c index e94c295..0213346 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -167,13 +167,16 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra) size = humanize_size(alpm_pkg_get_size(pkg), 'K', 2, &label); if(from == ALPM_PKG_FROM_SYNCDB) { - printf(_("Download Size : %6.2f %s\n"), size, label); + printf("%s%s%s %6.2f %s\n", config->colstr.title, _("Download Size :"), + config->colstr.nocolor, size, label); } else if(from == ALPM_PKG_FROM_FILE) { - printf(_("Compressed Size: %6.2f %s\n"), size, label); + printf("%s%s%s %6.2f %s\n", config->colstr.title, _("Compressed Size:"), + config->colstr.nocolor, size, label); } size = humanize_size(alpm_pkg_get_isize(pkg), 'K', 2, &label); - printf(_("Installed Size : %6.2f %s\n"), size, label); + printf("%s%s%s %6.2f %s\n", config->colstr.title, _("Installed Size :"), + config->colstr.nocolor, size, label); string_display(_("Packager :"), alpm_pkg_get_packager(pkg), cols); string_display(_("Build Date :"), bdatestr, cols); @@ -267,7 +270,8 @@ void dump_pkg_backups(alpm_pkg_t *pkg) { alpm_list_t *i; const char *root = alpm_option_get_root(config->handle); - printf(_("Backup Files:\n")); + printf("%s%s%s", config->colstr.title, _("Backup Files:\n"), + config->colstr.nocolor); if(alpm_pkg_get_backup(pkg)) { /* package has backup files, so print them */ for(i = alpm_pkg_get_backup(pkg); i; i = alpm_list_next(i)) { diff --git a/src/pacman/util.c b/src/pacman/util.c index 8008c33..f44a661 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -427,7 +427,7 @@ static size_t string_length(const char *s) void string_display(const char *title, const char *string, unsigned short cols) { if(title) { - printf("%s ", title); + printf("%s%s%s ", config->colstr.title, title, config->colstr.nocolor); } if(string == NULL || string[0] == '\0') { printf(_("None")); @@ -620,7 +620,7 @@ void list_display(const char *title, const alpm_list_t *list, if(title) { len = string_length(title) + 1; - printf("%s ", title); + printf("%s%s%s ", config->colstr.title, title, config->colstr.nocolor); } if(!list) { @@ -660,7 +660,7 @@ void list_display_linebreak(const char *title, const alpm_list_t *list, if(title) { len = (unsigned short)string_length(title) + 1; - printf("%s ", title); + printf("%s%s%s ", config->colstr.title, title, config->colstr.nocolor); } if(!list) { -- 1.8.1.5
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- src/pacman/package.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/pacman/package.c b/src/pacman/package.c index 0213346..06d31d6 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -352,10 +352,12 @@ void print_installed(alpm_db_t *db_local, alpm_pkg_t *pkg) alpm_pkg_t *lpkg = alpm_db_get_pkg(db_local, pkgname); if(lpkg) { const char *lpkgver = alpm_pkg_get_version(lpkg); + const colstr_t *colstr = &config->colstr; if(strcmp(lpkgver, pkgver) == 0) { - printf(" [%s]", _("installed")); + printf(" %s[%s]%s", colstr->meta, _("installed"), colstr->nocolor); } else { - printf(" [%s: %s]", _("installed"), lpkgver); + printf(" %s[%s: %s]%s", colstr->meta, _("installed"), + lpkgver, colstr->nocolor); } } } @@ -371,6 +373,7 @@ int dump_pkg_search(alpm_db_t *db, alpm_list_t *targets, int show_status) int freelist = 0; alpm_list_t *i, *searchlist; unsigned short cols; + const colstr_t *colstr = &config->colstr; /* if we have a targets list, search for packages matching it */ if(targets) { @@ -392,12 +395,13 @@ int dump_pkg_search(alpm_db_t *db, alpm_list_t *targets, int show_status) if(config->quiet) { fputs(alpm_pkg_get_name(pkg), stdout); } else { - printf("%s/%s %s", alpm_db_get_name(db), - alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg)); + printf("%s%s/%s%s %s%s%s", colstr->repo, alpm_db_get_name(db), + colstr->title, alpm_pkg_get_name(pkg), + colstr->version, alpm_pkg_get_version(pkg), colstr->nocolor); if((grp = alpm_pkg_get_groups(pkg)) != NULL) { alpm_list_t *k; - fputs(" (", stdout); + printf(" %s(", colstr->groups); for(k = grp; k; k = alpm_list_next(k)) { const char *group = k->data; fputs(group, stdout); @@ -406,7 +410,7 @@ int dump_pkg_search(alpm_db_t *db, alpm_list_t *targets, int show_status) putchar(' '); } } - putchar(')'); + printf(")%s", colstr->nocolor); } if(show_status) { -- 1.8.1.5
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- src/pacman/package.c | 7 ++----- src/pacman/sync.c | 6 ++++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/pacman/package.c b/src/pacman/package.c index 06d31d6..df87dd8 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -307,12 +307,9 @@ void dump_pkg_files(alpm_pkg_t *pkg, int quiet) * Quiet : '<root><filepath>\n' */ if(!quiet) { - fputs(pkgname, stdout); - putchar(' '); + printf("%s%s%s ", config->colstr.title, pkgname, config->colstr.nocolor); } - fputs(root, stdout); - fputs(file->name, stdout); - putchar('\n'); + printf("%s%s\n", root, file->name); } fflush(stdout); diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 7b54cba..e8da346 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -522,8 +522,10 @@ 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)); + const colstr_t *colstr = &config->colstr; + printf("%s%s %s%s %s%s%s", colstr->repo, alpm_db_get_name(db), + colstr->title, alpm_pkg_get_name(pkg), + colstr->version, alpm_pkg_get_version(pkg), colstr->nocolor); print_installed(db_local, pkg); printf("\n"); } else { -- 1.8.1.5
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- src/pacman/query.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pacman/query.c b/src/pacman/query.c index ba8d7bc..f051571 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -386,7 +386,9 @@ 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)); + const colstr_t *colstr = &config->colstr; + printf("%s%s %s%s%s\n", colstr->title, alpm_pkg_get_name(pkg), + colstr->version, alpm_pkg_get_version(pkg), colstr->nocolor); } else { printf("%s\n", alpm_pkg_get_name(pkg)); } -- 1.8.1.5
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- doc/pacman.8.txt | 5 +++++ doc/pacman.conf.5.txt | 3 +++ etc/pacman.conf.in | 1 + 3 files changed, 9 insertions(+) diff --git a/doc/pacman.8.txt b/doc/pacman.8.txt index 33a9421..d1c7d20 100644 --- a/doc/pacman.8.txt +++ b/doc/pacman.8.txt @@ -146,6 +146,11 @@ Options and they are tried in the order they are passed to pacman. *NOTE*: this is an absolute path, the root path is not automatically prepended. +*\--color* <when>:: + Specify when to enable coloring, can be 'always', 'never' or 'auto'. Always + forces colours on, never forces colours off, and auto only automatically enables + colours when outputting onto a tty. + *\--config* <file>:: Specify an alternate configuration file. diff --git a/doc/pacman.conf.5.txt b/doc/pacman.conf.5.txt index aa28012..58d68f3 100644 --- a/doc/pacman.conf.5.txt +++ b/doc/pacman.conf.5.txt @@ -167,6 +167,9 @@ Options Log action messages through syslog(). This will insert log entries into +{localstatedir}/log/messages+ or equivalent. +*Color*:: + Automatically enable colors only when pacman's output is on a tty. + *UseDelta* [= ratio]:: Download delta files instead of complete packages if possible. Requires the `xdelta3` program to be installed. If a ratio is specified (e.g., diff --git a/etc/pacman.conf.in b/etc/pacman.conf.in index 4c72724..f610fa8 100644 --- a/etc/pacman.conf.in +++ b/etc/pacman.conf.in @@ -30,6 +30,7 @@ Architecture = auto # Misc options #UseSyslog +#Color #TotalDownload CheckSpace #VerbosePkgLists -- 1.8.1.5
participants (2)
-
Allan McRae
-
Simon Gomizelj