[pacman-dev] [PATCH] Added better colourisation support for certain operations: * Package Information: -Si and -Qi * Install Group: -S (group)

xavion.0 at gmail.com xavion.0 at gmail.com
Fri Mar 25 01:16:25 UTC 2016


From: Xavion <Xavion (dot) 0 (at) Gmail (dot) com>

Signed-off-by: Xavion <Xavion (dot) 0 (at) Gmail (dot) com>
---
 src/pacman/callback.c |  3 ++-
 src/pacman/package.c  | 55 ++++++++++++++++++++++++++-------------------------
 src/pacman/pacman.c   |  3 ++-
 src/pacman/sync.c     |  7 ++++---
 src/pacman/util.c     | 29 +++++++++++++++++----------
 src/pacman/util.h     |  4 ++--
 6 files changed, 57 insertions(+), 44 deletions(-)

diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 1e1a4cd..f7c69e2 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -436,7 +436,8 @@ void cb_question(alpm_question_t *question)
 							"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());
+				const colstr_t *colstr = &config->colstr;
+				list_display("     ", namelist, colstr->nocolor, getcols());
 				printf("\n");
 				q->skip = noyes(_n(
 							"Do you want to skip the above package for this upgrade?",
diff --git a/src/pacman/package.c b/src/pacman/package.c
index 3ab9abc..fab1a5c 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -148,14 +148,14 @@ static void make_aligned_titles(void)
  * @param deps a list with items of type alpm_depend_t
  */
 static void deplist_display(const char *title,
-		alpm_list_t *deps, unsigned short cols)
+		alpm_list_t *deps, const char *colour, unsigned short cols)
 {
 	alpm_list_t *i, *text = NULL;
 	for(i = deps; i; i = alpm_list_next(i)) {
 		alpm_depend_t *dep = i->data;
 		text = alpm_list_add(text, alpm_dep_compute_string(dep));
 	}
-	list_display(title, text, cols);
+	list_display(title, text, colour, cols);
 	FREELIST(text);
 }
 
@@ -256,29 +256,30 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
 	}
 
 	cols = getcols();
+	const colstr_t *colstr = &config->colstr;
 
 	/* actual output */
 	if(from == ALPM_PKG_FROM_SYNCDB) {
 		string_display(titles[T_REPOSITORY],
-				alpm_db_get_name(alpm_pkg_get_db(pkg)), cols);
+				alpm_db_get_name(alpm_pkg_get_db(pkg)), colstr->repo, cols);
 	}
-	string_display(titles[T_NAME], alpm_pkg_get_name(pkg), cols);
-	string_display(titles[T_VERSION], alpm_pkg_get_version(pkg), cols);
-	string_display(titles[T_DESCRIPTION], alpm_pkg_get_desc(pkg), cols);
-	string_display(titles[T_ARCHITECTURE], alpm_pkg_get_arch(pkg), cols);
-	string_display(titles[T_URL], alpm_pkg_get_url(pkg), cols);
-	list_display(titles[T_LICENSES], alpm_pkg_get_licenses(pkg), cols);
-	list_display(titles[T_GROUPS], alpm_pkg_get_groups(pkg), cols);
-	deplist_display(titles[T_PROVIDES], alpm_pkg_get_provides(pkg), cols);
-	deplist_display(titles[T_DEPENDS_ON], alpm_pkg_get_depends(pkg), cols);
+	string_display(titles[T_NAME], alpm_pkg_get_name(pkg), colstr->title, cols);
+	string_display(titles[T_VERSION], alpm_pkg_get_version(pkg), colstr->version, cols);
+	string_display(titles[T_DESCRIPTION], alpm_pkg_get_desc(pkg), colstr->nocolor, cols);
+	string_display(titles[T_ARCHITECTURE], alpm_pkg_get_arch(pkg), colstr->nocolor, cols);
+	string_display(titles[T_URL], alpm_pkg_get_url(pkg), colstr->nocolor, cols);
+	list_display(titles[T_LICENSES], alpm_pkg_get_licenses(pkg), colstr->nocolor, cols);
+	list_display(titles[T_GROUPS], alpm_pkg_get_groups(pkg), colstr->groups, cols);
+	deplist_display(titles[T_PROVIDES], alpm_pkg_get_provides(pkg), colstr->nocolor, cols);
+	deplist_display(titles[T_DEPENDS_ON], alpm_pkg_get_depends(pkg), colstr->nocolor, cols);
 	optdeplist_display(pkg, cols);
 
 	if(extra || from == ALPM_PKG_FROM_LOCALDB) {
-		list_display(titles[T_REQUIRED_BY], requiredby, cols);
-		list_display(titles[T_OPTIONAL_FOR], optionalfor, cols);
+		list_display(titles[T_REQUIRED_BY], requiredby, colstr->nocolor, cols);
+		list_display(titles[T_OPTIONAL_FOR], optionalfor, colstr->nocolor, cols);
 	}
