From e4f6edf2374185c76a1f42a1aa6156d479bc6f40 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Thu, 23 Jan 2014 00:07:09 +0100 Subject: pacsearch: CLI option to turn off colors Signed-off-by: Pierre Neidhardt Signed-off-by: Allan McRae --- contrib/pacsearch.in | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'contrib') diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index 180694b6..21043d4c 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -19,8 +19,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -#TODO: colors flag on commandline - use strict; use warnings; use Term::ANSIColor; @@ -31,7 +29,9 @@ my $myver = '@PACKAGE_VERSION@'; sub usage { print "$myname (pacman) v$myver\n\n"; print "Perform a pacman search using both the local and the sync databases.\n\n"; - print "Usage: $myname \n\n"; + print "Usage: $myname [-n] \n\n"; + print "Options:\n"; + print " -n, --nocolor: turn off coloring\n\n"; print "Example: $myname ^gnome\n"; } @@ -55,16 +55,28 @@ if ($ARGV[0] eq "--version" || $ARGV[0] eq "-V") { exit 0; } -# define our colors to use when printing +# define formatting variables my($BLUE, $CYAN, $GREEN, $MAGENTA, $RED, $YELLOW, $BOLD, $RESET); -$BLUE = color('blue'); -$CYAN = color('cyan'); -$GREEN = color('green'); -$MAGENTA = color('magenta'); -$RED = color('red'); -$YELLOW = color('yellow'); -$BOLD = color('bold'); -$RESET = color('reset'); +if ($ARGV[0] eq "--nocolor" || $ARGV[0] eq "-n") { + shift; + $BLUE = ""; + $CYAN = ""; + $GREEN = ""; + $MAGENTA = ""; + $RED = ""; + $YELLOW = ""; + $BOLD = ""; + $RESET = ""; +} else { + $BLUE = color('blue'); + $CYAN = color('cyan'); + $GREEN = color('green'); + $MAGENTA = color('magenta'); + $RED = color('red'); + $YELLOW = color('yellow'); + $BOLD = color('bold'); + $RESET = color('reset'); +} # localization my $LC_INSTALLED = `gettext pacman installed`; -- cgit v1.2.3-54-g00ecf