]> Dogcows Code - chaz/git-codeowners/commitdiff
allow shorter color codes
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Fri, 8 Nov 2019 03:29:18 +0000 (20:29 -0700)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Fri, 8 Nov 2019 03:29:18 +0000 (20:29 -0700)
bin/git-codeowners
dist.ini
lib/App/Codeowners.pm

index e620ea8bb416d02cb08fbae884b35ffbb5647212..d565192c139cbdab4874d539c34384418bb0a4f8 100755 (executable)
@@ -42,6 +42,17 @@ Alias: C<-h>
 
 You can also use C<--manual> to print the full documentation.
 
+=head2 --color
+
+Enable colorized output.
+
+Color is ON by default on terminals; use C<--no-color> to disable. Some environment variables may
+also alter the behavior of colorizing output:
+
+=for :list
+* C<NO_COLOR> - Set to disable color (same as C<--no-color>).
+* C<COLOR_DEPTH> - Set the number of supportable colors (e.g. 0, 16, 256, 16777216).
+
 =head2 --format
 
 Specify the output format to use. See L</FORMAT>.
@@ -98,7 +109,30 @@ The C<--format> argument can be one of:
 * C<yaml> - YAML (requires L<YAML>)
 * C<FORMAT> - Custom format (see below)
 
-You can specify a custom format using printf-like format sequences.
+You can specify a custom format using printf-like format sequences. These are the items that can
+substituted:
+
+=for :list
+* C<%F> - Filename
+* C<%O> - Owner or owners
+* C<%P> - Project
+* C<%T> - Pattern
+* C<%n> - newline
+* C<%t> - tab
+* C<%%> - percent sign
+
+The syntax also allows padding and some filters. Examples:
+
+    git-codeowners show -f ' * %-50F %O'                # default for "show"
+    git-codeowners show -f '%{quote}F,%{quote}O'        # ad hoc CSV
+    git-codeowners patterns -f '--> %{color:0c0}T'      # whatever...
+
+Available filters:
+
+=for :list
+* C<quote> - Quote the replacement string.
+* C<color:FFFFFF> - Colorize the replacement string (if color is ON).
+* C<nocolor> - Do not colorize replacement string.
 
 =cut
 
index c1f4b4125fb5322e23543a2b31ad27c99431e82c..c7fe9e69be063e7e01400182f6efacdf8eb54bfc 100644 (file)
--- a/dist.ini
+++ b/dist.ini
@@ -21,7 +21,8 @@ remove_runtime      = Text::Table
 remove_runtime      = Unicode::GCString
 remove_runtime      = YAML
 [Prereqs / RuntimeRecommends]
-Unicode::GCString   = 0
+Unicode::GCString       = 0
+Term::Detect::Software  = 0
 [Prereqs / RuntimeSuggests]
 JSON::MaybeXS       = 0
 Text::CSV           = 0
index eebe058be5e9e61a1d6ecb29e0f8f8a4f406b698..efe86f7e88e428bb76108d78c17183300844b12e 100644 (file)
@@ -275,7 +275,7 @@ sub _expand_filter_args {
 
     for (my $i = 0; $i < @filters; ++$i) {
         my $filter = $filters[$i] or next;
-        if ($filter =~ /^(?:nocolor|color:([0-9a-fA-F]{6}))$/) {
+        if ($filter =~ /^(?:nocolor|color:([0-9a-fA-F]{3,6}))$/) {
             $color_override = $1 || '';
             splice(@filters, $i, 1);
             redo;
@@ -292,6 +292,12 @@ sub _colored {
     # ansifg honors NO_COLOR already, but ansi_reset does not.
     return $text if $ENV{NO_COLOR};
 
+    $rgb =~ s/^(.)(.)(.)$/$1$1$2$2$3$3/;
+    if ($rgb !~ m/^[0-9a-fA-F]{6}$/) {
+        warn "Color value must be in 'ffffff' or 'fff' form.\n";
+        return $text;
+    }
+
     my ($begin, $end) = (ansifg($rgb), ansi_reset);
     return "${begin}${text}${end}";
 }
This page took 0.022819 seconds and 4 git commands to generate.