From 0461a822c29a6e110d6acb79b88cb1062d84b69c Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 20 Jan 2017 19:05:13 -0800 Subject: [PATCH 1/3] Add character sets for most languages Part of #481 --- src/Charsets.ts | 202 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 190 insertions(+), 12 deletions(-) diff --git a/src/Charsets.ts b/src/Charsets.ts index 3220f7d5..317d60e4 100644 --- a/src/Charsets.ts +++ b/src/Charsets.ts @@ -52,16 +52,194 @@ CHARSETS.SCLD = { // (0 '~': '\u00b7' // '·' }; -CHARSETS.UK = null; // (A -CHARSETS.US = null; // (B (USASCII) -CHARSETS.Dutch = null; // (4 -CHARSETS.Finnish = null; // (C or (5 -CHARSETS.French = null; // (R -CHARSETS.FrenchCanadian = null; // (Q -CHARSETS.German = null; // (K -CHARSETS.Italian = null; // (Y -CHARSETS.NorwegianDanish = null; // (E or (6 -CHARSETS.Spanish = null; // (Z -CHARSETS.Swedish = null; // (H or (7 -CHARSETS.Swiss = null; // (= +/** + * British character set + * ESC (A + * Reference: http://vt100.net/docs/vt220-rm/table2-5.html + */ +CHARSETS.UK = { + '#': '£' +}; + +/** + * United States character set + * ESC (B + */ +CHARSETS.US = null; + +/** + * Dutch character set + * ESC (4 + * Reference: http://vt100.net/docs/vt220-rm/table2-6.html + */ +CHARSETS.Dutch = { // (4 + '#': '£', + '@': '¾', + '[': 'ij', + '\\': '½', + ']': '|', + '{': '¨', + '|': 'f', + '}': '¼', + '~': '´' +}; + +/** + * Finnish character set + * ESC (C or ESC (5 + * Reference: http://vt100.net/docs/vt220-rm/table2-7.html + */ +CHARSETS.Finnish = { + '[': 'Ä', + '\\': 'Ö', + ']': 'Å', + '^': 'Ü', + '`': 'é', + '{': 'ä', + '|': 'ö', + '}': 'å', + '~': 'ü' +}; + +/** + * French character set + * ESC (R + * Reference: http://vt100.net/docs/vt220-rm/table2-8.html + */ +CHARSETS.French = { + '#': '£', + '@': 'à', + '[': '°', + '\\': 'ç', + ']': '§', + '{': 'é', + '|': 'ù', + '}': 'è', + '~': '¨' +}; + +/** + * French Canadian character set + * ESC (Q + * Reference: http://vt100.net/docs/vt220-rm/table2-9.html + */ +CHARSETS.FrenchCanadian = { + '@': 'à', + '[': 'â', + '\\': 'ç', + ']': 'ê', + '^': 'î', + '`': 'ô', + '{': 'é', + '|': 'ù', + '}': 'è', + '~': 'û' +}; + +/** + * German character set + * ESC (K + * Reference: http://vt100.net/docs/vt220-rm/table2-10.html + */ +CHARSETS.German = { + '@': '§', + '[': 'Ä', + '\\': 'Ö', + ']': 'Ü', + '{': 'ä', + '|': 'ö', + '}': 'ü', + '~': 'ß' +}; + +/** + * Italian character set + * ESC (Y + * Reference: http://vt100.net/docs/vt220-rm/table2-11.html + */ +CHARSETS.Italian = { + '#': '£', + '@': '§', + '[': '°', + '\\': 'ç', + ']': 'é', + '`': 'ù', + '{': 'à', + '|': 'ò', + '}': 'è', + '~': 'ì' +}; + +/** + * Norwegian/Danish character set + * ESC (E or ESC (6 + * Reference: http://vt100.net/docs/vt220-rm/table2-12.html + */ +CHARSETS.NorwegianDanish = { + '@': 'Ä', + '[': 'Æ', + '\\': 'Ø', + ']': 'Å', + '^': 'Ü', + '`': 'ä', + '{': 'æ', + '|': 'ø', + '}': 'å', + '~': 'ü' +}; + +/** + * Spanish character set + * ESC (Z + * Reference: http://vt100.net/docs/vt220-rm/table2-13.html + */ +CHARSETS.Spanish = { + '#': '£', + '@': '§', + '[': '¡', + '\\': 'Ñ', + ']': '¿', + '{': '°', + '|': 'ñ', + '}': 'ç' +}; + +/** + * Swedish character set + * ESC (H or ESC (7 + * Reference: http://vt100.net/docs/vt220-rm/table2-14.html + */ +CHARSETS.Swedish = { + '@': 'É', + '[': 'Ä', + '\\': 'Ö', + ']': 'Å', + '^': 'Ü', + '`': 'é', + '{': 'ä', + '|': 'ö', + '}': 'å', + '~': 'ü' +}; + +/** + * Swiss character set + * ESC (= + * Reference: http://vt100.net/docs/vt220-rm/table2-15.html + */ +CHARSETS.Swiss = { + '#': 'ù', + '@': 'à', + '[': 'é', + '\\': 'ç', + ']': 'ê', + '^': 'î', + '_': 'è', + '`': 'ô', + '{': 'ä', + '|': 'ö', + '}': 'ü', + '~': 'û' +}; + CHARSETS.ISOLatin = null; // /A From aab67c2ed97177be9e6a464a5c0b725e3eb48783 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 20 Jan 2017 20:12:47 -0800 Subject: [PATCH 2/3] Reference CHARSETS using codes --- src/Charsets.ts | 41 +++++++++++++++++++++++------------------ src/InputHandler.ts | 10 +++++----- src/Parser.ts | 32 +++++--------------------------- 3 files changed, 33 insertions(+), 50 deletions(-) diff --git a/src/Charsets.ts b/src/Charsets.ts index 317d60e4..b3bdbbb4 100644 --- a/src/Charsets.ts +++ b/src/Charsets.ts @@ -2,13 +2,17 @@ * @license MIT */ -// TODO: Give CHARSETS a proper type /** * The character sets supported by the terminal. These enable several languages * to be represented within the terminal with only 8-bit encoding. See ISO 2022 - * for a discussion on character sets. + * for a discussion on character sets. Only VT100 character sets are supported. */ -export const CHARSETS: any = {}; +export const CHARSETS: {[key: string]: {[key: string]: string}} = {}; + +/** + * The default character set, US. + */ +export const DEFAULT_CHARSET = CHARSETS['B']; // DEC Special Character and Line Drawing Set. // http://vt100.net/docs/vt102-ug/table5-13.html @@ -18,7 +22,7 @@ export const CHARSETS: any = {}; // reference above. xterm seems in line with the reference // when running vttest however. // The table below now uses xterm's output from vttest. -CHARSETS.SCLD = { // (0 +CHARSETS['0'] = { '`': '\u25c6', // '◆' 'a': '\u2592', // '▒' 'b': '\u0009', // '\t' @@ -57,7 +61,7 @@ CHARSETS.SCLD = { // (0 * ESC (A * Reference: http://vt100.net/docs/vt220-rm/table2-5.html */ -CHARSETS.UK = { +CHARSETS['A'] = { '#': '£' }; @@ -65,14 +69,14 @@ CHARSETS.UK = { * United States character set * ESC (B */ -CHARSETS.US = null; +CHARSETS['B'] = null; /** * Dutch character set * ESC (4 * Reference: http://vt100.net/docs/vt220-rm/table2-6.html */ -CHARSETS.Dutch = { // (4 +CHARSETS['4'] = { '#': '£', '@': '¾', '[': 'ij', @@ -89,7 +93,8 @@ CHARSETS.Dutch = { // (4 * ESC (C or ESC (5 * Reference: http://vt100.net/docs/vt220-rm/table2-7.html */ -CHARSETS.Finnish = { +CHARSETS['C'] = +CHARSETS['5'] = { '[': 'Ä', '\\': 'Ö', ']': 'Å', @@ -106,7 +111,7 @@ CHARSETS.Finnish = { * ESC (R * Reference: http://vt100.net/docs/vt220-rm/table2-8.html */ -CHARSETS.French = { +CHARSETS['R'] = { '#': '£', '@': 'à', '[': '°', @@ -123,7 +128,7 @@ CHARSETS.French = { * ESC (Q * Reference: http://vt100.net/docs/vt220-rm/table2-9.html */ -CHARSETS.FrenchCanadian = { +CHARSETS['Q'] = { '@': 'à', '[': 'â', '\\': 'ç', @@ -141,7 +146,7 @@ CHARSETS.FrenchCanadian = { * ESC (K * Reference: http://vt100.net/docs/vt220-rm/table2-10.html */ -CHARSETS.German = { +CHARSETS['K'] = { '@': '§', '[': 'Ä', '\\': 'Ö', @@ -157,7 +162,7 @@ CHARSETS.German = { * ESC (Y * Reference: http://vt100.net/docs/vt220-rm/table2-11.html */ -CHARSETS.Italian = { +CHARSETS['Y'] = { '#': '£', '@': '§', '[': '°', @@ -175,7 +180,8 @@ CHARSETS.Italian = { * ESC (E or ESC (6 * Reference: http://vt100.net/docs/vt220-rm/table2-12.html */ -CHARSETS.NorwegianDanish = { +CHARSETS['E'] = +CHARSETS['6'] = { '@': 'Ä', '[': 'Æ', '\\': 'Ø', @@ -193,7 +199,7 @@ CHARSETS.NorwegianDanish = { * ESC (Z * Reference: http://vt100.net/docs/vt220-rm/table2-13.html */ -CHARSETS.Spanish = { +CHARSETS['Z'] = { '#': '£', '@': '§', '[': '¡', @@ -209,7 +215,8 @@ CHARSETS.Spanish = { * ESC (H or ESC (7 * Reference: http://vt100.net/docs/vt220-rm/table2-14.html */ -CHARSETS.Swedish = { +CHARSETS['H'] = +CHARSETS['7'] = { '@': 'É', '[': 'Ä', '\\': 'Ö', @@ -227,7 +234,7 @@ CHARSETS.Swedish = { * ESC (= * Reference: http://vt100.net/docs/vt220-rm/table2-15.html */ -CHARSETS.Swiss = { +CHARSETS['='] = { '#': 'ù', '@': 'à', '[': 'é', @@ -241,5 +248,3 @@ CHARSETS.Swiss = { '}': 'ü', '~': 'û' }; - -CHARSETS.ISOLatin = null; // /A diff --git a/src/InputHandler.ts b/src/InputHandler.ts index 975d7c11..bed835b6 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -4,7 +4,7 @@ import { IInputHandler, ITerminal } from './Interfaces'; import { C0 } from './EscapeSequences'; -import { CHARSETS } from './Charsets'; +import { DEFAULT_CHARSET } from './Charsets'; /** * The terminal's standard implementation of IInputHandler, this handles all @@ -842,10 +842,10 @@ export class InputHandler implements IInputHandler { this._terminal.applicationCursor = true; break; case 2: - this._terminal.setgCharset(0, CHARSETS.US); - this._terminal.setgCharset(1, CHARSETS.US); - this._terminal.setgCharset(2, CHARSETS.US); - this._terminal.setgCharset(3, CHARSETS.US); + this._terminal.setgCharset(0, DEFAULT_CHARSET); + this._terminal.setgCharset(1, DEFAULT_CHARSET); + this._terminal.setgCharset(2, DEFAULT_CHARSET); + this._terminal.setgCharset(3, DEFAULT_CHARSET); // set VT100 mode here break; case 3: // 132 col mode diff --git a/src/Parser.ts b/src/Parser.ts index 02028005..8f5f3e69 100644 --- a/src/Parser.ts +++ b/src/Parser.ts @@ -4,7 +4,7 @@ import { C0 } from './EscapeSequences'; import { IInputHandler } from './Interfaces'; -import { CHARSETS } from './Charsets'; +import { CHARSETS, DEFAULT_CHARSET } from './Charsets'; const normalStateHandler: {[key: string]: (parser: Parser, handler: IInputHandler) => void} = {}; normalStateHandler[C0.BEL] = (parser, handler) => handler.bell(); @@ -70,7 +70,7 @@ escapedStateHandler['%'] = (parser, terminal) => { // ESC % Select default/utf-8 character set. // @ = default, G = utf-8 terminal.setgLevel(0); - terminal.setgCharset(0, CHARSETS.US); + terminal.setgCharset(0, DEFAULT_CHARSET); // US (default) parser.setState(ParserState.NORMAL); parser.skipNextChar(); }; @@ -145,28 +145,6 @@ csiStateHandler['r'] = (handler, params) => handler.setScrollRegion(params); csiStateHandler['s'] = (handler, params) => handler.saveCursor(params); csiStateHandler['u'] = (handler, params) => handler.restoreCursor(params); -// TODO: Many codes/charsets appear to not be supported -// See: http://invisible-island.net/xterm/ctlseqs/ctlseqs.html -const charsetMap = { - '0': CHARSETS.SCLD, - 'A': CHARSETS.UK, // United Kingdom - 'B': CHARSETS.US, // United States (USASCII) - '4': CHARSETS.Dutch, - 'C': CHARSETS.Finnish, - '5': CHARSETS.Finnish, - 'f': CHARSETS.French, - 'Q': CHARSETS.FrenchCanadian, - 'K': CHARSETS.German, - 'Y': CHARSETS.Italian, - 'E': CHARSETS.NorwegianDanish, - '6': CHARSETS.NorwegianDanish, - 'Z': CHARSETS.Spanish, - 'H': CHARSETS.Swedish, - '7': CHARSETS.Swedish, - '=': CHARSETS.Swiss, - '/': CHARSETS.ISOLatin // ISOLatin is actually /A -}; - enum ParserState { NORMAL = 0, ESCAPED = 1, @@ -371,13 +349,13 @@ export class Parser { break; case ParserState.CHARSET: - if (ch in charsetMap) { - cs = charsetMap[ch]; + if (ch in CHARSETS) { + cs = CHARSETS[ch]; if (ch === '/') { // ISOLatin is actually /A this.skipNextChar(); } } else { - cs = CHARSETS.US; // Default + cs = DEFAULT_CHARSET; } this._terminal.setgCharset(this._terminal.gcharset, cs); this._terminal.gcharset = null; From b5d16ed7d7b6d2a98102877cda0c8b96ad91a035 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 20 Jan 2017 20:13:45 -0800 Subject: [PATCH 3/3] Use block comment for SCLD --- src/Charsets.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Charsets.ts b/src/Charsets.ts index b3bdbbb4..f567ef44 100644 --- a/src/Charsets.ts +++ b/src/Charsets.ts @@ -14,14 +14,16 @@ export const CHARSETS: {[key: string]: {[key: string]: string}} = {}; */ export const DEFAULT_CHARSET = CHARSETS['B']; -// DEC Special Character and Line Drawing Set. -// http://vt100.net/docs/vt102-ug/table5-13.html -// A lot of curses apps use this if they see TERM=xterm. -// testing: echo -e '\e(0a\e(B' -// The xterm output sometimes seems to conflict with the -// reference above. xterm seems in line with the reference -// when running vttest however. -// The table below now uses xterm's output from vttest. +/** + * DEC Special Character and Line Drawing Set. + * Reference: http://vt100.net/docs/vt102-ug/table5-13.html + * A lot of curses apps use this if they see TERM=xterm. + * testing: echo -e '\e(0a\e(B' + * The xterm output sometimes seems to conflict with the + * reference above. xterm seems in line with the reference + * when running vttest however. + * The table below now uses xterm's output from vttest. + */ CHARSETS['0'] = { '`': '\u25c6', // '◆' 'a': '\u2592', // '▒'