termcol: reindent table handling code
[sheet.git] / termcol.plp
index 26a5c70e4343d71a343484ee7a91f3a1e6c30624..3880a62ecd46bca9ff202616ba3ecd1032df0661 100644 (file)
@@ -127,34 +127,33 @@ sub coltable {
                $caption,
        ) if $info->{href} or $info->{title};
 
-       if (my $mapinfo = $info->{rgbmap}) {
+       if ($info->{table} or $info->{rgbmap}) {
                say '<table class="color mapped">';
                say sprintf '<caption>%s</caption>', $caption;
-               print coltable_hsv(@{$mapinfo});
-               say "</table>\n";
-       }
 
-       if (my $table = $info->{table}) {
-               say '<table class="color mapped">';
-               say sprintf '<caption>%s</caption>', $caption;
-               for my $row (@$table) {
-                       if (!$row) {
-                               say '<tbody>';
-                               next;
+               print coltable_hsv(@{$_}) for $info->{rgbmap} || ();
+
+               if (my $table = $info->{table}) {
+                       for my $row (@$table) {
+                               if (!$row) {
+                                       say '<tbody>';
+                                       next;
+                               }
+                               print '<tr>';
+                               print colcell(ref $_ ? @$_ : $_ ? reverse split /:/ : undef) for @$row;
                        }
-                       print '<tr>';
-                       print colcell(ref $_ ? @$_ : $_ ? reverse split /:/ : undef) for @$row;
-               }
 
-       if (@draw) {
-               my $width = scalar @{ $table->[0] };
-               my @imgpal = map {
-                       [ ref $_ ? @{$_}[1 .. 3] : map {hex} /(..)(..)(..)/ ]
-               } map { @{$_} } @{$table};
-               for (@draw) {
-                       print "<tr><td colspan=$width>", img_egapal(\@imgpal, @{$_});
+                       if (@draw) {
+                               my $width = scalar @{ $table->[0] };
+                               my @imgpal = map {
+                                       [ ref $_ ? @{$_}[1 .. 3] : map {hex} /(..)(..)(..)/ ]
+                               } map { @{$_} } @{$table};
+                               for (@draw) {
+                                       print "<tr><td colspan=$width>", img_egapal(\@imgpal, @{$_});
+                               }
+                       }
                }
-       }
+
                say "</table>\n";
        }