-	deplist_display(titles[T_CONFLICTS_WITH], alpm_pkg_get_conflicts(pkg), cols);
-	deplist_display(titles[T_REPLACES], alpm_pkg_get_replaces(pkg), cols);
+	deplist_display(titles[T_CONFLICTS_WITH], alpm_pkg_get_conflicts(pkg), colstr->nocolor, cols);
+	deplist_display(titles[T_REPLACES], alpm_pkg_get_replaces(pkg), colstr->nocolor, cols);
 
 	size = humanize_size(alpm_pkg_get_size(pkg), '\0', 2, &label);
 	if(from == ALPM_PKG_FROM_SYNCDB) {
@@ -296,15 +297,15 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
 	printf("%s%s%s %.2f %s\n", config->colstr.title, titles[T_INSTALLED_SIZE],
 			config->colstr.nocolor, size, label);
 
-	string_display(titles[T_PACKAGER], alpm_pkg_get_packager(pkg), cols);
-	string_display(titles[T_BUILD_DATE], bdatestr, cols);
+	string_display(titles[T_PACKAGER], alpm_pkg_get_packager(pkg), colstr->nocolor, cols);
+	string_display(titles[T_BUILD_DATE], bdatestr, colstr->nocolor, cols);
 	if(from == ALPM_PKG_FROM_LOCALDB) {
-		string_display(titles[T_INSTALL_DATE], idatestr, cols);
-		string_display(titles[T_INSTALL_REASON], reason, cols);
+		string_display(titles[T_INSTALL_DATE], idatestr, colstr->nocolor, cols);
+		string_display(titles[T_INSTALL_REASON], reason, colstr->nocolor, cols);
 	}
 	if(from == ALPM_PKG_FROM_FILE || from == ALPM_PKG_FROM_LOCALDB) {
 		string_display(titles[T_INSTALL_SCRIPT],
-				alpm_pkg_has_scriptlet(pkg) ? _("Yes") : _("No"), cols);
+				alpm_pkg_has_scriptlet(pkg) ? _("Yes") : _("No"), colstr->nocolor, cols);
 	}
 
 	if(from == ALPM_PKG_FROM_SYNCDB && extra) {
@@ -321,25 +322,25 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
 			keys = alpm_list_add(keys, _("None"));
 		}
 
-		string_display(titles[T_MD5_SUM], alpm_pkg_get_md5sum(pkg), cols);
-		string_display(titles[T_SHA_256_SUM], alpm_pkg_get_sha256sum(pkg), cols);
-		list_display(titles[T_SIGNATURES], keys, cols);
+		string_display(titles[T_MD5_SUM], alpm_pkg_get_md5sum(pkg), colstr->nocolor, cols);
+		string_display(titles[T_SHA_256_SUM], alpm_pkg_get_sha256sum(pkg), colstr->nocolor, cols);
+		list_display(titles[T_SIGNATURES], keys, colstr->nocolor, cols);
 
 		if(base64_sig) {
 			FREELIST(keys);
 		}
 	} else {
-		list_display(titles[T_VALIDATED_BY], validation, cols);
+		list_display(titles[T_VALIDATED_BY], validation, colstr->nocolor, cols);
 	}
 
 	if(from == ALPM_PKG_FROM_FILE) {
 		alpm_siglist_t siglist;
 		int err = alpm_pkg_check_pgp_signature(pkg, &siglist);
 		if(err && alpm_errno(config->handle) == ALPM_ERR_SIG_MISSING) {
-			string_display(titles[T_SIGNATURES], _("None"), cols);
+			string_display(titles[T_SIGNATURES], _("None"), colstr->nocolor, cols);
 		} else if(err) {
 			string_display(titles[T_SIGNATURES],
-					alpm_strerror(alpm_errno(config->handle)), cols);
+					alpm_strerror(alpm_errno(config->handle)), colstr->err, cols);
 		} else {
 			signature_display(titles[T_SIGNATURES], &siglist, cols);
 		}
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index be52d1b..e42e9fa 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -1237,7 +1237,8 @@ int main(int argc, char *argv[])
 		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);
