summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Neidhardt <ambrevar@gmail.com>2014-01-23 00:07:09 +0100
committerAllan McRae <allan@archlinux.org>2014-02-02 16:12:29 +1000
commite4f6edf2374185c76a1f42a1aa6156d479bc6f40 (patch)
tree4b3d5b79696ac65f69b31bb22719f5b0bff89130
parent1e07af1b0a16d9f8e42a76d00de8558e49cb57b7 (diff)
downloadpacman-e4f6edf2374185c76a1f42a1aa6156d479bc6f40.tar.xz
pacsearch: CLI option to turn off colors
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
-rw-r--r--contrib/pacsearch.in36
1 files changed, 24 insertions, 12 deletions
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 <http://www.gnu.org/licenses/>.
-#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 <pattern>\n\n";
+ print "Usage: $myname [-n] <pattern>\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`;