Skip to content

Commit

Permalink
Remove ANSIColor bright_ attribute for older perls
Browse files Browse the repository at this point in the history
Change on/off to always/never
  • Loading branch information
ingydotnet committed Jan 14, 2017
1 parent 44f0d68 commit bec2627
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
6 changes: 3 additions & 3 deletions doc/Pegex/Parser.swim
Expand Up @@ -96,21 +96,21 @@ variables:
(`bright_green` and `bright_red` respectively). Color will be enabled by
default for debugging. It requires [Term::ANSIColor].

- `on` or `1`
- `always` or `1`

Color is enabled.

- `auto`

Color is enabled when STDERR is a tty.

- `off` or 0
- `never` or 0

Color is disabled.

You can configure the specific colors used by appending them like this:

PERL_PEGEX_DEBUG_COLOR='on, cyan bold, black on_yellow'
PERL_PEGEX_DEBUG_COLOR='always, cyan bold, black on_yellow'

For available colors, see [Term::ANSIColor]

Expand Down
24 changes: 15 additions & 9 deletions lib/Pegex/Parser.pm
Expand Up @@ -41,26 +41,32 @@ sub BUILD {
or $self->{debug_indent} < 0
);

{
if ($self->{debug}) {
$self->{debug_color} //=
$ENV{PERL_PEGEX_DEBUG_COLOR} //
$Pegex::Parser::DebugColor // $self->{debug};
$Pegex::Parser::DebugColor // 1;
my ($got, $not);
($self->{debug_color}, $got, $not) = split / *, */, $self->{debug_color};
($self->{debug_color}, $got, $not) =
split / *, */, $self->{debug_color};
$got ||= 'bright_green';
$not ||= 'bright_red';
$_ = [split ' ', $_] for ($got, $not);
$self->{debug_got_color} = $got;
$self->{debug_not_color} = $not;
my $c = $self->{debug_color} // $self->{debug};
my $c = $self->{debug_color} // 1;
$self->{debug_color} =
$c eq 'on' ? 1 :
$c eq 'always' ? 1 :
$c eq 'auto' ? (-t STDERR ? 1 : 0) :
$c eq 'off' ? 0 :
$c eq 'never' ? 0 :
$c =~ /^\d+$/ ? $c : 0;
$self->{debug_color} and
eval {require v5.14; require Term::ANSIColor; 1} or
$self->{debug_color} = 0;
if ($self->{debug_color}) {
require Term::ANSIColor;
if ($Term::ANSIColor::VERSION < 3.00) {
s/^bright_// for
@{$self->{debug_got_color}},
@{$self->{debug_not_color}};
}
}
}
$self->{recursion_limit} //=
$ENV{PERL_PEGEX_RECURSION_LIMIT} //
Expand Down

0 comments on commit bec2627

Please sign in to comment.