X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/f467c45a5d41e959e438028ab7df4946fab93d30..c4ca0bd3e94a7978772dadaa3b941ecc84741407:/Shiar_Sheet/Keyboard.pm
diff --git a/Shiar_Sheet/Keyboard.pm b/Shiar_Sheet/Keyboard.pm
index 2ab838e..47c1cf0 100644
--- a/Shiar_Sheet/Keyboard.pm
+++ b/Shiar_Sheet/Keyboard.pm
@@ -6,7 +6,7 @@ use warnings;
no warnings 'uninitialized'; # save some useless checks for more legible code
use Carp;
-our $VERSION = '2.07';
+our $VERSION = '3.00';
my @casedesc = (undef, qw/shift ctrl meta/, 'shift meta');
my @rowdesc = qw(numeric top home bottom);
@@ -56,6 +56,7 @@ sub escapeclass {
s/\+/_m/g;
s/\[/_sbo/g;
s/\]/_sbc/g;
+ s/\\/_b/g;
s/^$/_/;
return $_;
}
@@ -79,12 +80,13 @@ sub keyunalias {
my $self = shift;
my ($key, $ancestry) = @_;
- $key =~ s/(\S*?)(\+?\^?\S)($|\s.*)/$2/;
+ $key =~ s/(\S*?)(\+?\^?\S$)/$2/;
my $mode = $1;
my $keyinfo = $self->{def}->{$mode}->{$key};
return unless defined $keyinfo;
- $keyinfo =~ s/^=// or return $keyinfo;
+ return $keyinfo unless ref $keyinfo eq 'SCALAR';
+ $keyinfo = ${$keyinfo};
return '' if $ancestry->{$key}++; # endless loop failsafe
return $self->keyunalias($keyinfo, $ancestry);
}
@@ -104,20 +106,28 @@ sub print_letter {
sub print_key {
my $self = shift;
- my ($mode, $key, $flags) = @_;
- my ($desc, $mnem);
+ my ($mode, $key, $def) = @_;
- if (not defined $flags) {
- $flags = $key eq '^0' ? 'ni' : 'no';
+ if (not defined $def) {
+ $def = [$key eq '^0' ? 'ni' : 'no'];
}
- elsif ($flags =~ s/^=//) { # alias
- $desc = $self->{sign}->{alias};
- $desc .= $flags eq "\e" ? 'esc' : $flags;
- $flags = $self->keyunalias($flags) . ' alias';
+ elsif (ref $def eq 'SCALAR') {
+ $def = [undef, $def];
}
- if (my $txt = $self->{key}->{$mode.$key}) {
- ($desc, $mnem) = split /\n/, $self->escapedesc($txt);
+ if (ref $def ne 'ARRAY') {
+ carp "print_key: invalid definition for $mode$key: $def";
+ return;
}
+ my ($flags, $txt) = @{$def};
+ if (ref $txt eq 'SCALAR') {
+ my $ref = ${$txt};
+ $def = $self->keyunalias($ref);
+ $ref = 'esc' if $ref eq "\e";
+ $flags //= $def->[0] if ref $def eq 'ARRAY';
+ $txt = $self->{sign}->{alias} . $ref;
+ $flags .= ' alias';
+ }
+ my ($desc, $mnem) = split /\n/, $self->escapedesc($txt);
my $keytxt = $self->print_letter($key, $mode);
$keytxt .= "$self->{sign}->{motion}" if $flags =~ s/ ?\bargm\b//; # motion argument
@@ -149,11 +159,16 @@ sub print_rows {
);
my @modes = sort keys %{ $self->{def} };
- print '
'."\n\n";
+ printf ''."\n\n", $self->{tableclass} // 'keys';
+print_row:
for (my $row = -1; $row <= $#{ $keyrows{$self->{map}} }; $row++) {
my $keyrow = $row < 0 ? [["\e"]] : $keyrows{$self->{map}}->[$row];
+# grep {
+# defined $self->{def}->{''}->{$_} or defined $self->{def}->{g}->{$_}
+# } map { @{$_} } @{$keyrow} or next;
+
printf qq{\n}, $row+1;
for my $basemode (@modes) {
my @moderows = split /\s+/,
@@ -162,8 +177,8 @@ sub print_rows {
for my $submode (@moderows ? @moderows : '') {
my $mode = $basemode . $submode;
- my @caserows = $mode =~ s/(\d+)(?:-(\d+))?$//
- ? (map {$_ - 1} split //, $row == 0 && $2 || $1) # user override
+ my @caserows = $mode =~ s/(\d+)(?:-(\d*))?$//
+ ? (map {$_ - 1} split //, $row == 0 ? $2 // $1 : $1) # user override
: @$defrows; # default
my $modekeys = $self->{def}{$mode};
@@ -201,44 +216,12 @@ sub print_legend {
my ($class, $flags) = @_;
say qq{\t\t};
- printf("\t\t".'- %s'."\n\t\t\t".'
- %s'."\n",
+ printf("\t\t".'
- %s'."\n\t\t\t".'
- %s
'."\n",
$_, map { $self->escapedesc($_) } @{ $self->{flag}->{$_} || ["($_)", '...'] }
) for @$flags;
say "\t\t
";
}
-sub print_legends {
- my $self = shift;
- my ($input) = @_;
-
- say "
\n";
- say '';
-
- say "\t", '
';
- my @groups = sort grep {/^g\d/} keys %{ $self->{flag} };
- $self->print_legend('legend-types', \@groups);
- say "\t
\n";
-
- say "\t", '
';
- my @attr = sort grep {!/^g\d/} keys %{ $self->{flag} };
- $self->print_legend('legend-options', \@attr);
- say '';
-
- say "\t\t", '
';
-
- say "\t\t- keyboard map is ",
- ($input->{map} ? 'set to ' : ''), "$self->{map}";
- say "\t\t
- keys are ",
- "", ($self->{showkeys} ? 'always shown' : 'hidden if unassigned'), "",
- (!defined $self->{showkeys} && ' by default');
- say "\t\t
- default style is ",
- (defined $input->{style} && 'set to '), "$self->{style}";
-
- say "\t\t
";
- say "\t
\n";
- say "
\n";
-}
-
1;
=head1 NAME
@@ -252,13 +235,10 @@ 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', 'description', 'hover comments'],
},
},
- key => {
- 'leada' => ['description', 'comments (on hover)'],
- },
mode => {
'lead' => 'mode description',
},
@@ -269,7 +249,7 @@ Shiar_Sheet::Keyboard - Output HTML for key sheets
=head1 DESCRIPTION
-Used by http://sheet.shiar.nl to display keyboard sheets.
+Used by https://sheet.shiar.nl to display keyboard sheets.
Assumes specific stylesheets and javascript from this site,
so probably not of much use elsewhere.