diff options
-rwxr-xr-x | dobble.pl | 42 |
1 files changed, 38 insertions, 4 deletions
@@ -96,7 +96,7 @@ package CardsTable { } } - sub table($self,$lines) { + sub html_table($self,$lines) { my @ret = ('<table>'); # this thing is isomorphic to its dual! we don't need to pivot @@ -120,6 +120,30 @@ package CardsTable { push @ret,'</table>'; return \@ret; } + + sub text_table($self,$lines) { + my @ret = (); + + # this thing is isomorphic to its dual! we don't need to pivot + # lines/points, it's all the same + + for my $line (sort keys $lines->%*) { + my @row; + for my $point ($lines->{$line}->@*) { + + my $symbol = $self->symbol_for($point); + my $column = $symbol->[1]; + $row[$column] = $symbol->[0]; + } + my $string = '';; + for my $s (@row) { + next unless $s or $self->padding; + $string .= $s||' '; + } + push @ret, $string; + } + return \@ret; + } }; sub load_symbols($file) { @@ -142,6 +166,10 @@ my ($opt,$usage) = describe_options( [ 'padding|p!', 'vertically align symbols', { default => 0 } ], [ 'symbols|s=s', 'string of symbols (one per character)' ], [ 'symbols-from|f=s', 'file with one symbol per line' ], + [ 'format' => hidden => { one_of => [ + [ 'html|H' => 'output HTML document' ], + [ 'text|T' => 'output plain text' ], + ], default => 'html' } ], [], ['help|h', 'show this help text', { shortcircuit => 1 } ], ); @@ -163,7 +191,9 @@ if ((my $actual = $table->symbols->@*) < $needed) { die "For order $order, we need $needed symbols, but we only have $actual; please pass a (larger) file to --symbols\n"; } -say <<'HTML'; +my $lines = $plane->scan_lines; +if ($opt->format eq 'html') { + say <<'HTML'; <html> <head> <meta http-equiv="Content-type" content="text/html;charset=utf-8"> @@ -172,9 +202,13 @@ say <<'HTML'; <body> HTML -say for $table->table($plane->scan_lines)->@*; + say for $table->html_table($lines)->@*; -say <<'HTML'; + say <<'HTML'; </body> </html> HTML +} +else { + say for $table->text_table($lines)->@*; +} |