tled: support digraphs - neatvi - [fork] simple vi-type editor with UTF-8 support
git clone git://src.adamsgaard.dk/neatvi
Log
Files
Refs
README
---
commit 88384358c2852c6b9b994bbd98307712f1c0588d
parent 67f3f8c955e80f17bc4ca092e2454a0104d13b18
Author: Ali Gholami Rudi 
Date:   Wed, 17 Jun 2015 18:37:41 +0430

led: support digraphs

The digraphs resemble troff named characters.

Diffstat:
  M kmap.h                              |     336 +++++++++++++++++++++++++++++++
  M led.c                               |      24 ++++++++++++++++++++++++

2 files changed, 360 insertions(+), 0 deletions(-)
---
diff --git a/kmap.h b/kmap.h
t@@ -99,3 +99,339 @@ static char *kmap_fa[256] = {
         ['?'] = "؟",
         ['|'] = "|",
 };
+
+static char *digraphs[][2] = {
+        {"cq", "’"},
+        {"pl", "+"},
+        {"hy", "-"},
+        {"sl", "/"},
+        {"eq", "="},
+        {"dq", "\""},
+        {"rs", "\\"},
+        {"ru", "_"},
+        {"ul", "_"},
+        {"oq", "‘"},
+        {"or", "|"},
+        {"!!", "¡"},
+        {"r!", "¡"},
+        {"c|", "¢"},
+        {"ct", "¢"},
+        {"L-", "£"},
+        {"ps", "£"},
+        {"xo", "¤"},
+        {"cr", "¤"},
+        {"Y-", "¥"},
+        {"yn", "¥"},
+        {"||", "¦"},
+        {"so", "§"},
+        {"sc", "§"},
+        {"co", "©"},
+        {"a_", "ª"},
+        {"<<", "«"},
+        {"Fo", "«"},
+        {"-,", "¬"},
+        {"no", "¬"},
+        {"ro", "®"},
+        {"rg", "®"},
+        {"0^", "°"},
+        {"de", "°"},
+        {"+-", "±"},
+        {"2^", "²"},
+        {"3^", "³"},
+        {"P!", "¶"},
+        {"pg" "¶"},
+        {".^", "·"},
+        {"1^", "¹"},
+        {"o_", "º"},
+        {">>", "»"},
+        {"Fc", "»"},
+        {"14", "¼"},
+        {"12", "½"},
+        {"34", "¾"},
+        {"??", "¿"},
+        {"r?", "¿"},
+        {"A`", "À"},
+        {"A'", "Á"},
+        {"A^", "Â"},
+        {"A~", "Ã"},
+        {"A:", "Ä"},
+        {"A\"", "A:"},
+        {"A*", "Å"},
+        {"AE", "Æ"},
+        {"C,", "Ç"},
+        {"E`", "È"},
+        {"E'", "É"},
+        {"E^", "Ê"},
+        {"E:", "Ë"},
+        {"I`", "Ì"},
+        {"I'", "Í"},
+        {"I^", "Î"},
+        {"I:", "Ï"},
+        {"D-", "Ð"},
+        {"N~", "Ñ"},
+        {"O`", "Ò"},
+        {"O'", "Ó"},
+        {"O^", "Ô"},
+        {"O~", "Õ"},
+        {"O:", "Ö"},
+        {"xx", "×"},
+        {"mu", "×"},
+        {"O/", "Ø"},
+        {"U`", "Ù"},
+        {"U'", "Ú"},
+        {"U^", "Û"},
+        {"U:", "Ü"},
+        {"Y'", "Ý"},
+        {"TH", "Þ"},
+        {"ss", "ß"},
+        {"a`", "à"},
+        {"a'", "á"},
+        {"a^", "â"},
+        {"a~", "ã"},
+        {"a:", "ä"},
+        {"a*", "å"},
+        {"ae", "æ"},
+        {"c,", "ç"},
+        {"e`", "è"},
+        {"e'", "é"},
+        {"e^", "ê"},
+        {"e:", "ë"},
+        {"i`", "ì"},
+        {"i'", "í"},
+        {"i^", "î"},
+        {"i:", "ï"},
+        {"d-", "ð"},
+        {"n~", "ñ"},
+        {"o`", "ò"},
+        {"o'", "ó"},
+        {"o^", "ô"},
+        {"o~", "õ"},
+        {"o:", "ö"},
+        {"di", "÷"},
+        {"-:", "÷"},
+        {"o/", "ø"},
+        {"u`", "ù"},
+        {"u'", "ú"},
+        {"u^", "û"},
+        {"u:", "ü"},
+        {"y'", "ý"},
+        {"th", "þ"},
+        {"y:", "ÿ"},
+        {"C<", "Č"},
+        {"c<", "č"},
+        {"D<", "Ď"},
+        {"d<", "ď"},
+        {"e<", "ě"},
+        {"n<", "ň"},
+        {"O\"", "Ő"},
+        {"o\"", "ő"},
+        {"R<", "Ř"},
+        {"r<", "ř"},
+        {"S<", "Š"},
+        {"s<", "š"},
+        {"T<", "Ť"},
+        {"t<", "ť"},
+        {"U*", "Ů"},
+        {"u*", "ů"},
+        {"U\"", "Ű"},
+        {"u\"", "ű"},
+        {"Y:", "Ÿ"},
+        {"Z<", "Ž"},
+        {"z<", "ž"},
+        {"fn", "ƒ"},
+        {",,", "¸"},
+        {",a", "¸"},
+        {"aa", "´"},
+        {"\\'", "´"},
+        {"-a", "¯"},
+        {"\"\"", "¨"},
+        {":a", "¨"},
+        {"^", "ˆ"},
+        {"^a", "ˆ"},
+        {"va", "ˇ"},
+        {"Ua", "˘"},
+        {".a", "˙"},
+        {"oa", "˚"},
+        {"Ca", "˛"},
+        {"\"a", "˝"},
+        {"~", "˜"},
+        {"*A", "Α"},
+        {"*B", "Β"},
+        {"*G", "Γ"},
+        {"*E", "Ε"},
+        {"*Z", "Ζ"},
+        {"*Y", "Η"},
+        {"*H", "Θ"},
+        {"*I", "Ι"},
+        {"*K", "Κ"},
+        {"*L", "Λ"},
+        {"*M", "Μ"},
+        {"*N", "Ν"},
+        {"*C", "Ξ"},
+        {"*O", "Ο"},
+        {"*P", "Π"},
+        {"*R", "Ρ"},
+        {"*S", "Σ"},
+        {"*T", "Τ"},
+        {"*U", "Υ"},
+        {"*F", "Φ"},
+        {"*X", "Χ"},
+        {"*Q", "Ψ"},
+        {"*W", "Ω"},
+        {"*a", "α"},
+        {"*b", "β"},
+        {"*g", "γ"},
+        {"*d", "δ"},
+        {"*e", "ε"},
+        {"*z", "ζ"},
+        {"*y", "η"},
+        {"*h", "θ"},
+        {"*i", "ι"},
+        {"*k", "κ"},
+        {"*l", "λ"},
+        {"*m", "μ"},
+        {"/u", "µ"},
+        {"*n", "ν"},
+        {"*c", "ξ"},
+        {"*o", "ο"},
+        {"*p", "π"},
+        {"*r", "ρ"},
+        {"ts", "ς"},
+        {"*s", "σ"},
+        {"*t", "τ"},
+        {"*u", "υ"},
+        {"*f", "φ"},
+        {"*x", "χ"},
+        {"*q", "ψ"},
+        {"*w", "ω"},
+        {"en", "–"},
+        {"\\-", "–"},
+        {"em", "—"},
+        {"--", "—"},
+        {"bq", "‚"},
+        {"``", "“"},
+        {"lq", "“"},
+        {"''", "”"},
+        {"rq", "”"},
+        {"dg", "†"},
+        {"dd", "‡"},
+        {"bu", "•"},
+        {"el", "…"},
+        {"%0", "‰"},
+        {"fm", "′"},
+        {"fo", "‹"},
+        {"fc", "›"},
+        {"fr", "⁄"},
+        {"If", "ℑ"},
+        {"ws", "ℛ"},
+        {"Rf", "ℜ"},
+        {"af", "ℵ"},
+        {"<-", "←"},
+        {"ua", "↑"},
+        {"->", "→"},
+        {"da", "↓"},
+        {"<>", "↔"},
+        {"ab", "↔"},
+        {"CR", "↵"},
+        {"fa", "∀"},
+        {"pd", "∂"},
+        {"te", "∃"},
+        {"es", "∅"},
+        {"*D", "Δ"},
+        {"gr", "∇"},
+        {"mo", "∈"},
+        {"!m", "∉"},
+        {"st", "∋"},
+        {"pr", "∏"},
+        {"su", "∑"},
+        {"mi", "−"},
+        {"-+", "∓"},
+        {"**", "∗"},
+        {"sr", "√"},
+        {"pt", "∝"},
+        {"if", "∞"},
+        {"an", "∠"},
+        {"l&", "∧"},
+        {"l|", "∨"},
+        {"ca", "∩"},
+        {"cu", "∪"},
+        {"is", "∫"},
+        {"tf", "∴"},
+        {"ap", "∼"},
+        {"cg", "≅"},
+        {"=~", "≅"},
+        {"~~", "≈"},
+        {"!=", "≠"},
+        {"==", "≡"},
+        {"<=", "≤"},
+        {">=", "≥"},
+        {"sb", "⊂"},
+        {"sp", "⊃"},
+        {"!b", "⊄"},
+        {"ib", "⊆"},
+        {"ip", "⊇"},
+        {"O+", "⊕"},
+        {"Ox", "⊗"},
+        {"pp", "⊥"},
+        {"c.", "⋅"},
+        {"b<", "〈"},
+        {"b>", "〉"},
+        {"lz", "◊"},
+        {"ci", "○"},
+        {"la", "⟨"},
+        {"ra", "⟩"},
+        {"co", ""},
+        {"rg", ""},
+        {"tm", ""},
+        {"rn", ""},
+        {"av", ""},
+        {"ah", ""},
+        {"RG", ""},
+        {"CO", ""},
+        {"TM", ""},
+        {"LT", ""},
+        {"br", ""},
+        {"LX", ""},
+        {"LB", ""},
+        {"LT", "⎛"},
+        {"LX", "⎜"},
+        {"LB", "⎝"},
+        {"lc", ""},
+        {"lx", ""},
+        {"lf", ""},
+        {"lc", "⎡"},
+        {"lx", "⎢"},
+        {"lf", "⎣"},
+        {"lt", ""},
+        {"lk", ""},
+        {"lb", ""},
+        {"lt", "⎧"},
+        {"lk", "⎨"},
+        {"lb", "⎩"},
+        {"bv", "⎪"},
+        {"RT", ""},
+        {"RX", ""},
+        {"RB", ""},
+        {"RT", "⎞"},
+        {"RX", "⎟"},
+        {"RB", "⎠"},
+        {"rc", ""},
+        {"rx", ""},
+        {"rf", ""},
+        {"rc", "⎤"},
+        {"rx", "⎥"},
+        {"rf", "⎦"},
+        {"rt", ""},
+        {"rk", ""},
+        {"rb", ""},
+        {"rt", "⎫"},
+        {"rk", "⎬"},
+        {"rb", "⎭"},
+        {"ff", "ff"},
+        {"fi", "fi"},
+        {"fl", "fl"},
+        {"ffi", "ffi"},
+        {"Fi", "ffi"},
+        {"ffl", "ffl"},
+        {"Fl", "ffl"},
+};
diff --git a/led.c b/led.c
t@@ -178,6 +178,22 @@ static void led_printparts(char *ai, char *pref, char *main, char *post, char *k
         term_commit();
 }
 
