vi: generic function to print entire help legends
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 18 Jun 2017 11:59:27 +0000 (13:59 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 17 Jul 2017 15:13:44 +0000 (17:13 +0200)
Replace setup of help container consisting of left type legend (ordered .g*)
and right options legend (other flags and provided user options) as it is
identical on all other keyboard pages.

Shiar_Sheet/Keyboard.pm
vi.eng.inc.pl
vi.plp

index c5fdb09fdb7fa37bc28272c8f25ac2c21931195b..44ecc4d67adbbdf9bb2e3ccd3c14372850e1fcf0 100644 (file)
@@ -6,7 +6,7 @@ use warnings;
 no  warnings 'uninitialized';  # save some useless checks for more legible code
 use Carp;
 
-our $VERSION = 'v2.06';
+our $VERSION = '2.07';
 
 my @casedesc = (undef, qw/shift ctrl meta/, 'shift meta');
 my @rowdesc = qw(numeric top home bottom);
@@ -36,6 +36,9 @@ sub new {
                \%Shiar_Sheet::KeySigns::sign;
        };
 
+       $self->{showkeys} = $PLP::Script::showkeys;
+       $self->{style   } = $PLP::Script::style;
+
        bless $self, $class;
 }
 
@@ -185,11 +188,43 @@ sub print_legend {
        my $self = shift;
        my ($class, $flags) = @_;
 
-       print qq{\t\t<dl class="legend $class">\n};
+       say qq{\t\t<dl class="legend $class">};
        printf("\t\t".'<dt class="%s">%s'."\n\t\t\t".'<dd>%s'."\n",
                $_, map { $self->escapedesc($_) } @{ $self->{flag}->{$_} || ["($_)", '...'] }
        ) for @$flags;
-       print "\t\t</dl>";
+       say "\t\t</dl>";
+}
+
+sub print_legends {
+       my $self = shift;
+       my ($input) = @_;
+
+       say "<hr/>\n";
+       say '<div class="help">';
+
+       say "\t", '<div class="left">';
+       my @groups = sort grep {/^g\d/} keys %{ $self->{flag} };
+       $self->print_legend('legend-types', \@groups);
+       say "\t</div>\n";
+
+       say "\t", '<div class="right">';
+       my @attr = sort grep {!/^g\d/} keys %{ $self->{flag} };
+       $self->print_legend('legend-options', \@attr);
+       say '';
+
+       say "\t\t", '<ul class="legend legend-set">';
+
+       say "\t\t<li>keyboard <strong>map</strong> is ",
+               ($input->{map} ? 'set to ' : ''), "<em>$self->{map}</em>";
+       say "\t\t<li><strong>keys</strong> are ",
+               "<em>", ($self->{showkeys} ? 'always shown' : 'hidden if unassigned'), "</em>",
+               (!defined $self->{showkeys} && ' by default');
+       say "\t\t<li>default <strong>style</strong> is ",
+               (defined $input->{style} && 'set to '), "<em>$self->{style}</em>";
+
+       say "\t\t</ul>";
+       say "\t</div>\n";
+       say "</div>\n";
 }
 
 1;
index 77c6acc9c021c0824194f685d813396afa70c3ed..823bbfe4306c6c4d40420ab8bd575debb6197597 100644 (file)
@@ -472,8 +472,8 @@ flag => {
 
        arg => ["key<arg>", "Commands with a dot need a char argument afterwards."],
        motion => ["key<motion>", "Requires a motion afterwards, operates between cursor and destination."],
-       'ext vim6' => ["vim", "Not in original Vi (assessment incomplete)."],
-       'ext new vim7' => ["vim7", "New in vim version 7.x."],
+       'vim6 ext' => ["vim", "Not in original Vi (assessment incomplete)."],
+       'vim7 ext new' => ["vim7", "New in vim version 7.x."],
 },
 
 def => {
diff --git a/vi.plp b/vi.plp
index 203fdc8c39051812e773a38aad72ec1c65097f52..9a115803b2d4c8dab08aa670f54ee59f853b2a88 100644 (file)
--- a/vi.plp
+++ b/vi.plp
@@ -20,36 +20,10 @@ Html({
 <h2>normal mode (default)</h2>
 
 <:
-use Shiar_Sheet::Keyboard 2;
+use Shiar_Sheet::Keyboard 2.07;
 my $info = do 'vi.eng.inc.pl' or die $@;
 my $keys = Shiar_Sheet::Keyboard->new($info);
 $keys->map($get{map}) or undef $get{map};
 $keys->print_rows($get{rows});
-:>
-
-<hr>
-
-<div class="help">
-       <div class="left">
-<:
-               $keys->print_legend('legend-types', ['g1' .. 'g4', 'g6' .. 'g9']);
-:>
-       </div>
-
-       <div class="right">
-<:
-               $keys->print_legend('legend-options', [qw'arg motion', 'ext vim6', 'ext new vim7']);
-:>
-
-               <ul class="legend legend-set">
-               <li>keyboard <strong>map</strong> is
-                       <:= $get{map} ? 'set to ' : '' :><em><:= $keys->{map} :></em>
-               <li><strong>keys</strong> are
-                       <em><:= $showkeys ? 'always shown' : 'hidden if unassigned' :></em><:=
-                               !defined $showkeys && ' by default' :>
-               <li>default <strong>style</strong> is
-                       <:= defined $get{style} && 'set to ' :><em><:= $style :></em>
-               </ul>
-       </div>
-</div>
+$keys->print_legends(\%get);