From c7fdff2f40a77f0ae2b0c19556086dd53cc06dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Breitbart?= Date: Tue, 1 May 2018 17:50:41 +0200 Subject: [PATCH] several changes: - missing escape sequence related methods in InputHandler implemented - created namespace for C1 control codes --- src/EscapeSequences.ts | 71 +++++++++++++++++++++++++++++++++++ src/InputHandler.ts | 85 ++++++++++++++++++++++++++++++++++++------ src/Types.ts | 21 ++++++++--- 3 files changed, 159 insertions(+), 18 deletions(-) diff --git a/src/EscapeSequences.ts b/src/EscapeSequences.ts index 11cbd84e..e35f01dd 100644 --- a/src/EscapeSequences.ts +++ b/src/EscapeSequences.ts @@ -77,3 +77,74 @@ export namespace C0 { /** Delete (Caret = ^?) */ export const DEL = '\x7f'; } + +/** + * C1 control codes + * See = https://en.wikipedia.org/wiki/C0_and_C1_control_codes + */ +export namespace C1 { + /** padding character */ + export const PAD = '\x80'; + /** High Octet Preset */ + export const HOP = '\x81'; + /** Break Permitted Here */ + export const BPH = '\x82'; + /** No Break Here */ + export const NBH = '\x83'; + /** Index */ + export const IND = '\x84'; + /** Next Line */ + export const NEL = '\x85'; + /** Start of Selected Area */ + export const SSA = '\x86'; + /** End of Selected Area */ + export const ESA = '\x87'; + /** Horizontal Tabulation Set */ + export const HTS = '\x88'; + /** Horizontal Tabulation With Justification */ + export const HTJ = '\x89'; + /** Vertical Tabulation Set */ + export const VTS = '\x8a'; + /** Partial Line Down */ + export const PLD = '\x8b'; + /** Partial Line Up */ + export const PLU = '\x8c'; + /** Reverse Index */ + export const RI = '\x8d'; + /** Single-Shift 2 */ + export const SS2 = '\x8e'; + /** Single-Shift 3 */ + export const SS3 = '\x8f'; + /** Device Control String */ + export const DCS = '\x90'; + /** Private Use 1 */ + export const PU1 = '\x91'; + /** Private Use 2 */ + export const PU2 = '\x92'; + /** Set Transmit State */ + export const STS = '\x93'; + /** Destructive backspace, intended to eliminate ambiguity about meaning of BS. */ + export const CCH = '\x94'; + /** Message Waiting */ + export const MW = '\x95'; + /** Start of Protected Area */ + export const SPA = '\x96'; + /** End of Protected Area */ + export const EPA = '\x97'; + /** Start of String */ + export const SOS = '\x98'; + /** Single Graphic Character Introducer */ + export const SGCI = '\x99'; + /** Single Character Introducer */ + export const SCI = '\x9a'; + /** Control Sequence Introducer */ + export const CSI = '\x9b'; + /** String Terminator */ + export const ST = '\x9c'; + /** Operating System Command */ + export const OSC = '\x9d'; + /** Privacy Message */ + export const PM = '\x9e'; + /** Application Program Command */ + export const APC = '\x9f'; +} diff --git a/src/InputHandler.ts b/src/InputHandler.ts index 8339a8be..4779435a 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -5,7 +5,7 @@ */ import { CharData, IInputHandler } from './Types'; -import { C0 } from './EscapeSequences'; +import { C0, C1 } from './EscapeSequences'; import { CHARSETS, DEFAULT_CHARSET } from './Charsets'; import { CHAR_DATA_CHAR_INDEX, CHAR_DATA_WIDTH_INDEX } from './Buffer'; import { FLAGS } from './renderer/Types'; @@ -108,6 +108,11 @@ export class InputHandler implements IInputHandler { // FIXME: What do to with missing? Old code just added those to print, but that's wrong // behavior for most control codes. + // some C1 control codes - should those be enabled by default? + this._parser.setExecuteHandler(C1.IND, () => this.index()); + this._parser.setExecuteHandler(C1.NEL, () => this.nextLine()); + this._parser.setExecuteHandler(C1.HTS, () => this.tabSet()); + /** * OSC handler */ @@ -154,18 +159,18 @@ export class InputHandler implements IInputHandler { */ this._parser.setEscHandler('', '7', () => this.saveCursor([])); this._parser.setEscHandler('', '8', () => this.restoreCursor([])); - this._parser.setEscHandler('', 'D', () => this._terminal.index()); // FIXME: move? + this._parser.setEscHandler('', 'D', () => this.index()); this._parser.setEscHandler('', 'E', () => this.nextLine()); - this._parser.setEscHandler('', 'H', () => this._terminal.tabSet()); // FIXME: move? - this._parser.setEscHandler('', 'M', () => this._terminal.reverseIndex()); // FIXME: move? + this._parser.setEscHandler('', 'H', () => this.tabSet()); + this._parser.setEscHandler('', 'M', () => this.reverseIndex()); this._parser.setEscHandler('', '=', () => this.keypadApplicationMode()); this._parser.setEscHandler('', '>', () => this.keypadNumericMode()); - this._parser.setEscHandler('', 'c', () => this._terminal.reset()); // FIXME: move? - this._parser.setEscHandler('', 'n', () => this._terminal.setgLevel(2)); // FIXME: move? - this._parser.setEscHandler('', 'o', () => this._terminal.setgLevel(3)); // FIXME: move? - this._parser.setEscHandler('', '|', () => this._terminal.setgLevel(3)); // FIXME: move? - this._parser.setEscHandler('', '}', () => this._terminal.setgLevel(2)); // FIXME: move? - this._parser.setEscHandler('', '~', () => this._terminal.setgLevel(1)); // FIXME: move? + this._parser.setEscHandler('', 'c', () => this.reset()); + this._parser.setEscHandler('', 'n', () => this.setgLevel(2)); + this._parser.setEscHandler('', 'o', () => this.setgLevel(3)); + this._parser.setEscHandler('', '|', () => this.setgLevel(3)); + this._parser.setEscHandler('', '}', () => this.setgLevel(2)); + this._parser.setEscHandler('', '~', () => this.setgLevel(1)); this._parser.setEscHandler('%', '@', () => this.selectDefaultCharset()); this._parser.setEscHandler('%', 'G', () => this.selectDefaultCharset()); for (let flag in CHARSETS) { @@ -175,7 +180,7 @@ export class InputHandler implements IInputHandler { this._parser.setEscHandler('+', flag, () => this.selectCharset('+' + flag)); this._parser.setEscHandler('-', flag, () => this.selectCharset('-' + flag)); this._parser.setEscHandler('.', flag, () => this.selectCharset('.' + flag)); - this._parser.setEscHandler('/', flag, () => this.selectCharset('/' + flag)); // FIXME + this._parser.setEscHandler('/', flag, () => this.selectCharset('/' + flag)); // FIXME: supported? } /** @@ -1727,12 +1732,13 @@ export class InputHandler implements IInputHandler { /** * ESC E + * C1.NEL * DEC mnemonic: NEL (https://vt100.net/docs/vt510-rm/NEL) * Moves cursor to first position on next line. */ public nextLine(): void { this._terminal.buffer.x = 0; - this._terminal.index(); + this.index(); } /** @@ -1793,4 +1799,59 @@ export class InputHandler implements IInputHandler { if (collectAndFlag[0] === '/') return; // FIXME: Is this supported? this._terminal.setgCharset(GLEVEL[collectAndFlag[0]], CHARSETS[collectAndFlag[1]] || DEFAULT_CHARSET); } + + /** + * ESC D + * C1.IND + * DEC mnemonic: IND (https://vt100.net/docs/vt510-rm/IND.html) + * Moves the cursor down one line in the same column. + */ + public index(): void { + this._terminal.index(); // FIXME: save to move the implementation from terminal? + } + + /** + * ESC H + * C1.HTS + * DEC mnemonic: HTS (https://vt100.net/docs/vt510-rm/HTS.html) + * Sets a horizontal tab stop at the column position indicated by + * the value of the active column when the terminal receives an HTS. + */ + public tabSet(): void { + this._terminal.tabSet(); // FIXME: save to move the implementation from terminal? + } + + /** + * ESC M + * C1.RI + * DEC mnemonic: HTS + * Moves the cursor up one line in the same column. If the cursor is at the top margin, + * the page scrolls down. + */ + public reverseIndex(): void { + this._terminal.reverseIndex(); // FIXME: save to move the implementation from terminal? + } + + /** + * ESC c + * DEC mnemonic: RIS (https://vt100.net/docs/vt510-rm/RIS.html) + * Reset to initial state. + */ + public reset(): void { + this._terminal.reset(); // FIXME: save to move the implementation from terminal? + } + + /** + * ESC n + * ESC o + * ESC | + * ESC } + * ESC ~ + * DEC mnemonic: LS (https://vt100.net/docs/vt510-rm/LS.html) + * When you use a locking shift, the character set remains in GL or GR until + * you use another locking shift. (partly supported) + */ + public setgLevel(level: number): void { + this._terminal.setgLevel(level); // FIXME: save to move the implementation from terminal? + } } diff --git a/src/Types.ts b/src/Types.ts index 59efe71f..8cc5ae2c 100644 --- a/src/Types.ts +++ b/src/Types.ts @@ -163,12 +163,21 @@ export interface IInputHandler { /** ESC % G ESC % @ */ selectDefaultCharset(): void; /** ESC ( C - * ESC ) C - * ESC * C - * ESC + C - * ESC - C - * ESC . C - * ESC / C */ selectCharset(collectAndFlag: string): void; + ESC ) C + ESC * C + ESC + C + ESC - C + ESC . C + ESC / C */ selectCharset(collectAndFlag: string): void; + /** ESC D */ index(): void; + /** ESC H */ tabSet(): void; + /** ESC M */ reverseIndex(): void; + /** ESC c */ reset(): void; + /** ESC n + ESC o + ESC | + ESC } + ESC ~ */ setgLevel(level: number): void; } export interface ILinkMatcher {