File Coverage

lib/Devel/Trepan/DB/Colors.pm
Criterion Covered Total %
statement 17 18 94.4
branch 1 2 50.0
condition 1 3 33.3
subroutine 5 5 100.0
pod 0 1 0.0
total 24 29 82.7


line stmt bran cond sub pod time code
1             # Pretty much cut and paste from Syntax::Highlight::Perl's viewperl
2             package Devel::Trepan::DB::Colors;
3             =head1 NAME
4              
5             Devel::Trepan::DB::Colors - Set up L<Devel::Trepan>'s formatter to do ANSI colors.
6              
7             =cut
8              
9 14     14   91 use warnings; use strict;
  14     14   28  
  14         538  
  14         95  
  14         26  
  14         326  
10 14     14   13977 use Syntax::Highlight::Perl::Improved;
  14         265250  
  14         900  
11              
12 14     14   134 use vars qw(%ANSI_colors);
  14         33  
  14         10408  
13              
14             # See also Term::ANSIColor.
15             #
16             %ANSI_colors = (
17             none => "\e[0m",
18              
19             black => "\e[m",
20             red => "\e[0;31m",
21             green => "\e[0;32m",
22             yellow => "\e[0;33m",
23             blue => "\e[0;34m",
24             magenta => "\e[0;35m",
25             cyan => "\e[0;36m",
26             white => "\e[0;37m",
27              
28             gray => "\e[1;30m",
29             bred => "\e[1;31m",
30             bgreen => "\e[1;32m",
31             byellow => "\e[1;33m",
32             bblue => "\e[1;34m",
33             bmagenta => "\e[1;35m",
34             bcyan => "\e[1;36m",
35             bwhite => "\e[1;37m",
36              
37             bgred => "\e[41m",
38             bggreen => "\e[42m",
39             bgyellow => "\e[43m",
40             bgblue => "\e[44m",
41             bgmagenta => "\e[45m",
42             bgcyan => "\e[46m",
43             bgwhite => "\e[47m",
44             );
45              
46             sub setup
47             {
48 14     14 0 168 my $perl_formatter = new Syntax::Highlight::Perl::Improved;
49 14         4688 $perl_formatter->unstable(1);
50 14 50 33     225 if (scalar @_ && $_[0] eq 'darkbg') {
51             $perl_formatter->set_format(
52             'Comment_Normal' => [$ANSI_colors{'yellow'}, $ANSI_colors{'none'}],
53             'Comment_POD' => [$ANSI_colors{'yellow'}, $ANSI_colors{'none'}],
54             'Directive' => [$ANSI_colors{'magenta'}, $ANSI_colors{'none'}],
55             'Label' => [$ANSI_colors{'magenta'}, $ANSI_colors{'none'}],
56             'Quote' => [$ANSI_colors{'black'}, $ANSI_colors{'none'}],
57             'String' => [$ANSI_colors{'cyan'}, $ANSI_colors{'none'}],
58             'Subroutine' => [$ANSI_colors{'yellow'}, $ANSI_colors{'none'}],
59             'Variable_Scalar' => [$ANSI_colors{'green'}, $ANSI_colors{'none'}],
60             'Variable_Array' => [$ANSI_colors{'magenta'}, $ANSI_colors{'none'}],
61             'Variable_Hash' => [$ANSI_colors{'green'}, $ANSI_colors{'none'}],
62             'Variable_Typeglob'=> [$ANSI_colors{'black'}, $ANSI_colors{'none'}],
63             'Whitespace' => ['', '' ],
64             'Character' => [$ANSI_colors{'red'}, $ANSI_colors{'none'}],
65             'Keyword' => [$ANSI_colors{'yellow'}, $ANSI_colors{'none'}],
66             'Builtin_Function' => [$ANSI_colors{'grey'}, $ANSI_colors{'none'}],
67             'Builtin_Operator' => [$ANSI_colors{'white'}, $ANSI_colors{'none'}],
68             'Operator' => [$ANSI_colors{'white'}, $ANSI_colors{'none'}],
69             'Bareword' => [$ANSI_colors{'grey'}, $ANSI_colors{'none'}],
70             'Package' => [$ANSI_colors{'green'}, $ANSI_colors{'none'}],
71             'Number' => [$ANSI_colors{'magenta'}, $ANSI_colors{'none'}],
72             'Symbol' => [$ANSI_colors{'cyan'}, $ANSI_colors{'none'}],
73             'CodeTerm' => [$ANSI_colors{'gray'}, $ANSI_colors{'none'}],
74             'DATA' => [$ANSI_colors{'gray'}, $ANSI_colors{'none'}],
75              
76             'Line' => [$ANSI_colors{'byellow'}, $ANSI_colors{'none'}],
77             'File_Name' => [$ANSI_colors{'red'} . $ANSI_colors{'bgwhite'},
78 0         0 $ANSI_colors{'none'}],);
79             } else {
80             $perl_formatter->set_format(
81             'Comment_Normal' => [$ANSI_colors{'red'}, $ANSI_colors{'none'}],
82             'Comment_POD' => [$ANSI_colors{'bblue'}, $ANSI_colors{'none'}],
83             'Directive' => [$ANSI_colors{'magenta'}, $ANSI_colors{'none'}],
84             'Label' => [$ANSI_colors{'bblue'}, $ANSI_colors{'none'}],
85             'Quote' => [$ANSI_colors{'black'}, $ANSI_colors{'none'}],
86             'String' => [$ANSI_colors{'gray'}, $ANSI_colors{'none'}],
87             'Subroutine' => [$ANSI_colors{'blue'}, $ANSI_colors{'none'}],
88             'Variable_Scalar' => [$ANSI_colors{'bgreen'}, $ANSI_colors{'none'}],
89             'Variable_Array' => [$ANSI_colors{'magenta'}, $ANSI_colors{'none'}],
90             'Variable_Hash' => [$ANSI_colors{'bgreen'}, $ANSI_colors{'none'}],
91             'Variable_Typeglob'=> [$ANSI_colors{'black'}, $ANSI_colors{'none'}],
92             'Whitespace' => ['', '' ],
93             'Character' => [$ANSI_colors{'bred'}, $ANSI_colors{'none'}],
94             'Keyword' => [$ANSI_colors{'bblue'}, $ANSI_colors{'none'}],
95             'Builtin_Function' => [$ANSI_colors{'bwhite'}, $ANSI_colors{'none'}],
96             'Builtin_Operator' => [$ANSI_colors{'black'}, $ANSI_colors{'none'}],
97             'Operator' => [$ANSI_colors{'black'}, $ANSI_colors{'none'}],
98             'Bareword' => [$ANSI_colors{'white'}, $ANSI_colors{'none'}],
99             'Package' => [$ANSI_colors{'green'}, $ANSI_colors{'none'}],
100             'Number' => [$ANSI_colors{'gray'}, $ANSI_colors{'none'}],
101             'Symbol' => [$ANSI_colors{'gray'}, $ANSI_colors{'none'}],
102             'CodeTerm' => [$ANSI_colors{'gray'}, $ANSI_colors{'none'}],
103             'DATA' => [$ANSI_colors{'gray'}, $ANSI_colors{'none'}],
104              
105             'Line' => [$ANSI_colors{'byellow'}, $ANSI_colors{'none'}],
106             'File_Name' => [$ANSI_colors{'red'} . $ANSI_colors{'bgwhite'},
107 14         509 $ANSI_colors{'none'}],
108             );
109             }
110 14         2702 $perl_formatter;
111             }
112              
113             unless (caller) {
114             my $perl_formatter = Devel::Trepan::DB::Colors::setup();
115             my $colors_file = __FILE__;
116             open my $fh, "<", __FILE__ or die "Why can't I read myself?: $!";
117             local $/; # enable localized slurp mode
118             my $content = <$fh>;
119             close $fh;
120             print $perl_formatter->format_string($content);
121              
122             }