keyboard: categorise keys by result similarity
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 18 Jun 2017 12:58:01 +0000 (14:58 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 17 Jul 2017 15:13:44 +0000 (17:13 +0200)
keyboard.plp

index 92c2aa2..3a8f35f 100644 (file)
@@ -14,6 +14,7 @@ Html({
 
 <:
 use Shiar_Sheet::Keyboard 2.07;
+use Unicode::Normalize qw( NFKD );
 
 my $usint = [
        [  'a' ..                                            'z'],
@@ -26,7 +27,17 @@ my $usint = [
 my $keys = Shiar_Sheet::Keyboard->new({
        def => {
                '' => {
-                       map { $_ => '' } @{ $usint->[0] }
+                       map {
+                               my $c = $_;
+                               my @row = map { $usint->[$_]->[$c] } 0 .. 2;
+                               my $class = (
+                                         !defined $row[2] || $row[0] eq $row[2] ? 1 # identical
+                                       : NFKD($row[2]) =~ $row[0] ? 2 # equivalent
+                                       : $row[2] =~ /^\p{Latin}/ ? 3 # latin
+                                       : 4
+                               );
+                               $row[0] => "g$class"
+                       } 0 .. $#{ $usint->[0] }
                },
        },
        key => {
@@ -34,6 +45,12 @@ my $keys = Shiar_Sheet::Keyboard->new({
                        $usint->[0]->[$_] => "$usint->[1]->[$_]<br>$usint->[2]->[$_]"
                } 0 .. $#{ $usint->[0] }
        },
+       flag => {
+               g1 => ['unaltered'],
+               g2 => ['accented'],
+               g3 => ['latin'],
+               g4 => ['other'],
+       },
 });
 $keys->map($get{map}) or undef $get{map};
 $keys->print_rows($get{rows}, [0]);