formatchar: highlight by unicode range if no digraphs
[sheet.git] / unicode.plp
index 4d935549f01c70bb853d65f46d7e9ea64f2ac0cb..71499530bf12c15f9e5233d1b31314247012a36f 100644 (file)
-<:
-use utf8;
-use strict;
-use warnings;
-no  warnings 'qw';  # that's not a comment, it's a NUMBER SIGN
-use open IO => ':utf8';
-
-our $VERSION = '1.0';
-
-$header{content_type} = 'text/html; charset=utf-8';
-
-:><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
- "http://www.w3.org/TR/html4/loose.dtd">
-<html>
-
-<head>
-<title>digraph cheat sheet</title>
-<meta http-equiv="content-type" content="utf-8">
-<link rel="stylesheet" type="text/css" media="all" href="/digraphs.css">
-</head>
-
-<body>
-<h1>Common uncommon Unicode</h1>
-
-<p>i^k in <a href="/">Vim</a>.
-Also see the <a href="/digraphs">complete digraphs table</a>.</p>
+<(common.inc.plp)><:
+
+Html({
+       title => 'unicode glyph cheat sheet',
+       version => 'v1.0',
+       description => [
+               "Common Unicode characters with digraph or code point, layed out for quick location.",
+               "Includes general symbols, arrows, drawing characters, and IPA letters.",
+       ],
+       keywords => [qw'
+               unicode glyph char character reference common ipa symbol sign mark table digraph
+       '],
+       stylesheet => [qw'light dark red'],
+});
+
+:>
+<h1>Common Unicode</h1>
+
+<p>
+Glyphs are followed by
+<a href="/digraphs">digraph</a> or <a href="/charset">code point</a>,
+i^k or i^vu respectively in <a href="/vi">Vim</a>.
+</p>
 
 <div class="diinfo">
 
 <:
-my $diinfo = do 'digraphs.inc.pl';
-my %di = map { $diinfo->{$_}->[0] => $_ } grep { ref $diinfo->{$_} }
-       keys %$diinfo;
+use Shiar_Sheet::FormatChar;
+my $glyphs = Shiar_Sheet::FormatChar->new;
 
-sub quote {
-       local $_ = shift;
-       s/"/&quot;/g;
-       s/</&lt;/g;
-       s/>/&gt;/g;
-       return $_;
+if (exists $get{di}) {
+       $glyphs->{digraph} = defined $get{di} ? ! !$get{di} : 1;
+       $glyphs->{unicode} = 1;
 }
-
-sub glyph_table {
-       my ($digraphs) = @_;
-
-       my @rows;
-
-       my @colheads;
-       while ($digraphs->[0] !~ /^\./) {
-               my $cell = shift @$digraphs or last;
-               push @colheads, sprintf(
-                       '<%s%s>%s',
-                       $cell =~ s/^-// ? 'td' : 'th',
-                       $cell =~ s/:(.*)// ? qq{ title="$1"} : '',
-                       $cell eq '_' ? '&nbsp;' : $cell
-               );
-       }
-       push @rows, sprintf '<thead><tr>%s<tbody>', join '', @colheads if @colheads;
-
-       my $colspan = 1;
-       for my $cell (@$digraphs) {
-               if ($cell =~ s/^\.//) {
-                       # dot indicates start of a new row
-                       push @rows, '';
-                       if ($cell =~ s/^>//) {
-                               # header cell text follows
-                               $cell =~ s/_/ /g;  # underscores may be used instead of whitespace (for qw//ability)
-                               $rows[-1] .= '<th>'.($cell || '&nbsp;');
-                       }
-                       next;
-               }
-               elsif ($cell eq '>') {
-                       # merge this cell to the next column
-                       $colspan++;
-                       next;
-               }
-
-               my $code = join '', map { $di{ord $_} || '' } split //, $cell;
-               my $name = $diinfo->{$code}->[1];
-
-               # determine display class
-               my @class;
-               if ($cell eq '-') {
-                       $cell = '';
-               }
-               elsif ($cell eq '=') {
-                       push @class, 'di-invalid';
-                       $cell = '';
-               }
-               else {
-                       if ($cell =~ s/^-//) {
-                               push @class, 'di-rare'; # discouraged
-                       }
-
-                       if ($code) {
-                               push @class, 'di-d'; # digraph
-                               push @class, 'di-prop' # unofficial
-                                       if $diinfo->{$code}->[2] =~ /\bXz\b/;
-                       }
-
-                       if ($cell =~ /[ -~]/) {
-                               push @class, 'di-a'; # ascii
-                       }
-                       else {
-                               push @class, 'di-b'; # basic unicode
-                       }
-               }
-
-               # add cell html
-               $rows[-1] .= sprintf('<td%s%s%s>%s%s',
-                       defined $name  ? qq{ title="$name"}  : '',
-                       @class ? sprintf(' class="%s"', join ' ', @class) : '',
-                       $colspan > 1 && qq{ colspan="$colspan"},
-                       $cell eq '' ? '&nbsp;' : quote($cell),
-                       $code ne '' ? sprintf(' <small class="digraph">%s</small>', quote($code))
-                               : length($cell) == 1 && $cell !~ /[a-z]/
-                                       ? sprintf(' <small class="%s">%04X</small>', 'value', ord $cell)
-                                       : '',
-               );
-
-               $colspan = 1;
-       }
-
-       return sprintf qq{<table class="glyphs dilabel">\n%s</table>\n},
-               join '', map {"<tr>$_\n"} @rows;
+if (exists $get{q}) {
+       $glyphs->{unicode} = -1;
+       $glyphs->{digraph}--;
 }
 
-sub print_glyph_tables {
-       while (@_) {
-               printf "<div><h2>%s</h2>\n\n", shift;
-               while (ref $_[0] and $_ = shift) {
-                       print glyph_table($_);
-               }
-               print '</div>';
-       }
-}
+our $verbose = exists $get{v};
 
-print_glyph_tables(
+$glyphs->print(
        'Popular',
-       [qw{. « » . ‹ › . ‘ ’ . “ ” . „ ‚}],
-       [qw{. † ‡ • . § ¶ # . © ® ™ . − × ÷ . ± ² √}],
-       [qw{. å ä ö ü ß . Å æ ø ű ſ}],
-       [qw{. ¿ ç ñ é ê è}],
+       [qw{. « » . ‹ › . ‘ ’ . “ ” . „ ‚ . ‟ ‛}],
+       [qw{. † ‡ • . § ¶ # . © ® ™ . ° ′ ″ . − × ÷ . ± ² √}],
+       [qw{. ⚋ ⚊ . ⚐ ⚑ . ☺ ☹ . ✓ ✗ . ✔ ✘ }, $verbose ? () : qw{. ◄ ►}],
+       [qw{. å ä ö ü ß . ā æ ø ű ſ}],
+       [qw{
+               . á è õ û ç . ą ı ơ ů þ
+       }],
+       $verbose ? [qw{
+               .>Englisc   æ ð ē ȝ œ þ ƿ
+               .>Sámi      á č đ ŋ š ŧ ž
+               .>Slavic    ą ě ł ů ź ż ž
+               .>Türkçe    ç ğ ı İ ö ş ü
+               .>Esperanto ĉ ĝ ĥ ĵ ŝ ŭ
+       }] : (),
+       [qw{. α β}],
+       [qw{. ¿ … 〃 ‐ – . ‽ · ※ ‒ — }],
+
+       'Symbols',
+       [qw{. ¤ ¢ ₥ € £ ₨ $ ¥ . ฿ ₫ ₭ ₦ ₱ ₮ ₩ ₪}],
+       [qw{. ♠ ♡ ♢ ♣ . ♤ ♥ ♦ ♧}],
+       [qw{. ☮ ☯ ☻ ♪ ♲ ♿ }],
+       [qw{. ✂ ✉ ℻ ☎ ☏}, $verbose ? qw{. 🔞 🔾 🔰 🔮 🕀 } : ()], # communication
+       [qw{. ✊ ✋ ✌ }, $verbose ? qw{. 🖹 🐜 👼 } : ()], # 3-way (RockPaperScissors, TerranProtossZerg)
+       [qw{. ⚠ ☡ ☠}],
+       'Signs',
+       [qw{. ☉ ☿ ♀ ♁ ♂ ♃ ♄ ♅ ♆ ♇}],  # solar
+       [qw{
+               . ♈ ♉ ♊ ♋ ♌ ♍ ♎ ♏ ♐ ♑ ♒ ♓
+       }, !$verbose ? () : qw{
+               . 寅 卯 辰 巳 午 未 申 酉 戌 亥 子 丑
+               . 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬 鼠 牛
+               . 🐅 🐇 🐉 🐍 🐎 🐐 🐒 🐓 🐕 🐖 🐀 🐂
+       }], # zodiac
+
+       'Key commands',
+       [qw{. ⇥ ⇤ . ␣ ⌫ }], # common spacing
+       [qw{. ⎀ ⇱ ⇞ . ⌦ ⇲ ⇟ }], # edit block
+       [qw{. ⇪ ⇯ ⇭ . ⇧ ⇮ № }], # modifier
+       [qw{. ⎈ ⌥ ⌘ ⎄ }], [qw{. ↵ ⎋ ⎉ ⎊ }], # command
+$verbose ? (
+       [qw{. ► ⏩ ⏭ ◼ ⚫ . ◄ ⏪ ⏮ ⏏ -❚❚ }], # player ui
+) : (),
 
        'Arrows',
        [qw{. ↖ ↑ ↗ ↔ . ← - → ↕ . ↙ ↓ ↘ -}],
        [qw{. ⇖ ⇑ ⇗ ⇔ . ⇐ - ⇒ ⇕ . ⇙ ⇓ ⇘ -}],
-       [qw{. ◤ ▲ ◥ . ◀ ◆ ▶ . ◣ ▼ ◢}],
-       [qw{. ◸ △ ◹ . ◁ ◇ ▷ . ◺ ▽ ◿}],
+       [qw{. ⬁ ⇧ ⬀ ⬄ . ⇦ - ⇨ ⇳ . ⬃ ⇩ ⬂ -}],
+       [qw{. ⬉ ⬆ ⬈ ⬌ . ⬅ - ➡ ⬍ . ⬋ ⬇ ⬊ -}],
+       [qw{. ◩ ⬒ ⬔   . ◧ □ ◨   . ⬕ ⬓ ◪  }],
+       [qw{. ◤ ▲ ◥   . ◀ ◆ ▶   . ◣ ▼ ◢  }],
+       [qw{. ◸ △ ◹   . ◁ ◇ ▷   . ◺ ▽ ◿  }],
+$verbose ? (
+       [qw{.    .  -  .    }],
+       [qw{.    .  -  .    }],
+) : (),
 
        'Line drawing',
+       [qw{. ╔ ╦ ╗ ═ . ╠ ╬ ╣ ║ . ╚ ╩ ╝ - }],
+       [qw{. ╒ ╤ ╕ . ╞ ╪ ╡ . ╘ ╧ ╛ }],
+       [qw{. ╓ ╥ ╖ . ╟ ╫ ╢ . ╙ ╨ ╜ }],
        [qw{. ┌ ┬ ┐ . ├ ┼ ┤ . └ ┴ ┘}],
        [qw{. ┏ ┳ ┓ . ┣ ╋ ┫ . ┗ ┻ ┛}],
        [qw{. ┍ ┯ ┑ . ┝ ┿ ┥ . ┕ ┷ ┙}],
@@ -159,23 +111,16 @@ print_glyph_tables(
                . ╵ │ ╎ ┆ ┊ ╷ ╿
                . ╹ ┃ ╏ ┇ ┋ ╻ ╽
        }],
+       [qw{. ╭ ╮ . ╰ ╯ }],
        [qw{. ╱ ╳ ╲ }],
-       [qw{. ╔ ╦ ╗ ═ . ╠ ╬ ╣ ║ . ╚ ╩ ╝ - }],
-       [qw{. ╒ ╤ ╕ . ╞ ╪ ╡ . ╘ ╧ ╛ }],
-       [qw{. ╓ ╥ ╖ . ╟ ╫ ╢ . ╙ ╨ ╜ }],
+       # ┞┟┡┢┦┧┩┪┭┮┱┲┵┶┹┺┽┾╀╁╃╄╅╆╇╈╉╊
 
        'Blocks',
-       [qw{. �� ▀ ▝ . ▌ █ ▐ . ▖ ▄ ▗ }],
+       [qw{. �� ▣ ■ . ▤ ▦ ▥ . ▧ ▩ ▨}],
        [qw{. ░ . ▒ . ▓ }],
+       [qw{. ▘ ▀ ▝ . ▌ █ ▐ . ▖ ▄ ▗ }],
        [qw{. ▛ ▚ ▟ . ▙ ▞ ▜ }],
        [qw{. ▁ ▂ ▃ ▄ ▅ ▆ ▇ ▔ . ▏ ▎ ▍ ▌ ▋ ▊ ▉ ▕ }],
-       [qw{. □ ▣ ■ . ▤ ▦ ▥ . ▧ ▩ ▨}],
-
-       'Signs',
-       [qw{. ¤ ¢ ₥ € £ ₨ $ ¥ . ₫ ₭ ₦ ₱ ₧ ₮ ₩ ₪}],
-       [qw{. ♠ ♡ ♢ ♣ . ♤ ♥ ♦ ♧}],
-       [qw{. ☉ ☿ ♀ ♁ ♂ ♃ ♄ ♅ ♆ ♇}],  # solar
-       [qw{. ♈ ♉ ♊ ♋ ♌ ♍ ♎ ♏ ♐ ♑ ♒ ♓}],  # zodiac
 
        'IPA',
        [qw{
@@ -197,7 +142,7 @@ print_glyph_tables(
                .>Implosive                 ɓ  ɗ̪  >  >  ɗ  -ᶑ ʄ  ɠ  ʛ  =  =  =
        }],
        [qw{
-               co . ɕ . ʑ . ɧ . ɥ . ʍ . w
+               - co:coarticulated .>sç ɕ .>zʝ ʑ .>ʃx ɧ .>jʷ ɥ .>hw̥ ʍ .>ɰʷ w
        }],
        [(
                '-',
@@ -213,14 +158,7 @@ print_glyph_tables(
                .>Open       a ɶ  - -  ɑ ɒ
        }],
 
-       'Alphabetics',
-       [qw{
-               .>Latin    a ī ı ę ô ɳ ŋ ṡ š đ ð Ʒ
-               .>Cyrillic а і й э ё н њ ш щ ч ь Я
-               .>Greek    α ί ϊ η ϋ π ψ σ ς θ ξ Ω
-               .>Hebrew   א ײ י ע ו נ ן ס ש ט צ ץ
-       }],
-
+$verbose ? (
        'Japanese',
        [qw{
                  - A  I  U  E  O  _
@@ -233,7 +171,7 @@ print_glyph_tables(
                .>M ま み む め も =
                .>Y や =  ゆ =  よ =
                .>R ら り る れ ろ =
-               .>W わ ゐ =  ゑ を =
+               .>W わ -ゐ = -ゑ を =
        }],
        [qw{
                  - A  I  U  E  O
@@ -265,20 +203,18 @@ print_glyph_tables(
                .>P パ ピ プ ペ ポ
                .>V ヷ ヸ ヴ ヹ ヺ
        }],
+) : (),
 );
 
 :></div>
 
-<p id="footer">
-       <a href="http://vi.shiar.net/unicode">vi.<strong>shiar.net</strong>/unicode</a>
-       <a href="git://dev.shiar.net/vi-cheat"><:= "v$VERSION" :></a>
-       created by Shiar •
-       <a title="Licensed under the GNU Affero General Public License, version 3"
-          href="http://www.fsf.org/licensing/licenses/agpl-3.0.html">AGPLv3</a> •
-       last update <:
-               use Time::Format qw(time_format);
-               print time_format('yyyy-mm-dd', (stat $ENV{SCRIPT_FILENAME})[9]);
-       :>
-</p>
+<div class="legend">
+       <table class="glyphs"><tr>
+       <td class="X di-a">ascii
+       <td class="X di-d"><:= $glyphs->{digraph} ? 'digraph' : 'latin1' :>
+       <td class="X di-prop"><:= $glyphs->{digraph} ? 'proposed' : 'BMP' :>
+       <td class="X di-b">other unicode
+       <td class="X di-rare">discouraged
+       </table>
+</div>
 
-</html>