From a291c591eb1ea7d8c4f27fc9c4d6333ef60672fd Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 5 Aug 2016 12:01:23 +0100 Subject: print text table in alternative to html --- dobble.pl | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'dobble.pl') diff --git a/dobble.pl b/dobble.pl index 324b3cd..84db265 100755 --- a/dobble.pl +++ b/dobble.pl @@ -96,7 +96,7 @@ package CardsTable { } } - sub table($self,$lines) { + sub html_table($self,$lines) { my @ret = (''); # this thing is isomorphic to its dual! we don't need to pivot @@ -120,6 +120,30 @@ package CardsTable { push @ret,'
'; 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'; @@ -172,9 +202,13 @@ say <<'HTML'; HTML -say for $table->table($plane->scan_lines)->@*; + say for $table->html_table($lines)->@*; -say <<'HTML'; + say <<'HTML'; HTML +} +else { + say for $table->text_table($lines)->@*; +} -- cgit v1.2.3