|
1 | 1 | #!/usr/bin/perl
|
2 | 2 |
|
3 | 3 | use strict;
|
| 4 | +use warnings; |
4 | 5 |
|
5 | 6 | my $args = join(" ",@ARGV);
|
6 | 7 | my ($perl) = $args =~ /--perl/;
|
|
19 | 20 | #print "TERM::ANSIColor constant names:\n";
|
20 | 21 | term_ansicolor();
|
21 | 22 | } else {
|
22 |
| - my $cols = 120; |
23 |
| - my $rows = 24; |
24 |
| - if (-f '/bin/stty') { |
25 |
| - ($rows,$cols) = split(/ /,`/bin/stty size`); |
26 |
| - } |
27 |
| - |
28 | 23 | my $section = 1;
|
29 | 24 | my $grouping = 8;
|
30 | 25 |
|
31 |
| - for (my $i=0;$i<256;$i++) { |
| 26 | + for (my $i = 0; $i < 256; $i++) { |
32 | 27 | print set_bcolor($i); # Set the background color
|
33 | 28 |
|
34 | 29 | if (needs_white($i)) {
|
|
40 | 35 | }
|
41 | 36 |
|
42 | 37 | print set_fcolor(); # Reset both colors
|
43 |
| - print " "; # Seperators |
| 38 | + print " "; # Seperator |
44 | 39 |
|
45 | 40 | if ($i == 15 || $i == 231) {
|
46 | 41 | print set_bcolor(); # Reset
|
|
65 | 60 |
|
66 | 61 | sub has_term_ansicolor {
|
67 | 62 | my $version = shift();
|
68 |
| - $version ||= 4; |
69 | 63 |
|
70 | 64 | eval {
|
71 | 65 | # Check if we have Term::ANSIColor version 4.0
|
@@ -100,19 +94,6 @@ sub set_bcolor {
|
100 | 94 | return $ret;
|
101 | 95 | }
|
102 | 96 |
|
103 |
| -sub highlight_string { |
104 |
| - my $needle = shift(); |
105 |
| - my $haystack = shift(); |
106 |
| - my $color = shift() || 2; # Green if they don't pass in a color |
107 |
| - |
108 |
| - my $fc = set_fcolor($color); |
109 |
| - my $reset = set_fcolor(); |
110 |
| - |
111 |
| - $haystack =~ s/$needle/$fc.$needle.$reset/e; |
112 |
| - |
113 |
| - return $haystack; |
114 |
| -} |
115 |
| - |
116 | 97 | sub get_color_mapping {
|
117 | 98 | my $map = {};
|
118 | 99 |
|
@@ -196,16 +177,23 @@ sub get_color_names {
|
196 | 177 | }
|
197 | 178 |
|
198 | 179 | sub needs_white {
|
199 |
| - my $num = shift(); |
200 |
| - |
201 | 180 | # Sorta lame, but it's a hard coded list of which background colors need a white foreground
|
202 |
| - my @white = qw(0 1 4 5 8 232 233 234 235 236 237 238 239 240 241 242 243 16 17 18 |
| 181 | + my @needs_white = qw(0 1 4 5 8 232 233 234 235 236 237 238 239 240 241 242 243 16 17 18 |
203 | 182 | 19 20 21 22 28 52 53 54 55 25 56 57 58 59 60 88 89 90 91 92 93 124 125 29 30 31 26
|
204 | 183 | 27 61 62 64 160 196 161 126 63 94 95 100 101 127 128 129 12 130 131 23 24);
|
205 | 184 |
|
206 |
| - if (grep(/\b$num\b/,@white)) { |
207 |
| - return 1, |
208 |
| - } else { |
209 |
| - return 0; |
| 185 | + my $num = shift(); |
| 186 | + my $ret = in_array($num, @needs_white); |
| 187 | + |
| 188 | + return $ret; |
| 189 | +} |
| 190 | + |
| 191 | +sub in_array { |
| 192 | + my ($needle, @haystack) = @_; |
| 193 | + |
| 194 | + foreach my $l (@haystack) { |
| 195 | + if ($l == $needle) { return 1; } |
210 | 196 | }
|
| 197 | + |
| 198 | + return 0; |
211 | 199 | }
|
0 commit comments