mutt: page, key classes, various updates
[sheet.git] / Shiar_Sheet / KeySigns.pm
1 package Shiar_Sheet::KeySigns;
2
3 use utf8;
4 use strict;
5 use warnings;
6
7 our $VERSION = 'v1.00';
8
9 sub import {
10         my $class = shift;
11
12         my $ascii = undef;
13         if (exists $PLP::Script::get{ascii}) {
14                 # manual override
15                 $ascii = !defined $PLP::Script::get{ascii} || $PLP::Script::get{ascii} !~ /^0*$/;
16         }
17         elsif (defined $ENV{HTTP_ACCEPT_CHARSET}) {
18                 $ascii = 1;
19                 for (split q{,}, $ENV{HTTP_ACCEPT_CHARSET}) {
20                         $ascii = undef, last if $_ eq '*' or m{utf-?8}i;
21                 }
22         }
23
24         my %sign = (
25                 -ascii => $ascii,
26                 charset=> $ascii ? 'us-ascii' : 'utf-8',
27                 arg    => $ascii ? '.' : '·',  # described as 'dot'
28                 args   => $ascii ? ':' : '⁚',
29                 argi   => $ascii ? "'" : '′',
30                 argm   => $ascii ? '|' : '↕',
31                 motion => $ascii ? '|' : '↕',
32                 alias  => $ascii ? 'see: ' : '»',
33                 up     => $ascii ? 'up'    : '▲',
34                 right  => $ascii ? 'right' : '▶',
35                 down   => $ascii ? 'down'  : '▼',
36                 left   => $ascii ? 'left'  : '◀',
37                 sep    => $ascii ? '*'     : '•',
38                 _      => defined $ascii && !$ascii ? "\x{200b}" : '<wbr>',
39                         # use the correct ZWNJ only when unicode is forced on
40                         # default to use unofficial html for best support
41         );
42
43         my ($parent) = caller;
44         eval '*'.$parent.'::sign = \%sign';
45 }
46
47 1;
48
49 __END__
50
51 =head1 NAME
52
53 Shiar_Sheet::KeySigns - Common Unicode characters in user-preferred charset
54
55 =head1 SYNOPSIS
56
57         use Shiar_Sheet::KeySigns;
58         print "$sign{alias} some$sign{_}thing";  # see: some<wbr>thing
59
60         package PLP::Script;
61         our %get = (ascii => 0);  # user input
62         Shiar_Sheet::KeySigns->import;
63         print "$sign{alias} some$sign{_}thing";  # »some( )thing
64
65 =head1 AUTHOR
66
67 Mischa POSLAWSKY <perl@shiar.org>
68
69 =head1 LICENSE
70
71 Copyright. All rights reserved.
72