#!/usr/bin/perl
######################################################################
# color.pl
######################################################################
# Perl Power! - Michael Schilli 1998
######################################################################

### Read colors and color text lines
open(COLORS, "< /usr/lib/X11/rgb.txt") || 
                       die "rgb.txt not found";
my $i=1;
while(<COLORS>) {

    s/!.*//;          # remove comments
    next if /^\s*$/;  # ignore empty lines

    my ($red, $green, $blue, $name) = split(' ', $_);
    my $col = sprintf("#%02x%02x%02x", $red, $green, $blue);

    ### labeling color white for dark background colors
    my $foreground = 
           ($red + $green + $blue < 350) ? "white" : "black";

    $text->insert("end", "$name\n");  # insert text into text
                                      # widget (including newline \n)

    ### Define tag and set color
    $text->tag("add", $i, "$i.0", sprintf("%d.0", $i+1));
    $text->tag("configure", $i, -background => $col, 
                                  -foreground => $foreground);

    ### Immediately display each new color
    $text->update();

    ### Refresh display
    $i++;
    $labelvar="Colors: $i";
}
close(COLORS);


