[Pgp-tools-commit] r797 - in trunk: caff debian

Guilhem Moulin guilhem-guest at moszumanska.debian.org
Fri Apr 10 17:04:48 UTC 2015


Author: guilhem-guest
Date: 2015-04-10 17:04:48 +0000 (Fri, 10 Apr 2015)
New Revision: 797

Modified:
   trunk/caff/caff
   trunk/debian/changelog
Log:
caff: Enable color customization via $CONFIG{colors}.

Modified: trunk/caff/caff
===================================================================
--- trunk/caff/caff	2015-04-10 17:04:42 UTC (rev 796)
+++ trunk/caff/caff	2015-04-10 17:04:48 UTC (rev 797)
@@ -183,6 +183,19 @@
 
 Base directory for the files caff stores.  Default: B<$HOME/.caff/>.
 
+=item B<colors> [hash]
+
+How to color output messages.  Colored output can be disabled by setting
+this option to an empty hash B<{}>.  Default:
+
+	{ error => 'bold bright_red'
+	, warn => 'bright_red'
+	, notice => 'bold'
+	, info => ''
+	, success => 'green' # used in combination with 'notice' and 'info'
+	, fail => 'yellow'   # used in combination with 'notice' and 'info'
+	}
+
 =back
 
 =head2 GnuPG settings
@@ -433,24 +446,31 @@
 # @param $exitcode exit code status to use to end the program
 # @param $line     error message to display on STDERR
 #
+sub mycolored($@) {
+	my $msg = shift;
+	my $color = join (' ', grep defined, map { defined $_ ? $CONFIG{colors}->{$_} : undef } @_) if defined $CONFIG{colors};
+	$msg = colored($msg, $color) if defined $color and $color !~ /^\s*$/;
+	return $msg;
+}
 sub myerror($$) {
 	my ($exitcode, $line) = @_;
-	print STDERR colored("[ERROR] $line", 'bold bright_red'), "\n";
+	print STDERR mycolored("[ERROR] $line", 'error'), "\n";
 	exit $exitcode;
 };
 
 sub mywarn($) {
 	my ($line) = @_;
-	print STDERR colored("[WARN] $line", 'bright_red'), "\n";
+	print STDERR mycolored("[WARN] $line", 'warn'), "\n";
 };
 sub notice($;$) {
 	my ($line,$color) = @_;
-	$color = !defined $color ? 'bold' : $color ? 'bold green' : 'bold yellow';
-	print STDERR colored("[NOTICE] $line", $color), "\n";
+	$color = $color ? 'success' : 'fail' if defined $color;
+	print STDERR mycolored("[NOTICE] $line", 'notice', $color), "\n";
 };
 sub info($$) {
 	my ($line,$color) = @_;
-	print STDERR colored("[INFO] $line", $color ? 'green' : 'yellow'), "\n";
+	$color = $color ? 'success' : 'fail' if defined $color;
+	print STDERR mycolored("[INFO] $line", 'info', $color), "\n";
 };
 sub debug($) {
 	my ($line) = @_;
@@ -609,6 +629,15 @@
 	myerror(1, "$0: invalid value for 'also-lsign-in-gnupghome': $CONFIG{'also-lsign-in-gnupghome'}")
 		unless grep { $_ eq $CONFIG{'also-lsign-in-gnupghome'} } qw/auto ask no/;
 	$CONFIG{'show-photos'} //= 0;
+
+	$CONFIG{colors} //= {
+		error => 'bold bright_red',
+		warn => 'bright_red',
+		notice => 'bold',
+		info => '',
+		success => 'green',
+		fail => 'yellow'
+  };
 };
 
 # Create a new GnuPG::Interface object with common options

Modified: trunk/debian/changelog
===================================================================
--- trunk/debian/changelog	2015-04-10 17:04:42 UTC (rev 796)
+++ trunk/debian/changelog	2015-04-10 17:04:48 UTC (rev 797)
@@ -21,7 +21,9 @@
       only those for which the UID is exported.  This is useful when the
       signee has some already signed RFC 2822 UIDs and a freshly added
       attribute, for instance.
-    + Use Term::ANSIColor to produce colored output.
+    + Use Term::ANSIColor to produce fancy colored output.  Can be configured
+      by setting $CONFIG{colors} to a suitable hash; in particular setting
+      $CONFIG{colors} = {} reverts to the old uncolored output.
     + Prune keys with import-{clean,minimal} not export-{clean,minimal}.
     + Fix $CONFIG{'also-lsign-in-gnupghome'}: local signatures are directly
       imported from caff's GNUPGHOME to our own; in auto-lsign'ing mode, lsign




More information about the Pgp-tools-commit mailing list