keyboard: custom rows overrides in moderows attribute
[sheet.git] / keyboard.plp
1 <(common.inc.plp)><:
2
3 my $mode = lc($Request || 'altgr');
4 my $include = "$mode.eng";
5
6 my $info = eval { Data($include) } || {};
7 warn "error in $include: ", @{$@} if ref $@;
8 $mode = $info->{title} // $mode;
9
10 Html({
11         title => "\L$mode\E keyboard cheat sheet",
12         version => $info->{version} || '0.1',
13         description => $info->{description} //
14                 ["Keyboard cheat sheet for the default controls of $mode."],
15         keywords => [@{ $info->{keywords} // [] }, qw'
16                 sheet cheat reference overview keyboard control commands shortkey
17         '],
18         stylesheet => [qw( light dark circus mono red )],
19         keys => 1,
20         data => ["$include.inc.pl"],
21 });
22
23 %{$info} or Abort(
24         "Requested keyboard <q>$mode</q> not available",
25         '404 request not found',
26 );
27
28 say "<h1>$mode cheat sheet</h1>";
29 say "<p>$_</p>" for $info->{intro} // ();
30 say "<h2>", $info->{mode}->{''}, " (default)</h2>"
31         if $info->{mode} and %{ $info->{mode} } > 1;
32
33 use Shiar_Sheet::Keyboard 2.08;
34 my $keys = Shiar_Sheet::Keyboard->new($info);
35 $keys->map($get{map}) or undef $get{map};
36 $keys->print_rows($get{rows} || $info->{moderows}, $info->{rows});
37
38 {
39         say "<hr/>\n";
40         say '<div class="help">';
41
42         use List::MoreUtils qw( part );
43         my @gflags = part {/^g\d/} sort keys %{ $keys->{flag} };
44
45         say "\t", '<div class="left">';
46         $keys->print_legend('legend-types', $gflags[1]);
47         say "\t</div>\n";
48
49         say "\t", '<div class="right">';
50         $keys->print_legend('legend-options', $gflags[0]);
51         say '';
52
53         say "\t\t", '<ul class="legend legend-set">';
54
55         say "\t\t<li>keyboard <strong>map</strong> is ",
56                 ($get{map} ? 'set to ' : ''), "<em>$keys->{map}</em>";
57         say "\t\t<li><strong>keys</strong> are ",
58                 "<em>", ($showkeys ? 'always shown' : 'hidden if unassigned'), "</em>",
59                 (!defined $showkeys && ' by default');
60         say "\t\t<li>default <strong>style</strong> is ",
61                 (defined $get{style} && 'set to '), "<em>$style</em>";
62
63         say "\t\t</ul>";
64         say "\t</div>\n";
65         say "</div>\n";
66 }