| // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| 'use strict'; |
| |
| lib.rtdep('lib.f'); |
| |
| /** |
| * Character map object. |
| * |
| * @param {object} The GL mapping from input characters to output characters. |
| * The GR mapping will be automatically created. |
| */ |
| hterm.VT.CharacterMap = function(name, glmap) { |
| /** |
| * Short name for this character set, useful for debugging. |
| */ |
| this.name = name; |
| |
| /** |
| * The function to call to when this map is installed in GL. |
| */ |
| this.GL = null; |
| |
| /** |
| * The function to call to when this map is installed in GR. |
| */ |
| this.GR = null; |
| |
| if (glmap) |
| this.reset(glmap); |
| }; |
| |
| /** |
| * @param {object} The GL mapping from input characters to output characters. |
| * The GR mapping will be automatically created. |
| */ |
| hterm.VT.CharacterMap.prototype.reset = function(glmap) { |
| // Set the the GL mapping. |
| this.glmap = glmap; |
| |
| var glkeys = Object.keys(this.glmap).map(function(key) { |
| return '\\x' + lib.f.zpad(key.charCodeAt(0).toString(16)); |
| }); |
| |
| this.glre = new RegExp('[' + glkeys.join('') + ']', 'g'); |
| |
| // Compute the GR mapping. |
| // This is the same as GL except all keys have their MSB set. |
| this.grmap = {}; |
| |
| glkeys.forEach(function(glkey) { |
| var grkey = String.fromCharCode(glkey.charCodeAt(0) & 0x80); |
| this.grmap[grkey] = this.glmap[glkey]; |
| }.bind(this)); |
| |
| var grkeys = Object.keys(this.grmap).map(function(key) { |
| return '\\x' + lib.f.zpad(key.charCodeAt(0).toString(16), 2); |
| }); |
| |
| this.grre = new RegExp('[' + grkeys.join('') + ']', 'g'); |
| |
| this.GL = function(str) { |
| return str.replace(this.glre, |
| function(ch) { return this.glmap[ch] }.bind(this)); |
| }.bind(this); |
| |
| this.GR = function(str) { |
| return str.replace(this.grre, |
| function(ch) { return this.grmap[ch] }.bind(this)); |
| }.bind(this); |
| }; |
| |
| /** |
| * Mapping from received to display character, used depending on the active |
| * VT character set. |
| */ |
| hterm.VT.CharacterMap.maps = {}; |
| |
| /** |
| * VT100 Graphic character map. |
| * http://vt100.net/docs/vt220-rm/table2-4.html |
| */ |
| hterm.VT.CharacterMap.maps['0'] = new hterm.VT.CharacterMap( |
| 'graphic', { |
| '\x60':'\u25c6', // ` -> diamond |
| '\x61':'\u2592', // a -> grey-box |
| '\x62':'\u2409', // b -> h/t |
| '\x63':'\u240c', // c -> f/f |
| '\x64':'\u240d', // d -> c/r |
| '\x65':'\u240a', // e -> l/f |
| '\x66':'\u00b0', // f -> degree |
| '\x67':'\u00b1', // g -> +/- |
| '\x68':'\u2424', // h -> n/l |
| '\x69':'\u240b', // i -> v/t |
| '\x6a':'\u2518', // j -> bottom-right |
| '\x6b':'\u2510', // k -> top-right |
| '\x6c':'\u250c', // l -> top-left |
| '\x6d':'\u2514', // m -> bottom-left |
| '\x6e':'\u253c', // n -> line-cross |
| '\x6f':'\u23ba', // o -> scan1 |
| '\x70':'\u23bb', // p -> scan3 |
| '\x71':'\u2500', // q -> scan5 |
| '\x72':'\u23bc', // r -> scan7 |
| '\x73':'\u23bd', // s -> scan9 |
| '\x74':'\u251c', // t -> left-tee |
| '\x75':'\u2524', // u -> right-tee |
| '\x76':'\u2534', // v -> bottom-tee |
| '\x77':'\u252c', // w -> top-tee |
| '\x78':'\u2502', // x -> vertical-line |
| '\x79':'\u2264', // y -> less-equal |
| '\x7a':'\u2265', // z -> greater-equal |
| '\x7b':'\u03c0', // { -> pi |
| '\x7c':'\u2260', // | -> not-equal |
| '\x7d':'\u00a3', // } -> british-pound |
| '\x7e':'\u00b7', // ~ -> dot |
| }); |
| |
| /** |
| * British character map. |
| * http://vt100.net/docs/vt220-rm/table2-5.html |
| */ |
| hterm.VT.CharacterMap.maps['A'] = new hterm.VT.CharacterMap( |
| 'british', { |
| '\x23': '\u00a3', // # -> british-pound |
| }); |
| |
| /** |
| * US ASCII map, no changes. |
| */ |
| hterm.VT.CharacterMap.maps['B'] = new hterm.VT.CharacterMap( |
| 'us', null); |
| |
| /** |
| * Dutch character map. |
| * http://vt100.net/docs/vt220-rm/table2-6.html |
| */ |
| hterm.VT.CharacterMap.maps['4'] = new hterm.VT.CharacterMap( |
| 'dutch', { |
| '\x23': '\u00a3', // # -> british-pound |
| |
| '\x40': '\u00be', // @ -> 3/4 |
| |
| '\x5b': '\u0132', // [ -> 'ij' ligature (xterm goes with \u00ff?) |
| '\x5c': '\u00bd', // \ -> 1/2 |
| '\x5d': '\u007c', // ] -> vertical bar |
| |
| '\x7b': '\u00a8', // { -> two dots |
| '\x7c': '\u0066', // | -> f |
| '\x7d': '\u00bc', // } -> 1/4 |
| '\x7e': '\u00b4', // ~ -> acute |
| }); |
| |
| /** |
| * Finnish character map. |
| * http://vt100.net/docs/vt220-rm/table2-7.html |
| */ |
| hterm.VT.CharacterMap.maps['C'] = |
| hterm.VT.CharacterMap.maps['5'] = new hterm.VT.CharacterMap( |
| 'finnish', { |
| '\x5b': '\u00c4', // [ -> 'A' umlaut |
| '\x5c': '\u00d6', // \ -> 'O' umlaut |
| '\x5d': '\u00c5', // ] -> 'A' ring |
| '\x5e': '\u00dc', // ~ -> 'u' umlaut |
| |
| '\x60': '\u00e9', // ` -> 'e' acute |
| |
| '\x7b': '\u00e4', // { -> 'a' umlaut |
| '\x7c': '\u00f6', // | -> 'o' umlaut |
| '\x7d': '\u00e5', // } -> 'a' ring |
| '\x7e': '\u00fc', // ~ -> 'u' umlaut |
| }); |
| |
| /** |
| * French character map. |
| * http://vt100.net/docs/vt220-rm/table2-8.html |
| */ |
| hterm.VT.CharacterMap.maps['R'] = new hterm.VT.CharacterMap( |
| 'french', { |
| '\x23': '\u00a3', // # -> british-pound |
| |
| '\x40': '\u00e0', // @ -> 'a' grave |
| |
| '\x5b': '\u00b0', // [ -> ring |
| '\x5c': '\u00e7', // \ -> 'c' cedilla |
| '\x5d': '\u00a7', // ] -> section symbol (double s) |
| |
| '\x7b': '\u00e9', // { -> 'e' acute |
| '\x7c': '\u00f9', // | -> 'u' grave |
| '\x7d': '\u00e8', // } -> 'e' grave |
| '\x7e': '\u00a8', // ~ -> umlaut |
| }); |
| |
| /** |
| * French Canadian character map. |
| * http://vt100.net/docs/vt220-rm/table2-9.html |
| */ |
| hterm.VT.CharacterMap.maps['Q'] = new hterm.VT.CharacterMap( |
| 'french canadian', { |
| '\x40': '\u00e0', // @ -> 'a' grave |
| |
| '\x5b': '\u00e2', // [ -> 'a' circumflex |
| '\x5c': '\u00e7', // \ -> 'c' cedilla |
| '\x5d': '\u00ea', // ] -> 'e' circumflex |
| '\x5e': '\u00ee', // ^ -> 'i' circumflex |
| |
| '\x60': '\u00f4', // ` -> 'o' circumflex |
| |
| '\x7b': '\u00e9', // { -> 'e' acute |
| '\x7c': '\u00f9', // | -> 'u' grave |
| '\x7d': '\u00e8', // } -> 'e' grave |
| '\x7e': '\u00fb', // ~ -> 'u' circumflex |
| }); |
| |
| /** |
| * German character map. |
| * http://vt100.net/docs/vt220-rm/table2-10.html |
| */ |
| hterm.VT.CharacterMap.maps['K'] = new hterm.VT.CharacterMap( |
| 'german', { |
| '\x40': '\u00a7', // @ -> section symbol (double s) |
| |
| '\x5b': '\u00c4', // [ -> 'A' umlaut |
| '\x5c': '\u00d6', // \ -> 'O' umlaut |
| '\x5d': '\u00dc', // ] -> 'U' umlaut |
| |
| '\x7b': '\u00e4', // { -> 'a' umlaut |
| '\x7c': '\u00f6', // | -> 'o' umlaut |
| '\x7d': '\u00fc', // } -> 'u' umlaut |
| '\x7e': '\u00df', // ~ -> eszett |
| }); |
| |
| /** |
| * Italian character map. |
| * http://vt100.net/docs/vt220-rm/table2-11.html |
| */ |
| hterm.VT.CharacterMap.maps['Y'] = new hterm.VT.CharacterMap( |
| 'italian', { |
| '\x23': '\u00a3', // # -> british-pound |
| |
| '\x40': '\u00a7', // @ -> section symbol (double s) |
| |
| '\x5b': '\u00b0', // [ -> ring |
| '\x5c': '\u00e7', // \ -> 'c' cedilla |
| '\x5d': '\u00e9', // ] -> 'e' acute |
| |
| '\x60': '\u00f9', // ` -> 'u' grave |
| |
| '\x7b': '\u00e0', // { -> 'a' grave |
| '\x7c': '\u00f2', // | -> 'o' grave |
| '\x7d': '\u00e8', // } -> 'e' grave |
| '\x7e': '\u00ec', // ~ -> 'i' grave |
| }); |
| |
| /** |
| * Norwegian/Danish character map. |
| * http://vt100.net/docs/vt220-rm/table2-12.html |
| */ |
| hterm.VT.CharacterMap.maps['E'] = |
| hterm.VT.CharacterMap.maps['6'] = new hterm.VT.CharacterMap( |
| 'norwegian/danish', { |
| '\x40': '\u00c4', // @ -> 'A' umlaut |
| |
| '\x5b': '\u00c6', // [ -> 'AE' ligature |
| '\x5c': '\u00d8', // \ -> 'O' stroke |
| '\x5d': '\u00c5', // ] -> 'A' ring |
| '\x5e': '\u00dc', // ^ -> 'U' umlaut |
| |
| '\x60': '\u00e4', // ` -> 'a' umlaut |
| |
| '\x7b': '\u00e6', // { -> 'ae' ligature |
| '\x7c': '\u00f8', // | -> 'o' stroke |
| '\x7d': '\u00e5', // } -> 'a' ring |
| '\x7e': '\u00fc', // ~ -> 'u' umlaut |
| }); |
| |
| /** |
| * Spanish character map. |
| * http://vt100.net/docs/vt220-rm/table2-13.html |
| */ |
| hterm.VT.CharacterMap.maps['Z'] = new hterm.VT.CharacterMap( |
| 'spanish', { |
| '\x23': '\u00a3', // # -> british-pound |
| |
| '\x40': '\u00a7', // @ -> section symbol (double s) |
| |
| '\x5b': '\u00a1', // [ -> '!' inverted |
| '\x5c': '\u00d1', // \ -> 'N' tilde |
| '\x5d': '\u00bf', // ] -> '?' inverted |
| |
| '\x7b': '\u00b0', // { -> ring |
| '\x7c': '\u00f1', // | -> 'n' tilde |
| '\x7d': '\u00e7', // } -> 'c' cedilla |
| }); |
| |
| /** |
| * Swedish character map. |
| * http://vt100.net/docs/vt220-rm/table2-14.html |
| */ |
| hterm.VT.CharacterMap.maps['7'] = |
| hterm.VT.CharacterMap.maps['H'] = new hterm.VT.CharacterMap( |
| 'swedish', { |
| '\x40': '\u00c9', // @ -> 'E' acute |
| |
| '\x5b': '\u00c4', // [ -> 'A' umlaut |
| '\x5c': '\u00d6', // \ -> 'O' umlaut |
| '\x5d': '\u00c5', // ] -> 'A' ring |
| '\x5e': '\u00dc', // ^ -> 'U' umlaut |
| |
| '\x60': '\u00e9', // ` -> 'e' acute |
| |
| '\x7b': '\u00e4', // { -> 'a' umlaut |
| '\x7c': '\u00f6', // | -> 'o' umlaut |
| '\x7d': '\u00e5', // } -> 'a' ring |
| '\x7e': '\u00fc', // ~ -> 'u' umlaut |
| }); |
| |
| /** |
| * Swiss character map. |
| * http://vt100.net/docs/vt220-rm/table2-15.html |
| */ |
| hterm.VT.CharacterMap.maps['='] = new hterm.VT.CharacterMap( |
| 'swiss', { |
| '\x23': '\u00f9', // # -> 'u' grave |
| |
| '\x40': '\u00e0', // @ -> 'a' grave |
| |
| '\x5b': '\u00e9', // [ -> 'e' acute |
| '\x5c': '\u00e7', // \ -> 'c' cedilla |
| '\x5d': '\u00ea', // ] -> 'e' circumflex |
| '\x5e': '\u00ee', // ^ -> 'i' circumflex |
| '\x5f': '\u00e8', // _ -> 'e' grave |
| |
| '\x60': '\u00f4', // ` -> 'o' circumflex |
| |
| '\x7b': '\u00e4', // { -> 'a' umlaut |
| '\x7c': '\u00f6', // | -> 'o' umlaut |
| '\x7d': '\u00fc', // } -> 'u' umlaut |
| '\x7e': '\u00fb', // ~ -> 'u' circumflex |
| }); |