summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-08-18 15:11:01 -0400
committerJune McEnroe <june@causal.agency>2019-08-18 15:11:01 -0400
commit83364534ca9ab777d824392b6fc1f3befedca62f (patch)
tree54ef50e45940cfd80488dc7c3f031d992c2c406c
parentFix CSI param counting (diff)
downloadstream-master.tar.gz
stream-master.zip
Implement alternate charset HEAD master
Diffstat (limited to '')
-rw-r--r--term.c30
-rw-r--r--term.h2
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 <http://www.gnu.org/licenses/>.
  */
 
-#include <stdbool.h>
 #include <wchar.h>
 
 typedef unsigned uint;
@@ -69,6 +68,7 @@ struct Term {
 		uint top, bot;
 	} scroll;
 	uint y, x;
+	uint charset;
 	struct Style style;
 	struct Cell cells[];
 };