+		const colstr_t *colstr = &config->colstr;
+		list_display("Targets   :", pm_targets, colstr->nocolor, 0);
 	}
 
 	/* Log command line */
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 041b6b2..f2ca125 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -557,9 +557,10 @@ static int process_group(alpm_list_t *dbs, const char *group, int error)
 	if(config->print == 0) {
 		char *array = malloc(count);
 		int n = 0;
-		colon_printf(_n("There is %d member in group %s:\n",
-				"There are %d members in group %s:\n", count),
-				count, group);
+		const colstr_t *colstr = &config->colstr;
+		colon_printf(_n("There is %d member in group %s%s%s:\n",
+				"There are %d members in group %s%s%s:\n", count),
+				count, colstr->groups, group, colstr->title);
 		select_display(pkgs);
 		if(!array) {
 			ret = 1;
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 0862de0..0c0703f 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -473,7 +473,7 @@ static void add_transaction_sizes_row(alpm_list_t **rows, char *label, off_t siz
 	*rows = alpm_list_add(*rows, row);
 }
 
-void string_display(const char *title, const char *string, unsigned short cols)
+void string_display(const char *title, const char *string, const char *colour, unsigned short cols)
 {
 	if(title) {
 		printf("%s%s%s ", config->colstr.title, title, config->colstr.nocolor);
@@ -483,7 +483,10 @@ void string_display(const char *title, const char *string, unsigned short cols)
 	} else {
 		/* compute the length of title + a space */
 		size_t len = string_length(title) + 1;
-		indentprint(string, (unsigned short)len, cols);
+		char *clrd_str = NULL;
+		pm_asprintf(&clrd_str, "%s%s", colour, string);
+		indentprint(clrd_str, (unsigned short)len, cols);
+		free(clrd_str);
 	}
 	printf("\n");
 }
@@ -654,7 +657,7 @@ cleanup:
 }
 
 void list_display(const char *title, const alpm_list_t *list,
-		unsigned short maxcols)
+		const char *colour, unsigned short maxcols)
 {
 	const alpm_list_t *i;
 	size_t len = 0;
@@ -669,7 +672,9 @@ void list_display(const char *title, const alpm_list_t *list,
 	} else {
 		size_t cols = len;
 		const char *str = list->data;
-		fputs(str, stdout);
+		char *clrd_str = NULL;
+		pm_asprintf(&clrd_str, "%s%s", colour, str);
+		fputs(clrd_str, stdout);
 		cols += string_length(str);
 		for(i = alpm_list_next(list); i; i = alpm_list_next(i)) {
 			str = i->data;
@@ -687,10 +692,12 @@ void list_display(const char *title, const alpm_list_t *list,
 				printf("  ");
 				cols += 2;
 			}
-			fputs(str, stdout);
+			pm_asprintf(&clrd_str, "%s%s", colour, str);
+			fputs(clrd_str, stdout);
 			cols += s;
 		}
 		putchar('\n');
+		free(clrd_str);
 	}
 }
 
@@ -914,18 +921,19 @@ static void _display_targets(alpm_list_t *targets, int verbose)
 	}
 
 	/* print to screen */
-	pm_asprintf(&str, "%s (%zu)", _("Packages"), alpm_list_count(targets));
+	pm_asprintf(&str, "%s (%zu):", _("Packages"), alpm_list_count(targets));
 	printf("\n");
 
 	cols = getcols();
+	const colstr_t *colstr = &config->colstr;
 	if(verbose) {
 		header = create_verbose_header(alpm_list_count(targets));
 		if(table_display(header, rows, cols) != 0) {
 			/* fallback to list display if table wouldn't fit */
-			list_display(str, names, cols);
+			list_display(str, names, colstr->nocolor, cols);
 		}
 	} else {
-		list_display(str, names, cols);
+		list_display(str, names, colstr->nocolor, cols);
 	}
 	printf("\n");
 
@@ -1256,8 +1264,9 @@ static void display_repo_list(const char *dbname, alpm_list_t *list,
 {
 	const char *prefix = "  ";
 
-	colon_printf(_("Repository %s\n"), dbname);
-	list_display(prefix, list, cols);
+	const colstr_t *colstr = &config->colstr;
+	colon_printf(_("Repository %s%s\n"), colstr->repo, dbname);
+	list_display(prefix, list, colstr->nocolor, cols);
 }
 
 void select_display(const alpm_list_t *pkglist)
diff --git a/src/pacman/util.h b/src/pacman/util.h
index f5e37c8..86aa204 100644
--- a/src/pacman/util.h
+++ b/src/pacman/util.h
@@ -55,10 +55,10 @@ void columns_cache_reset(void);
 int rmrf(const char *path);
 void indentprint(const char *str, unsigned short indent, unsigned short cols);
 char *strreplace(const char *str, const char *needle, const char *replace);
-void string_display(const char *title, const char *string, unsigned short cols);
+void string_display(const char *title, const char *string, const char *colour, unsigned short cols);
 double humanize_size(off_t bytes, const char target_unit, int precision,
 		const char **label);
-void list_display(const char *title, const alpm_list_t *list,
+void list_display(const char *title, const alpm_list_t *list, const char *colour,
 		unsigned short maxcols);
 void list_display_linebreak(const char *title, const alpm_list_t *list,
 		unsigned short maxcols);
-- 
2.7.3


More information about the pacman-dev mailing list