X-Git-Url: http://git.shiar.net/sheet.git/blobdiff_plain/25c42c7d1649e85339b165f205e620b8eadf6e7b..133e96335267b12bb7e97d9bbe551a3a043bd32a:/Shiar_Sheet/Keyboard.pm?ds=inline diff --git a/Shiar_Sheet/Keyboard.pm b/Shiar_Sheet/Keyboard.pm index bf25477..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.09'; +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/^=(\S+)\s?//) { # alias - my $ref = $1; - $desc = $self->{sign}->{alias} . ($ref eq "\e" ? 'esc' : $ref); - $flags = join ' ', $self->keyunalias($ref), 'alias', $flags; + 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,7 +159,7 @@ sub print_rows { ); my @modes = sort keys %{ $self->{def} }; - print '