+static char *led_digraph(void)
+{
+        int c1, c2;
+        int i;
+        c1 = term_read(-1);
+        if (TK_INT(c1))
+                return NULL;
+        c2 = term_read(-1);
+        if (TK_INT(c2))
+                return NULL;
+        for (i = 0; i < LEN(digraphs); i++)
+                if (digraphs[i][0][0] == c1 && digraphs[i][0][1] == c2)
+                        return digraphs[i][1];
+        return NULL;
+}
+
 char *led_read(char **kmap)
 {
         static char buf[8];
t@@ -194,6 +210,8 @@ char *led_read(char **kmap)
                         buf[0] = term_read(-1);
                         buf[1] = '\0';
                         return buf;
+                case TK_CTL('k'):
+                        return led_digraph();
                 default:
                         return kmap_map(*kmap, c);
                 }
t@@ -207,6 +225,7 @@ static char *led_line(char *pref, char *post, char *ai, int ai_max, int *key, ch
         struct sbuf *sb;
         int ai_len = strlen(ai);
         int c, lnmode;
+        char *dig;
         sb = sbuf_make();
         if (!pref)
                 pref = "";
t@@ -230,6 +249,11 @@ static char *led_line(char *pref, char *post, char *ai, int ai_max, int *key, ch
                 case TK_CTL('u'):
                         sbuf_cut(sb, 0);
                         break;
+                case TK_CTL('k'):
+                        dig = led_digraph();
+                        if (dig)
+                                sbuf_str(sb, dig);
+                        break;
                 case TK_CTL('v'):
                         sbuf_chr(sb, term_read(-1));
                         break;