Skip to content

Commit cb2f899

Browse files
Clean up code a bit
1 parent 595fdc7 commit cb2f899

File tree

1 file changed

+17
-29
lines changed

1 file changed

+17
-29
lines changed

third_party/term-colors/term-colors.pl

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/perl
22

33
use strict;
4+
use warnings;
45

56
my $args = join(" ",@ARGV);
67
my ($perl) = $args =~ /--perl/;
@@ -19,16 +20,10 @@
1920
#print "TERM::ANSIColor constant names:\n";
2021
term_ansicolor();
2122
} else {
22-
my $cols = 120;
23-
my $rows = 24;
24-
if (-f '/bin/stty') {
25-
($rows,$cols) = split(/ /,`/bin/stty size`);
26-
}
27-
2823
my $section = 1;
2924
my $grouping = 8;
3025

31-
for (my $i=0;$i<256;$i++) {
26+
for (my $i = 0; $i < 256; $i++) {
3227
print set_bcolor($i); # Set the background color
3328

3429
if (needs_white($i)) {
@@ -40,7 +35,7 @@
4035
}
4136

4237
print set_fcolor(); # Reset both colors
43-
print " "; # Seperators
38+
print " "; # Seperator
4439

4540
if ($i == 15 || $i == 231) {
4641
print set_bcolor(); # Reset
@@ -65,7 +60,6 @@ END
6560

6661
sub has_term_ansicolor {
6762
my $version = shift();
68-
$version ||= 4;
6963

7064
eval {
7165
# Check if we have Term::ANSIColor version 4.0
@@ -100,19 +94,6 @@ sub set_bcolor {
10094
return $ret;
10195
}
10296

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-
11697
sub get_color_mapping {
11798
my $map = {};
11899

@@ -196,16 +177,23 @@ sub get_color_names {
196177
}
197178

198179
sub needs_white {
199-
my $num = shift();
200-
201180
# 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
203182
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
204183
27 61 62 64 160 196 161 126 63 94 95 100 101 127 128 129 12 130 131 23 24);
205184

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; }
210196
}
197+
198+
return 0;
211199
}

0 commit comments

Comments
 (0)