[pacman-dev] [PATCH] Updated pacsearch colors to match pacman's coloring

Pierre Neidhardt ambrevar at gmail.com
Tue Jan 7 09:16:49 EST 2014


For now I've kept the original pacsearch colors for the repos. Some fields have
the same colors--e.g. 'extra' and 'version' are both bold green. Maybe it would
look nicer to make repo/name bold and to leave the other fields regular.

Additionally I have rephrased the help message; the previous message would let
one think this script was rather useless compared to a simple pacman -Ss.

Signed-off-by: Pierre Neidhardt <ambrevar at gmail.com>
---
 contrib/pacsearch.in | 58 ++++++++++++++++++++++++++++++----------------------
 1 file changed, 34 insertions(+), 24 deletions(-)

diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in
index 624f201..a580d85 100644
--- a/contrib/pacsearch.in
+++ b/contrib/pacsearch.in
@@ -20,6 +20,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #TODO: colors flag on commandline
+#TODO: for now the whole line is bold and some parts have the same formatting (e.g. extra and version), maybe it would be better to use regular formatting
 
 use strict;
 use warnings;
@@ -29,7 +30,7 @@ my $myver = '@PACKAGE_VERSION@';
 
 sub usage {
 	print "$myname (pacman) v$myver\n\n";
-	print "Add color and install information to a 'pacman -Ss' search\n\n";
+	print "Perform a pacman search using both the local and the sync databases.\n\n";
 	print "Usage: $myname <pattern>\n\n";
 	print "Example: $myname ^gnome\n";
 }
@@ -54,32 +55,41 @@ if ($ARGV[0] eq "--version" || $ARGV[0] eq "-V") {
 	exit 0;
 }
 
-# define our colors to use when printing
-my $CLR1 = "\e[0;34m";
-my $CLR2 = "\e[0;32m";
-my $CLR3 = "\e[0;35m";
-my $CLR4 = "\e[0;36m";
-my $CLR5 = "\e[0;31m";
-my $CLR6 = "\e[0;33m";
-my $CLR7 = "\e[1;36m";
-my $INST = "\e[1;31m";
-my $BASE = "\e[0m";
-
-# color a "repo/pkgname pkgver" line based on the repository name
+# define our colors to use when printing; we try to stick to pacman colors
+my $CLR_CORE = "\e[1;94m"; # blue
+my $CLR_EXTRA = "\e[1;92m"; # green
+my $CLR_COMMUNITY = "\e[1;95m"; # magenta
+my $CLR_TESTING = "\e[1;96m"; # cyan
+my $CLR_COMMUNITY_TESTING = "\e[1;91m"; # red
+my $CLR_MULTILIB = "\e[1;93m"; # yello
+my $CLR_LOCAL = "\e[1;96m"; # cyan
+my $CLR_INST = "\e[1;96m"; # cyan
+my $CLR_PACKAGE = "\e[1m"; # bold
+my $CLR_VERSION = "\e[1;92m"; # green
+my $CLR_GROUP = "\e[1;94m"; # blue
+my $CLR_BASE = "\e[0m";
+
+# color a "repo/pkgname pkgver (goups) [installed]" line
 sub to_color {
 	my $line = shift;
-	# get the installed text colored first
-	$line =~ s/(\[.*\]$)/$INST$1$BASE/;
-	# and now the repo and dealings
-	$line =~ s/(^core\/.*)/$CLR1$1$BASE/;
-	$line =~ s/(^extra\/.*)/$CLR2$1$BASE/;
-	$line =~ s/(^community\/.*)/$CLR3$1$BASE/;
-	$line =~ s/(^testing\/.*)/$CLR4$1$BASE/;
-	$line =~ s/(^community-testing\/.*)/$CLR5$1$BASE/;
-	$line =~ s/(^multilib\/.*)/$CLR6$1$BASE/;
-	$line =~ s/(^local\/.*)/$CLR7$1$BASE/;
+	# get the installed text colored first (between square brackets)
+	$line =~ s/(\[.*\]$)/$CLR_INST$1$CLR_BASE/;
+    # group (between parentheses)
+    $line =~ s/(\(.*\))/$CLR_GROUP$1$CLR_BASE/;
+    # version (second field)
+    $line =~ s/^([^ ]+) ([^ ]+) /$1 $CLR_VERSION$2$CLR_BASE /;
+    # name (word after slash)
+    $line =~ s/\/([\w-]*)/\/$CLR_PACKAGE$1$CLR_BASE/;
+	# repo (word before slash inclusive)
+	$line =~ s/(^core\/)/$CLR_CORE$1$CLR_BASE/;
+	$line =~ s/(^extra\/)/$CLR_EXTRA$1$CLR_BASE/;
+	$line =~ s/(^community\/)/$CLR_COMMUNITY$1$CLR_BASE/;
+	$line =~ s/(^testing\/)/$CLR_TESTING$1$CLR_BASE/;
+	$line =~ s/(^community-testing\/)/$CLR_COMMUNITY_TESTING$1$CLR_BASE/;
+	$line =~ s/(^multilib\/)/$CLR_MULTILIB$1$CLR_BASE/;
+	$line =~ s/(^local\/)/$CLR_LOCAL$1$CLR_BASE/;
 	# any other unknown repository
-	$line =~ s/(^[\w-]*\/.*)/$CLR6$1$BASE/;
+	$line =~ s/(^[\w-]*\/)/$CLR_MULTILIB$1$CLR_BASE/;
 	return $line;
 }
 
-- 
1.8.5.2



More information about the pacman-dev mailing list