termcol: optional preset for xcolors include
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 2 May 2017 19:39:55 +0000 (21:39 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 29 May 2017 17:23:11 +0000 (19:23 +0200)
Avoid load unless needed.

termcol.inc.pl
termcol.plp

index bf0001bab25d830c62ea1d8db1c20407e3cbdaf2..6e3b6d697e106b3470fdbdb8e3df661465cdf790 100644 (file)
@@ -7,6 +7,12 @@ use Shiar_Sheet::Colour 1.05;
        ansi    => [qw( cga putty xterm tango app html cgarne )],
        legacy  => [qw( c64 msx mac2 risc arnegame dawnbringer cpc cpcboy shiar32 ppu 64 )],
 
+       xcolors => sub {
+               my $pals = do 'termcol-xcolor.inc.pl' or die $! || $@;
+               $_[0]->{$_} = $pals->{$_} for keys %{$pals};
+               return 'xcolor';
+       },
+
        html => {
                title => 'HTML keywords (inherited by CSSā‰„2.1 and SVG), mostly identical to X11',
                href => 'http://www.w3.org/TR/css3-color/#html4',
index bd9fd538f8117860593facfafecb8d588bf6625c..26a5c70e4343d71a343484ee7a91f3a1e6c30624 100644 (file)
@@ -46,8 +46,6 @@ use POSIX qw( ceil );
 
 my $palettes = do 'termcol.inc.pl';
 die "Cannot open palette data: $_\n" for $@ || $! || ();
-my $more = do 'termcol-xcolor.inc.pl' || {};
-$palettes = {%$palettes, %$more};
 
 sub colcell {
        my $name = shift // return "<td>\n";
@@ -108,6 +106,12 @@ sub coltable {
 
        if (ref $info eq 'ARRAY') {
                coltable($_) for @{$info};
+               return;
+       }
+
+       if (ref $info eq 'CODE') {
+               coltable($_) for $info->($palettes);
+               return;
        }
 
        ref $info eq 'HASH' or return;