keyboard: altgr css for single-glyph keys
[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 my $showkeys //= !exists $get{keys} ? undef :
11         ($get{keys} ne '0' && ($get{keys} || 'always'));
12 my @keystyle = (
13         '<!--[if lte IE 6]><style> .help dl.legend dt {margin:0 0 1px} </style><![endif]-->',
14         '<!--[if lte IE 7]><style> .help dl.legend dd {float:none} </style><![endif]-->',
15         !$showkeys ? '<style> .no {visibility:hidden} </style>' :
16         $showkeys eq 'ghost' ? '<style> .no, .alias {opacity:.5} </style>' : (),
17         '<script type="text/javascript" src="/keys.js?1.6" async></script>',
18 );
19 if ($include =~ /^altgr/ and open my $cssinc, '<', 'keyboard-altgr.css') {
20         local $/;
21         my $data = readline $cssinc;
22         push @keystyle, "<style>\n$data</style>";
23 }
24
25 Html({
26         title => "\L$mode\E keyboard cheat sheet",
27         version => $info->{version} || '0.1',
28         description => $info->{description} //
29                 ["Keyboard cheat sheet for the default controls of $mode."],
30         keywords => [@{ $info->{keywords} // [] }, qw'
31                 sheet cheat reference overview keyboard control commands shortkey
32         '],
33         stylesheet => [qw( light dark circus mono red )],
34         data => ["$include.inc.pl"],
35         raw => \@keystyle,
36 });
37
38 %{$info} or Abort(
39         "Requested keyboard <q>$mode</q> not available",
40         '404 request not found',
41 );
42
43 say "<h1>$mode cheat sheet</h1>";
44 say "<p>$_</p>" for $info->{intro} // ();
45 say "<h2>", $info->{mode}->{''}, " (default)</h2>"
46         if $info->{mode} and %{ $info->{mode} } > 1;
47
48 use Shiar_Sheet::Keyboard 2.08;
49 my $keys = Shiar_Sheet::Keyboard->new($info);
50 $keys->map($get{map}) or undef $get{map};
51 $keys->print_rows($get{rows} || $info->{moderows}, $info->{rows});
52
53 {
54         say "<hr/>\n";
55         say '<div class="help">';
56
57         use List::MoreUtils qw( part );
58         my @gflags = part {/^g\d/} sort keys %{ $keys->{flag} };
59
60         say "\t", '<div class="left">';
61         $keys->print_legend('legend-types', $gflags[1]);
62         say "\t</div>\n";
63
64         say "\t", '<div class="right">';
65         $keys->print_legend('legend-options', $gflags[0]);
66         say '';
67
68         say "\t\t", '<ul class="legend legend-set">';
69
70         say "\t\t<li>keyboard <strong>map</strong> is ",
71                 ($get{map} ? 'set to ' : ''), "<em>$keys->{map}</em>";
72         say "\t\t<li><strong>keys</strong> are ",
73                 "<em>", ($showkeys ? 'always shown' : 'hidden if unassigned'), "</em>",
74                 (!defined $showkeys && ' by default');
75         say "\t\t<li>default <strong>style</strong> is ",
76                 (defined $get{style} && 'set to '), "<em>$style</em>";
77
78         say "\t\t</ul>";
79         say "\t</div>\n";
80         say "</div>\n";
81 }