X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/f91fd6d772ee8ea35f833802c9f8cc1db75ca950..3efe0eca82fa7f9c0fd125ff25f42901bc7133c8:/Shiar_Sheet/Keyboard.pm diff --git a/Shiar_Sheet/Keyboard.pm b/Shiar_Sheet/Keyboard.pm index aecd0bc..0ccd9c2 100644 --- a/Shiar_Sheet/Keyboard.pm +++ b/Shiar_Sheet/Keyboard.pm @@ -1,11 +1,12 @@ package Shiar_Sheet::Keyboard; +use 5.010; use strict; use warnings; no warnings 'uninitialized'; # save some useless checks for more legible code use Carp; -our $VERSION = 'v2.03'; +our $VERSION = 'v2.05'; my @casedesc = (undef, qw/shift ctrl meta/, 'shift meta'); my @rowdesc = qw(numeric top home bottom); @@ -31,7 +32,7 @@ sub new { $self->{sign} ||= do { require Shiar_Sheet::KeySigns; - Shiar_Sheet::KeySigns->VERSION(1.03); + Shiar_Sheet::KeySigns->VERSION(1.04); \%Shiar_Sheet::KeySigns::sign; }; @@ -64,6 +65,13 @@ sub escapehtml { return $_; } +sub escapedesc { + my $self = shift; + local $_ = shift; + s{ (< ([^>]*) >) }{ $self->{sign}->{$2} // $1 }xeg; + return $_; +} + sub keyunalias { my $self = shift; my ($key, $ancestry) = @_; @@ -73,7 +81,7 @@ sub keyunalias { my $keyinfo = $self->{def}->{$mode}->{$key}; return unless defined $keyinfo; - return $keyinfo->[0] if ref $keyinfo; + $keyinfo =~ s/^=// or return $keyinfo; return '' if $ancestry->{$key}++; # endless loop failsafe return $self->keyunalias($keyinfo, $ancestry); } @@ -81,18 +89,18 @@ sub keyunalias { sub print_key { my $self = shift; my ($mode, $key, $flags) = @_; + my ($desc, $mnem); if (not defined $flags) { - $flags = [$key eq '^0' ? 'ni' : 'no']; + $flags = $key eq '^0' ? 'ni' : 'no'; } - elsif (not ref $flags) { # alias - my $desc = $self->{sign}->{alias}; + elsif ($flags =~ s/^=//) { # alias + $desc = $self->{sign}->{alias}; $desc .= $flags eq "\e" ? 'esc' : $flags; - $flags = [$self->keyunalias($flags) . ' alias', $desc]; + $flags = $self->keyunalias($flags) . ' alias'; } - my ($flags, $desc, $mnem) = @{$flags}; if (my $txt = $self->{key}->{$mode.$key}) { - ($desc, $mnem) = split /\n/, $txt; + ($desc, $mnem) = split /\n/, $self->escapedesc($txt); } # $key = $keytrans{$key} if defined $keytrans{$key}; @@ -117,11 +125,13 @@ sub print_key { sub print_rows { my $self = shift; + my ($rowsspec, $defrows) = @_; + $defrows ||= [2, 1, 0]; my %moderows = ( - -DEFAULT => !@_ ? '' : split(/(?:\s*([^=\s]*)=\s*)/, shift), + -DEFAULT => defined $rowsspec && $rowsspec ne '' && + split(/\s* ([^=\s]*) = \s*/x, $rowsspec), # plus specific mode overrides prefixed by '=' ); - my $defrows = shift || [2, 1, 0]; my @modes = sort keys %{ $self->{def} }; print ''."\n\n"; @@ -133,7 +143,7 @@ sub print_rows { for my $basemode (@modes) { my @moderows = split /\s+/, $row < 0 ? "0" : - defined $moderows{$basemode} ? $moderows{$basemode} : $moderows{-DEFAULT}; + $moderows{$basemode} // $moderows{-DEFAULT}; for my $submode (@moderows ? @moderows : '') { my $mode = $basemode . $submode; @@ -154,7 +164,7 @@ sub print_rows { ' class="%s"', join ' ', @caseclass ); printf('', # XXX insert   here to fix msie<=6 - $self->{mode}->{$mode} || "mode $basemode", + $self->escapedesc($self->{mode}->{$mode} || "mode $basemode"), "$rowdesc[$row] row $casedesc[$case]" ) unless $row < 0; print "\n"; @@ -177,7 +187,7 @@ sub print_legend { print qq{\t\t
\n}; printf("\t\t".'
%s'."\n\t\t\t".'
%s'."\n", - $_, @{ $self->{flag}->{$_} || ["($_)", '...'] } + $_, map { $self->escapedesc($_) } @{ $self->{flag}->{$_} || ["($_)", '...'] } ) for @$flags; print "\t\t
"; } @@ -195,8 +205,8 @@ Shiar_Sheet::Keyboard - Output HTML for key sheets my $keys = Shiar_Sheet::Keyboard({ def => { 'lead' => { - 'A' => 'a', # alias - 'a' => ['classes'], + 'A' => '=a', # alias + 'a' => 'classes', }, }, key => {
%s: %s