Skip to content

Instantly share code, notes, and snippets.

@zoffixznet
Created January 1, 2020 01:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoffixznet/df5d813939ffd8d2a3fc8e7f9d172f99 to your computer and use it in GitHub Desktop.
Save zoffixznet/df5d813939ffd8d2a3fc8e7f9d172f99 to your computer and use it in GitHub Desktop.
if ($fg) {
$foreground = ($bb ? 'bright_' : '') . $fg;
# use Acme::Dump::And::Dumper;
# warn DnD [ $foreground ];
if ($foreground =~ /^rgb/) {
# %RGB_MAP
my ($r, $g, $b) = $foreground =~ /(\d)(\d)(\d)/;
$r = 255*$r/5; $r = 255 if $r > 255; $r = 0 if $r < 0;
$g = 255*$g/5; $g = 255 if $g > 255; $g = 0 if $g < 0;
$b = 255*$b/5; $b = 255 if $b > 255; $b = 0 if $b < 0;
my $wanted = sprintf "%02x%02x%02x", $r, $g, $b;
my $smallest_distance = 999999999999999;
my $smallest = 'green';
# use Acme::Dump::And::Dumper;
for (keys %RGB_MAP) {
# warn DnD [ Color::RGB::Util::rgb_distance($wanted, $_), $wanted, $_ ];
my $d = Color::RGB::Util::rgb_distance($wanted, $_);
if ($d < $smallest_distance) {
$smallest_distance = $d;
$smallest = $RGB_MAP{$_};
}
}
# warn DnD [$foreground, $r, $g, $b, $wanted, $smallest];
$foreground = $smallest;
# $foreground = 'green'; ### FIX FOR RGB
}
$set_color = "\cC$irccolors{$foreground}";
$bb = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment