From 83364534ca9ab777d824392b6fc1f3befedca62f Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Sun, 18 Aug 2019 15:11:01 -0400 Subject: Implement alternate charset --- term.c | 30 +++++++++++++++++++++++++++++- term.h | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/term.c b/term.c index 342bc66..aa44454 100644 --- a/term.c +++ b/term.c @@ -320,7 +320,28 @@ ACTION(sgr) { } } +enum { + USASCII, + DECSpecial, +}; + +ACTION(usascii) { t->charset = USASCII; } +ACTION(decSpecial) { t->charset = DECSpecial; } + +static const wchar_t AltCharset[128] = { + ['`'] = L'◆', ['a'] = L'▒', ['f'] = L'°', ['g'] = L'±', ['i'] = L'␋', + ['j'] = L'┘', ['k'] = L'┐', ['l'] = L'┌', ['m'] = L'└', ['n'] = L'┼', + ['o'] = L'⎺', ['p'] = L'⎻', ['q'] = L'─', ['r'] = L'⎼', ['s'] = L'⎽', + ['t'] = L'├', ['u'] = L'┤', ['v'] = L'┴', ['w'] = L'┬', ['x'] = L'│', + ['y'] = L'≤', ['z'] = L'≥', ['{'] = L'π', ['|'] = L'≠', ['}'] = L'£', + ['~'] = L'·', +}; + ACTION(add) { + if (t->charset == DECSpecial && ch < 128 && AltCharset[ch]) { + ch = AltCharset[ch]; + } + int width = wcwidth(ch); if (width < 0) { unhandled("\\u%02X", ch); @@ -364,6 +385,11 @@ ACTION(escDefault) { unhandled("ESC %lc", ch); } +ACTION(g0Default) { + unhandled("G0 %lc", ch); + t->charset = USASCII; +} + ACTION(csiInter) { switch (t->state) { break; case CSI: unhandled("CSI %lc ...", ch); @@ -414,7 +440,9 @@ void termUpdate(struct Term *term, wchar_t ch) { D(escDefault, Data); } S(G0) { - D(nop, Data); + A('0', decSpecial, Data); + A('B', usascii, Data); + D(g0Default, Data); } S(CSI) { diff --git a/term.h b/term.h index f2df1fa..155d01b 100644 --- a/term.h +++ b/term.h @@ -14,7 +14,6 @@ * along with this program. If not, see . */ -#include #include typedef unsigned uint; @@ -69,6 +68,7 @@ struct Term { uint top, bot; } scroll; uint y, x; + uint charset; struct Style style; struct Cell cells[]; }; -- cgit 1.4.1