[pacman-dev] [PATCH 7/7] pacsearch: CLI option to turn off colors
Pierre Neidhardt
ambrevar at gmail.com
Wed Jan 22 18:07:09 EST 2014
Signed-off-by: Pierre Neidhardt <ambrevar at gmail.com>
---
contrib/pacsearch.in | 36 ++++++++++++++++++++++++------------
1 file changed, 24 insertions(+), 12 deletions(-)
diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in
index 180694b..21043d4 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`;
--
1.8.5.3
More information about the pacman-dev
mailing list