Merge branch 'master' into cleanup_sequences_files
This commit is contained in:
+180
-190
@@ -14,13 +14,13 @@ import { concat } from 'common/TypedArrayUtils';
|
||||
import { StringToUtf32, stringFromCodePoint, utf32ToString, Utf8ToUtf32 } from 'common/input/TextDecoder';
|
||||
import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
|
||||
import { EventEmitter, IEvent } from 'common/EventEmitter';
|
||||
import { IParsingState, IDcsHandler, IEscapeSequenceParser } from 'common/parser/Types';
|
||||
import { IParsingState, IDcsHandler, IEscapeSequenceParser, IParams } from 'common/parser/Types';
|
||||
import { NULL_CELL_CODE, NULL_CELL_WIDTH, Attributes, FgFlags, BgFlags, Content } from 'common/buffer/Constants';
|
||||
import { CellData } from 'common/buffer/CellData';
|
||||
import { AttributeData } from 'common/buffer/AttributeData';
|
||||
import { IAttributeData, IDisposable } from 'common/Types';
|
||||
import { ICoreService } from 'common/services/Services';
|
||||
import { ISelectionService } from 'browser/services/Services';
|
||||
import { IDisposable } from 'common/Types';
|
||||
|
||||
/**
|
||||
* Map collect to glevel. Used in `selectCharset`.
|
||||
@@ -43,7 +43,7 @@ class DECRQSS implements IDcsHandler {
|
||||
|
||||
constructor(private _terminal: any) { }
|
||||
|
||||
hook(collect: string, params: number[], flag: number): void {
|
||||
hook(collect: string, params: IParams, flag: number): void {
|
||||
this._data = new Uint32Array(0);
|
||||
}
|
||||
|
||||
@@ -134,8 +134,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
/**
|
||||
* custom fallback handlers
|
||||
*/
|
||||
this._parser.setCsiHandlerFallback((collect: string, params: number[], flag: number) => {
|
||||
this._terminal.error('Unknown CSI code: ', { collect, params, flag: String.fromCharCode(flag) });
|
||||
this._parser.setCsiHandlerFallback((collect: string, params: IParams, flag: number) => {
|
||||
this._terminal.error('Unknown CSI code: ', { collect, params: params.toArray(), flag: String.fromCharCode(flag) });
|
||||
});
|
||||
this._parser.setEscHandlerFallback((collect: string, flag: number) => {
|
||||
this._terminal.error('Unknown ESC code: ', { collect, flag: String.fromCharCode(flag) });
|
||||
@@ -255,8 +255,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
/**
|
||||
* ESC handlers
|
||||
*/
|
||||
this._parser.setEscHandler('7', () => this.saveCursor([]));
|
||||
this._parser.setEscHandler('8', () => this.restoreCursor([]));
|
||||
this._parser.setEscHandler('7', () => this.saveCursor());
|
||||
this._parser.setEscHandler('8', () => this.restoreCursor());
|
||||
this._parser.setEscHandler('D', () => this.index());
|
||||
this._parser.setEscHandler('E', () => this.nextLine());
|
||||
this._parser.setEscHandler('H', () => this.tabSet());
|
||||
@@ -485,7 +485,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
/**
|
||||
* Forward addCsiHandler from parser.
|
||||
*/
|
||||
public addCsiHandler(flag: string, callback: (params: number[], collect: string) => boolean): IDisposable {
|
||||
public addCsiHandler(flag: string, callback: (params: IParams, collect: string) => boolean): IDisposable {
|
||||
return this._parser.addCsiHandler(flag, callback);
|
||||
}
|
||||
|
||||
@@ -586,13 +586,13 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* CSI Ps @
|
||||
* Insert Ps (Blank) Character(s) (default = 1) (ICH).
|
||||
*/
|
||||
public insertChars(params: number[]): void {
|
||||
public insertChars(params: IParams): void {
|
||||
if (this._terminal.buffer.x >= this._terminal.cols) {
|
||||
this._terminal.buffer.x = this._terminal.cols - 1;
|
||||
}
|
||||
this._terminal.buffer.lines.get(this._terminal.buffer.y + this._terminal.buffer.ybase).insertCells(
|
||||
this._terminal.buffer.x,
|
||||
params[0] || 1,
|
||||
params.params[0] || 1,
|
||||
this._terminal.buffer.getNullCell(this._terminal.eraseAttrData())
|
||||
);
|
||||
this._terminal.updateRange(this._terminal.buffer.y);
|
||||
@@ -635,48 +635,32 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* CSI Ps A
|
||||
* Cursor Up Ps Times (default = 1) (CUU).
|
||||
*/
|
||||
public cursorUp(params: number[]): void {
|
||||
let param = params[0];
|
||||
if (param < 1) {
|
||||
param = 1;
|
||||
}
|
||||
this._moveCursor(0, -param);
|
||||
public cursorUp(params: IParams): void {
|
||||
this._moveCursor(0, -(params.params[0] || 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* CSI Ps B
|
||||
* Cursor Down Ps Times (default = 1) (CUD).
|
||||
*/
|
||||
public cursorDown(params: number[]): void {
|
||||
let param = params[0];
|
||||
if (param < 1) {
|
||||
param = 1;
|
||||
}
|
||||
this._moveCursor(0, param);
|
||||
public cursorDown(params: IParams): void {
|
||||
this._moveCursor(0, params.params[0] || 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* CSI Ps C
|
||||
* Cursor Forward Ps Times (default = 1) (CUF).
|
||||
*/
|
||||
public cursorForward(params: number[]): void {
|
||||
let param = params[0];
|
||||
if (param < 1) {
|
||||
param = 1;
|
||||
}
|
||||
this._moveCursor(param, 0);
|
||||
public cursorForward(params: IParams): void {
|
||||
this._moveCursor(params.params[0] || 1, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* CSI Ps D
|
||||
* Cursor Backward Ps Times (default = 1) (CUB).
|
||||
*/
|
||||
public cursorBackward(params: number[]): void {
|
||||
let param = params[0];
|
||||
if (param < 1) {
|
||||
param = 1;
|
||||
}
|
||||
this._moveCursor(-param, 0);
|
||||
public cursorBackward(params: IParams): void {
|
||||
this._moveCursor(-(params.params[0] || 1), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -684,12 +668,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Cursor Next Line Ps Times (default = 1) (CNL).
|
||||
* Other than cursorDown (CUD) also set the cursor to first column.
|
||||
*/
|
||||
public cursorNextLine(params: number[]): void {
|
||||
let param = params[0];
|
||||
if (param < 1) {
|
||||
param = 1;
|
||||
}
|
||||
this._moveCursor(0, param);
|
||||
public cursorNextLine(params: IParams): void {
|
||||
this._moveCursor(0, params.params[0] || 1);
|
||||
this._terminal.buffer.x = 0;
|
||||
}
|
||||
|
||||
@@ -699,12 +679,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Cursor Previous Line Ps Times (default = 1) (CPL).
|
||||
* Other than cursorUp (CUU) also set the cursor to first column.
|
||||
*/
|
||||
public cursorPrecedingLine(params: number[]): void {
|
||||
let param = params[0];
|
||||
if (param < 1) {
|
||||
param = 1;
|
||||
}
|
||||
this._moveCursor(0, -param);
|
||||
public cursorPrecedingLine(params: IParams): void {
|
||||
this._moveCursor(0, -(params.params[0] || 1));
|
||||
this._terminal.buffer.x = 0;
|
||||
}
|
||||
|
||||
@@ -713,39 +689,31 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* CSI Ps G
|
||||
* Cursor Character Absolute [column] (default = [row,1]) (CHA).
|
||||
*/
|
||||
public cursorCharAbsolute(params: number[]): void {
|
||||
let param = params[0];
|
||||
if (param < 1) {
|
||||
param = 1;
|
||||
}
|
||||
this._setCursor(param - 1, this._terminal.buffer.y);
|
||||
public cursorCharAbsolute(params: IParams): void {
|
||||
this._setCursor((params.params[0] || 1) - 1, this._terminal.buffer.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* CSI Ps ; Ps H
|
||||
* Cursor Position [row;column] (default = [1,1]) (CUP).
|
||||
*/
|
||||
public cursorPosition(params: number[]): void {
|
||||
let col: number;
|
||||
const row: number = params[0] - 1;
|
||||
|
||||
if (params.length >= 2) {
|
||||
col = params[1] - 1;
|
||||
} else {
|
||||
col = 0;
|
||||
}
|
||||
this._setCursor(col, row);
|
||||
public cursorPosition(params: IParams): void {
|
||||
this._setCursor(
|
||||
// col
|
||||
(params.length >= 2) ? (params.params[1] || 1) - 1 : 0,
|
||||
// row
|
||||
(params.params[0] || 1) - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* CSI Ps I
|
||||
* Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
|
||||
*/
|
||||
public cursorForwardTab(params: number[]): void {
|
||||
public cursorForwardTab(params: IParams): void {
|
||||
if (this._terminal.buffer.x >= this._terminal.cols) {
|
||||
return;
|
||||
}
|
||||
let param = params[0] || 1;
|
||||
let param = params.params[0] || 1;
|
||||
while (param--) {
|
||||
this._terminal.buffer.x = this._terminal.buffer.nextStop();
|
||||
}
|
||||
@@ -791,9 +759,9 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Ps = 1 -> Selective Erase Above.
|
||||
* Ps = 2 -> Selective Erase All.
|
||||
*/
|
||||
public eraseInDisplay(params: number[]): void {
|
||||
public eraseInDisplay(params: IParams): void {
|
||||
let j;
|
||||
switch (params[0]) {
|
||||
switch (params.params[0]) {
|
||||
case 0:
|
||||
j = this._terminal.buffer.y;
|
||||
this._terminal.updateRange(j);
|
||||
@@ -850,11 +818,11 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Ps = 1 -> Selective Erase to Left.
|
||||
* Ps = 2 -> Selective Erase All.
|
||||
*/
|
||||
public eraseInLine(params: number[]): void {
|
||||
public eraseInLine(params: IParams): void {
|
||||
if (this._terminal.buffer.x >= this._terminal.cols) {
|
||||
this._terminal.buffer.x = this._terminal.cols - 1;
|
||||
}
|
||||
switch (params[0]) {
|
||||
switch (params.params[0]) {
|
||||
case 0:
|
||||
this._eraseInBufferLine(this._terminal.buffer.y, this._terminal.buffer.x, this._terminal.cols);
|
||||
break;
|
||||
@@ -872,11 +840,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* CSI Ps L
|
||||
* Insert Ps Line(s) (default = 1) (IL).
|
||||
*/
|
||||
public insertLines(params: number[]): void {
|
||||
let param: number = params[0];
|
||||
if (param < 1) {
|
||||
param = 1;
|
||||
}
|
||||
public insertLines(params: IParams): void {
|
||||
let param = params.params[0] || 1;
|
||||
|
||||
// make buffer local for faster access
|
||||
const buffer = this._terminal.buffer;
|
||||
@@ -902,11 +867,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* CSI Ps M
|
||||
* Delete Ps Line(s) (default = 1) (DL).
|
||||
*/
|
||||
public deleteLines(params: number[]): void {
|
||||
let param = params[0];
|
||||
if (param < 1) {
|
||||
param = 1;
|
||||
}
|
||||
public deleteLines(params: IParams): void {
|
||||
let param = params.params[0] || 1;
|
||||
|
||||
// make buffer local for faster access
|
||||
const buffer = this._terminal.buffer;
|
||||
@@ -933,10 +895,10 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* CSI Ps P
|
||||
* Delete Ps Character(s) (default = 1) (DCH).
|
||||
*/
|
||||
public deleteChars(params: number[]): void {
|
||||
public deleteChars(params: IParams): void {
|
||||
this._terminal.buffer.lines.get(this._terminal.buffer.y + this._terminal.buffer.ybase).deleteCells(
|
||||
this._terminal.buffer.x,
|
||||
params[0] || 1,
|
||||
params.params[0] || 1,
|
||||
this._terminal.buffer.getNullCell(this._terminal.eraseAttrData())
|
||||
);
|
||||
this._terminal.updateRange(this._terminal.buffer.y);
|
||||
@@ -945,8 +907,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
/**
|
||||
* CSI Ps S Scroll up Ps lines (default = 1) (SU).
|
||||
*/
|
||||
public scrollUp(params: number[]): void {
|
||||
let param = params[0] || 1;
|
||||
public scrollUp(params: IParams): void {
|
||||
let param = params.params[0] || 1;
|
||||
|
||||
// make buffer local for faster access
|
||||
const buffer = this._terminal.buffer;
|
||||
@@ -963,9 +925,9 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
/**
|
||||
* CSI Ps T Scroll down Ps lines (default = 1) (SD).
|
||||
*/
|
||||
public scrollDown(params: number[], collect?: string): void {
|
||||
public scrollDown(params: IParams, collect?: string): void {
|
||||
if (params.length < 2 && !collect) {
|
||||
let param = params[0] || 1;
|
||||
let param = params.params[0] || 1;
|
||||
|
||||
// make buffer local for faster access
|
||||
const buffer = this._terminal.buffer;
|
||||
@@ -984,10 +946,10 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* CSI Ps X
|
||||
* Erase Ps Character(s) (default = 1) (ECH).
|
||||
*/
|
||||
public eraseChars(params: number[]): void {
|
||||
public eraseChars(params: IParams): void {
|
||||
this._terminal.buffer.lines.get(this._terminal.buffer.y + this._terminal.buffer.ybase).replaceCells(
|
||||
this._terminal.buffer.x,
|
||||
this._terminal.buffer.x + (params[0] || 1),
|
||||
this._terminal.buffer.x + (params.params[0] || 1),
|
||||
this._terminal.buffer.getNullCell(this._terminal.eraseAttrData())
|
||||
);
|
||||
this._terminal.updateRange(this._terminal.buffer.y);
|
||||
@@ -996,8 +958,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
/**
|
||||
* CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
|
||||
*/
|
||||
public cursorBackwardTab(params: number[]): void {
|
||||
let param = params[0] || 1;
|
||||
public cursorBackwardTab(params: IParams): void {
|
||||
let param = params.params[0] || 1;
|
||||
|
||||
// make buffer local for faster access
|
||||
const buffer = this._terminal.buffer;
|
||||
@@ -1012,12 +974,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* [column] (default = [row,1]) (HPA).
|
||||
* Currently same functionality as CHA.
|
||||
*/
|
||||
public charPosAbsolute(params: number[]): void {
|
||||
let param = params[0];
|
||||
if (param < 1) {
|
||||
param = 1;
|
||||
}
|
||||
this._setCursor(param - 1, this._terminal.buffer.y);
|
||||
public charPosAbsolute(params: IParams): void {
|
||||
this._setCursor((params.params[0] || 1) - 1, this._terminal.buffer.y);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1025,12 +983,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* [columns] (default = [row,col+1]) (HPR)
|
||||
* Currently same functionality as CUF.
|
||||
*/
|
||||
public hPositionRelative(params: number[]): void {
|
||||
let param = params[0];
|
||||
if (param < 1) {
|
||||
param = 1;
|
||||
}
|
||||
this._moveCursor(param, 0);
|
||||
public hPositionRelative(params: IParams): void {
|
||||
this._moveCursor(params.params[0] || 1, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1055,12 +1009,12 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Note: To get reset on a valid sequence working correctly without much runtime penalty,
|
||||
* the preceding codepoint is stored on the parser in `this.print` and reset during `parser.parse`.
|
||||
*/
|
||||
public repeatPrecedingCharacter(params: number[]): void {
|
||||
public repeatPrecedingCharacter(params: IParams): void {
|
||||
if (!this._parser.precedingCodepoint) {
|
||||
return;
|
||||
}
|
||||
// call print to insert the chars and handle correct wrapping
|
||||
const length = params[0] || 1;
|
||||
const length = params.params[0] || 1;
|
||||
const data = new Uint32Array(length);
|
||||
for (let i = 0; i < length; ++i) {
|
||||
data[i] = this._parser.precedingCodepoint;
|
||||
@@ -1105,8 +1059,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* xterm/charproc.c - line 2012, for more information.
|
||||
* vim responds with ^[[?0c or ^[[?1c after the terminal's response (?)
|
||||
*/
|
||||
public sendDeviceAttributes(params: number[], collect?: string): void {
|
||||
if (params[0] > 0) {
|
||||
public sendDeviceAttributes(params: IParams, collect?: string): void {
|
||||
if (params.params[0] > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1127,7 +1081,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
} else if (this._terminal.is('linux')) {
|
||||
// not supported by linux console.
|
||||
// linux console echoes parameters.
|
||||
this._coreService.triggerDataEvent(params[0] + 'c');
|
||||
this._coreService.triggerDataEvent(params.params[0] + 'c');
|
||||
} else if (this._terminal.is('screen')) {
|
||||
this._coreService.triggerDataEvent(C0.ESC + '[>83;40003;0c');
|
||||
}
|
||||
@@ -1138,12 +1092,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* CSI Pm d Vertical Position Absolute (VPA)
|
||||
* [row] (default = [1,column])
|
||||
*/
|
||||
public linePosAbsolute(params: number[]): void {
|
||||
let param = params[0];
|
||||
if (param < 1) {
|
||||
param = 1;
|
||||
}
|
||||
this._setCursor(this._terminal.buffer.x, param - 1);
|
||||
public linePosAbsolute(params: IParams): void {
|
||||
this._setCursor(this._terminal.buffer.x, (params.params[0] || 1) - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1151,12 +1101,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* [rows] (default = [row+1,column])
|
||||
* reuse CSI Ps B ?
|
||||
*/
|
||||
public vPositionRelative(params: number[]): void {
|
||||
let param = params[0];
|
||||
if (param < 1) {
|
||||
param = 1;
|
||||
}
|
||||
this._moveCursor(0, param);
|
||||
public vPositionRelative(params: IParams): void {
|
||||
this._moveCursor(0, params.params[0] || 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1165,7 +1111,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* [1,1]) (HVP).
|
||||
* Same as CUP.
|
||||
*/
|
||||
public hVPosition(params: number[]): void {
|
||||
public hVPosition(params: IParams): void {
|
||||
this.cursorPosition(params);
|
||||
}
|
||||
|
||||
@@ -1177,9 +1123,9 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Ps = 2 -> Clear Stops on Line.
|
||||
* http://vt100.net/annarbor/aaa-ug/section6.html
|
||||
*/
|
||||
public tabClear(params: number[]): void {
|
||||
const param = params[0];
|
||||
if (param <= 0) {
|
||||
public tabClear(params: IParams): void {
|
||||
const param = params.params[0];
|
||||
if (param === 0) {
|
||||
delete this._terminal.buffer.tabs[this._terminal.buffer.x];
|
||||
} else if (param === 3) {
|
||||
this._terminal.buffer.tabs = {};
|
||||
@@ -1272,17 +1218,15 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Modes:
|
||||
* http: *vt100.net/docs/vt220-rm/chapter4.html
|
||||
*/
|
||||
public setMode(params: number[], collect?: string): void {
|
||||
if (params.length > 1) {
|
||||
for (let i = 0; i < params.length; i++) {
|
||||
this.setMode([params[i]]);
|
||||
}
|
||||
|
||||
return;
|
||||
public setMode(params: IParams, collect?: string): void {
|
||||
for (let i = 0; i < params.length; i++) {
|
||||
this._setMode(params.params[i], collect);
|
||||
}
|
||||
}
|
||||
|
||||
private _setMode(param: number, collect?: string): void {
|
||||
if (!collect) {
|
||||
switch (params[0]) {
|
||||
switch (param) {
|
||||
case 4:
|
||||
this._terminal.insertMode = true;
|
||||
break;
|
||||
@@ -1291,7 +1235,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
break;
|
||||
}
|
||||
} else if (collect === '?') {
|
||||
switch (params[0]) {
|
||||
switch (param) {
|
||||
case 1:
|
||||
this._coreService.decPrivateModes.applicationCursorKeys = true;
|
||||
break;
|
||||
@@ -1334,9 +1278,9 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
|
||||
// TODO: Why are params[0] compares nested within a switch for params[0]?
|
||||
|
||||
this._terminal.x10Mouse = params[0] === 9;
|
||||
this._terminal.vt200Mouse = params[0] === 1000;
|
||||
this._terminal.normalMouse = params[0] > 1000;
|
||||
this._terminal.x10Mouse = param === 9;
|
||||
this._terminal.vt200Mouse = param === 1000;
|
||||
this._terminal.normalMouse = param > 1000;
|
||||
this._terminal.mouseEvents = true;
|
||||
if (this._terminal.element) {
|
||||
this._terminal.element.classList.add('enable-mouse-events');
|
||||
@@ -1374,10 +1318,10 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
this._terminal.cursorHidden = false;
|
||||
break;
|
||||
case 1048: // alt screen cursor
|
||||
this.saveCursor(params);
|
||||
this.saveCursor();
|
||||
break;
|
||||
case 1049: // alt screen buffer cursor
|
||||
this.saveCursor(params);
|
||||
this.saveCursor();
|
||||
// FALL-THROUGH
|
||||
case 47: // alt screen buffer
|
||||
case 1047: // alt screen buffer
|
||||
@@ -1477,17 +1421,15 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Ps = 1 0 6 1 -> Reset keyboard emulation to Sun/PC style.
|
||||
* Ps = 2 0 0 4 -> Reset bracketed paste mode.
|
||||
*/
|
||||
public resetMode(params: number[], collect?: string): void {
|
||||
if (params.length > 1) {
|
||||
for (let i = 0; i < params.length; i++) {
|
||||
this.resetMode([params[i]]);
|
||||
}
|
||||
|
||||
return;
|
||||
public resetMode(params: IParams, collect?: string): void {
|
||||
for (let i = 0; i < params.length; i++) {
|
||||
this._resetMode(params.params[i], collect);
|
||||
}
|
||||
}
|
||||
|
||||
private _resetMode(param: number, collect?: string): void {
|
||||
if (!collect) {
|
||||
switch (params[0]) {
|
||||
switch (param) {
|
||||
case 4:
|
||||
this._terminal.insertMode = false;
|
||||
break;
|
||||
@@ -1496,7 +1438,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
break;
|
||||
}
|
||||
} else if (collect === '?') {
|
||||
switch (params[0]) {
|
||||
switch (param) {
|
||||
case 1:
|
||||
this._coreService.decPrivateModes.applicationCursorKeys = false;
|
||||
break;
|
||||
@@ -1553,7 +1495,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
this._terminal.cursorHidden = true;
|
||||
break;
|
||||
case 1048: // alt screen cursor
|
||||
this.restoreCursor(params);
|
||||
this.restoreCursor();
|
||||
break;
|
||||
case 1049: // alt screen buffer cursor
|
||||
// FALL-THROUGH
|
||||
@@ -1561,8 +1503,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
case 1047: // normal screen buffer - clearing it first
|
||||
// Ensure the selection manager has the correct buffer
|
||||
this._terminal.buffers.activateNormalBuffer();
|
||||
if (params[0] === 1049) {
|
||||
this.restoreCursor(params);
|
||||
if (param === 1049) {
|
||||
this.restoreCursor();
|
||||
}
|
||||
this._terminal.refresh(0, this._terminal.rows - 1);
|
||||
if (this._terminal.viewport) {
|
||||
@@ -1577,6 +1519,78 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to extract and apply color params/subparams.
|
||||
* Returns advance for params index.
|
||||
*/
|
||||
private _extractColor(params: IParams, pos: number, attr: IAttributeData): number {
|
||||
// normalize params
|
||||
// meaning: [target, CM, ign, val, val, val]
|
||||
// RGB : [ 38/48, 2, ign, r, g, b]
|
||||
// P256 : [ 38/48, 5, ign, v, ign, ign]
|
||||
const accu = [0, 0, -1, 0, 0, 0];
|
||||
|
||||
// alignment placeholder for non color space sequences
|
||||
let cSpace = 0;
|
||||
|
||||
// return advance we took in params
|
||||
let advance = 0;
|
||||
|
||||
do {
|
||||
accu[advance + cSpace] = params.params[pos + advance];
|
||||
if (params.hasSubParams(pos + advance)) {
|
||||
const subparams = params.getSubParams(pos + advance);
|
||||
let i = 0;
|
||||
do {
|
||||
if (accu[1] === 5) {
|
||||
cSpace = 1;
|
||||
}
|
||||
accu[advance + i + 1 + cSpace] = subparams[i];
|
||||
} while (++i < subparams.length && i + advance + 1 + cSpace < accu.length);
|
||||
break;
|
||||
}
|
||||
// exit early if can decide color mode with semicolons
|
||||
if ((accu[1] === 5 && advance + cSpace >= 2)
|
||||
|| (accu[1] === 2 && advance + cSpace >= 5)) {
|
||||
break;
|
||||
}
|
||||
// offset colorSpace slot for semicolon mode
|
||||
if (accu[1]) {
|
||||
cSpace = 1;
|
||||
}
|
||||
} while (++advance + pos < params.length && advance + cSpace < accu.length);
|
||||
|
||||
// set default values to 0
|
||||
for (let i = 2; i < accu.length; ++i) {
|
||||
if (accu[i] === -1) {
|
||||
accu[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// apply colors
|
||||
if (accu[0] === 38) {
|
||||
if (accu[1] === 2) {
|
||||
attr.fg |= Attributes.CM_RGB;
|
||||
attr.fg &= ~Attributes.RGB_MASK;
|
||||
attr.fg |= AttributeData.fromColorRGB([accu[3], accu[4], accu[5]]);
|
||||
} else if (accu[1] === 5) {
|
||||
attr.fg &= ~(Attributes.CM_MASK | Attributes.PCOLOR_MASK);
|
||||
attr.fg |= Attributes.CM_P256 | (accu[3] & 0xff);
|
||||
}
|
||||
} else if (accu[0] === 48) {
|
||||
if (accu[1] === 2) {
|
||||
attr.bg |= Attributes.CM_RGB;
|
||||
attr.bg &= ~Attributes.RGB_MASK;
|
||||
attr.bg |= AttributeData.fromColorRGB([accu[3], accu[4], accu[5]]);
|
||||
} else if (accu[1] === 5) {
|
||||
attr.bg &= ~(Attributes.CM_MASK | Attributes.PCOLOR_MASK);
|
||||
attr.bg |= Attributes.CM_P256 | (accu[3] & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
return advance;
|
||||
}
|
||||
|
||||
/**
|
||||
* CSI Pm m Character Attributes (SGR).
|
||||
* Ps = 0 -> Normal (default).
|
||||
@@ -1642,9 +1656,9 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Ps = 4 8 ; 5 ; Ps -> Set background color to the second
|
||||
* Ps.
|
||||
*/
|
||||
public charAttributes(params: number[]): void {
|
||||
public charAttributes(params: IParams): void {
|
||||
// Optimize a single SGR0.
|
||||
if (params.length === 1 && params[0] === 0) {
|
||||
if (params.length === 1 && params.params[0] === 0) {
|
||||
this._terminal.curAttrData.fg = DEFAULT_ATTR_DATA.fg;
|
||||
this._terminal.curAttrData.bg = DEFAULT_ATTR_DATA.bg;
|
||||
return;
|
||||
@@ -1655,7 +1669,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
const attr = this._terminal.curAttrData;
|
||||
|
||||
for (let i = 0; i < l; i++) {
|
||||
p = params[i];
|
||||
p = params.params[i];
|
||||
if (p >= 30 && p <= 37) {
|
||||
// fg color 8
|
||||
attr.fg &= ~(Attributes.CM_MASK | Attributes.PCOLOR_MASK);
|
||||
@@ -1725,34 +1739,9 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
// reset bg
|
||||
attr.bg &= ~(Attributes.CM_MASK | Attributes.RGB_MASK);
|
||||
attr.bg |= DEFAULT_ATTR_DATA.bg & (Attributes.PCOLOR_MASK | Attributes.RGB_MASK);
|
||||
} else if (p === 38) {
|
||||
} else if (p === 38 || p === 48) {
|
||||
// fg color 256 and RGB
|
||||
if (params[i + 1] === 2) {
|
||||
i += 2;
|
||||
attr.fg |= Attributes.CM_RGB;
|
||||
attr.fg &= ~Attributes.RGB_MASK;
|
||||
attr.fg |= AttributeData.fromColorRGB([params[i], params[i + 1], params[i + 2]]);
|
||||
i += 2;
|
||||
} else if (params[i + 1] === 5) {
|
||||
i += 2;
|
||||
p = params[i] & 0xff;
|
||||
attr.fg &= ~(Attributes.CM_MASK | Attributes.PCOLOR_MASK);
|
||||
attr.fg |= Attributes.CM_P256 | p;
|
||||
}
|
||||
} else if (p === 48) {
|
||||
// bg color 256 and RGB
|
||||
if (params[i + 1] === 2) {
|
||||
i += 2;
|
||||
attr.bg |= Attributes.CM_RGB;
|
||||
attr.bg &= ~Attributes.RGB_MASK;
|
||||
attr.bg |= AttributeData.fromColorRGB([params[i], params[i + 1], params[i + 2]]);
|
||||
i += 2;
|
||||
} else if (params[i + 1] === 5) {
|
||||
i += 2;
|
||||
p = params[i] & 0xff;
|
||||
attr.bg &= ~(Attributes.CM_MASK | Attributes.PCOLOR_MASK);
|
||||
attr.bg |= Attributes.CM_P256 | p;
|
||||
}
|
||||
i += this._extractColor(params, i, attr);
|
||||
} else if (p === 100) {
|
||||
// reset fg/bg
|
||||
attr.fg &= ~(Attributes.CM_MASK | Attributes.RGB_MASK);
|
||||
@@ -1788,9 +1777,9 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* CSI ? 5 3 n Locator available, if compiled-in, or
|
||||
* CSI ? 5 0 n No Locator, if not.
|
||||
*/
|
||||
public deviceStatus(params: number[], collect?: string): void {
|
||||
public deviceStatus(params: IParams, collect?: string): void {
|
||||
if (!collect) {
|
||||
switch (params[0]) {
|
||||
switch (params.params[0]) {
|
||||
case 5:
|
||||
// status report
|
||||
this._coreService.triggerDataEvent(`${C0.ESC}[0n`);
|
||||
@@ -1805,7 +1794,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
} else if (collect === '?') {
|
||||
// modern xterm doesnt seem to
|
||||
// respond to any of these except ?6, 6, and 5
|
||||
switch (params[0]) {
|
||||
switch (params.params[0]) {
|
||||
case 6:
|
||||
// cursor position
|
||||
const y = this._terminal.buffer.y + 1;
|
||||
@@ -1836,7 +1825,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* CSI ! p Soft terminal reset (DECSTR).
|
||||
* http://vt100.net/docs/vt220-rm/table4-10.html
|
||||
*/
|
||||
public softReset(params: number[], collect?: string): void {
|
||||
public softReset(params: IParams, collect?: string): void {
|
||||
if (collect === '!') {
|
||||
this._terminal.cursorHidden = false;
|
||||
this._terminal.insertMode = false;
|
||||
@@ -1867,9 +1856,9 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Ps = 5 -> blinking bar (xterm).
|
||||
* Ps = 6 -> steady bar (xterm).
|
||||
*/
|
||||
public setCursorStyle(params?: number[], collect?: string): void {
|
||||
public setCursorStyle(params?: IParams, collect?: string): void {
|
||||
if (collect === ' ') {
|
||||
const param = params[0] < 1 ? 1 : params[0];
|
||||
const param = params.params[0] || 1;
|
||||
switch (param) {
|
||||
case 1:
|
||||
case 2:
|
||||
@@ -1894,13 +1883,14 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Set Scrolling Region [top;bottom] (default = full size of win-
|
||||
* dow) (DECSTBM).
|
||||
* CSI ? Pm r
|
||||
* currently skipped
|
||||
*/
|
||||
public setScrollRegion(params: number[], collect?: string): void {
|
||||
public setScrollRegion(params: IParams, collect?: string): void {
|
||||
if (collect) {
|
||||
return;
|
||||
}
|
||||
this._terminal.buffer.scrollTop = (params[0] || 1) - 1;
|
||||
this._terminal.buffer.scrollBottom = (params[1] && params[1] <= this._terminal.rows ? params[1] : this._terminal.rows) - 1;
|
||||
this._terminal.buffer.scrollTop = (params.params[0] || 1) - 1;
|
||||
this._terminal.buffer.scrollBottom = (params.length > 1 && params.params[1] && params.params[1] <= this._terminal.rows ? params.params[1] : this._terminal.rows) - 1;
|
||||
this._terminal.buffer.x = 0;
|
||||
this._terminal.buffer.y = 0;
|
||||
}
|
||||
@@ -1911,7 +1901,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* ESC 7
|
||||
* Save cursor (ANSI.SYS).
|
||||
*/
|
||||
public saveCursor(params: number[]): void {
|
||||
public saveCursor(params?: IParams): void {
|
||||
this._terminal.buffer.savedX = this._terminal.buffer.x;
|
||||
this._terminal.buffer.savedY = this._terminal.buffer.ybase + this._terminal.buffer.y;
|
||||
this._terminal.buffer.savedCurAttrData.fg = this._terminal.curAttrData.fg;
|
||||
@@ -1924,7 +1914,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* ESC 8
|
||||
* Restore cursor (ANSI.SYS).
|
||||
*/
|
||||
public restoreCursor(params: number[]): void {
|
||||
public restoreCursor(params?: IParams): void {
|
||||
this._terminal.buffer.x = this._terminal.buffer.savedX || 0;
|
||||
this._terminal.buffer.y = Math.max(this._terminal.buffer.savedY - this._terminal.buffer.ybase, 0);
|
||||
this._terminal.curAttrData.fg = this._terminal.buffer.savedCurAttrData.fg;
|
||||
@@ -2088,7 +2078,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
|
||||
const buffer = this._terminal.buffer;
|
||||
|
||||
this.cursorPosition([1, 1]);
|
||||
this._setCursor(0, 0);
|
||||
for (let yOffset = 0; yOffset < this._terminal.rows; ++yOffset) {
|
||||
const row = buffer.y + buffer.ybase + yOffset;
|
||||
buffer.lines.get(row).fill(cell);
|
||||
@@ -2096,6 +2086,6 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
}
|
||||
this._terminal.updateRange(0);
|
||||
this._terminal.updateRange(this._terminal.rows);
|
||||
this.cursorPosition([1, 1]);
|
||||
this._setCursor(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user