Merge remote-tracking branch 'upstream/master' into protected

This commit is contained in:
Jörg Breitbart
2022-09-07 19:51:51 +02:00
7 changed files with 231 additions and 40 deletions
+102 -10
View File
@@ -4,13 +4,12 @@
* @license MIT
*/
import { IInputHandler, IAttributeData, IDisposable, IWindowOptions, IColorEvent, IParseStack, ColorIndex, ColorRequestType, IOscLinkData } from 'common/Types';
import { IInputHandler, IAttributeData, IDisposable, IWindowOptions, IColorEvent, IParseStack, ColorIndex, ColorRequestType } from 'common/Types';
import { C0, C1 } from 'common/data/EscapeSequences';
import { CHARSETS, DEFAULT_CHARSET } from 'common/data/Charsets';
import { EscapeSequenceParser } from 'common/parser/EscapeSequenceParser';
import { Disposable } from 'common/Lifecycle';
import { concat } from 'common/TypedArrayUtils';
import { StringToUtf32, stringFromCodePoint, utf32ToString, Utf8ToUtf32 } from 'common/input/TextDecoder';
import { StringToUtf32, stringFromCodePoint, Utf8ToUtf32 } from 'common/input/TextDecoder';
import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
import { EventEmitter, IEvent } from 'common/EventEmitter';
import { IParsingState, IDcsHandler, IEscapeSequenceParser, IParams, IFunctionIdentifier } from 'common/parser/Types';
@@ -263,6 +262,8 @@ export class InputHandler extends Disposable implements IInputHandler {
this._parser.registerCsiHandler({ intermediates: '\'', final: '}' }, params => this.insertColumns(params));
this._parser.registerCsiHandler({ intermediates: '\'', final: '~' }, params => this.deleteColumns(params));
this._parser.registerCsiHandler({ intermediates: '"', final: 'q' }, params => this.selectProtected(params));
this._parser.registerCsiHandler({ intermediates: '$', final: 'p' }, params => this.requestMode(params, true));
this._parser.registerCsiHandler({ prefix: '?', intermediates: '$', final: 'p' }, params => this.requestMode(params, false));
/**
* execute handler
@@ -1694,7 +1695,7 @@ export class InputHandler extends Disposable implements IInputHandler {
* | 2 | Keyboard Action Mode (KAM). Always on. | #N |
* | 4 | Insert Mode (IRM). | #Y |
* | 12 | Send/receive (SRM). Always off. | #N |
* | 20 | Automatic Newline (LNM). Always off. | #N |
* | 20 | Automatic Newline (LNM). | #Y |
*/
public setMode(params: IParams): boolean {
for (let i = 0; i < params.length; i++) {
@@ -1703,7 +1704,7 @@ export class InputHandler extends Disposable implements IInputHandler {
this._coreService.modes.insertMode = true;
break;
case 20:
// this._t.convertEol = true;
this._optionsService.options.convertEol = true;
break;
}
}
@@ -1856,7 +1857,7 @@ export class InputHandler extends Disposable implements IInputHandler {
this._coreService.decPrivateModes.wraparound = true;
break;
case 12:
// this.cursorBlink = true;
this._optionsService.options.cursorBlink = true;
break;
case 45:
this._coreService.decPrivateModes.reverseWraparound = true;
@@ -1940,7 +1941,7 @@ export class InputHandler extends Disposable implements IInputHandler {
* | 2 | Keyboard Action Mode (KAM). Always on. | #N |
* | 4 | Replace Mode (IRM). (default) | #Y |
* | 12 | Send/receive (SRM). Always off. | #N |
* | 20 | Normal Linefeed (LNM). Always off. | #N |
* | 20 | Normal Linefeed (LNM). | #Y |
*
*
* FIXME: why is LNM commented out?
@@ -1952,7 +1953,7 @@ export class InputHandler extends Disposable implements IInputHandler {
this._coreService.modes.insertMode = false;
break;
case 20:
// this._t.convertEol = false;
this._optionsService.options.convertEol = false;
break;
}
}
@@ -2094,7 +2095,7 @@ export class InputHandler extends Disposable implements IInputHandler {
this._coreService.decPrivateModes.wraparound = false;
break;
case 12:
// this.cursorBlink = false;
this._optionsService.options.cursorBlink = false;
break;
case 45:
this._coreService.decPrivateModes.reverseWraparound = false;
@@ -2122,7 +2123,7 @@ export class InputHandler extends Disposable implements IInputHandler {
case 1015: // urxvt ext mode mouse - removed in #2507
this._logService.debug('DECRST 1015 not supported (see #2507)');
break;
case 1006: // sgr pixels mode mouse
case 1016: // sgr pixels mode mouse
this._coreMouseService.activeEncoding = 'DEFAULT';
break;
case 25: // hide cursor
@@ -2152,6 +2153,97 @@ export class InputHandler extends Disposable implements IInputHandler {
return true;
}
/**
* CSI Ps $ p Request ANSI Mode (DECRQM).
*
* Reports CSI Ps; Pm $ y (DECRPM), where Ps is the mode number as in SM/RM,
* and Pm is the mode value:
* 0 - not recognized
* 1 - set
* 2 - reset
* 3 - permanently set
* 4 - permanently reset
*
* @vt: #Y CSI DECRQM "Request Mode" "CSI Ps $p" "Request mode state."
* Returns a report as `CSI Ps; Pm $ y` (DECRPM), where `Ps` is the mode number as in SM/RM
* or DECSET/DECRST, and `Pm` is the mode value:
* - 0: not recognized
* - 1: set
* - 2: reset
* - 3: permanently set
* - 4: permanently reset
*
* For modes not understood xterm.js always returns `notRecognized`. In general this means,
* that a certain operation mode is not implemented and cannot be used.
*
* Modes changing the active terminal buffer (47, 1047, 1049) are not subqueried
* and only report, whether the alternate buffer is set.
*
* Mouse encodings and mouse protocols are handled mutual exclusive,
* thus only one of each of those can be set at a given time.
*
* There is a chance, that some mode reports are not fully in line with xterm.js' behavior,
* e.g. if the default implementation already exposes a certain behavior. If you find
* discrepancies in the mode reports, please file a bug.
*/
public requestMode(params: IParams, ansi: boolean): boolean {
// return value as in DECRPM
const enum V {
NOT_RECOGNIZED = 0,
SET = 1,
RESET = 2,
PERMANENTLY_SET = 3,
PERMANENTLY_RESET = 4
}
// access helpers
const dm = this._coreService.decPrivateModes;
const { activeProtocol: mouseProtocol, activeEncoding: mouseEncoding } = this._coreMouseService;
const cs = this._coreService;
const { buffers, cols } = this._bufferService;
const { active, alt } = buffers;
const opts = this._optionsService.rawOptions;
const f = (m: number, v: V): boolean => {
cs.triggerDataEvent(`${C0.ESC}[${ansi ? '' : '?'}${m};${v}$y`);
return true;
};
const b2v = (value: boolean): V => value ? V.SET : V.RESET;
const p = params.params[0];
if (ansi) {
if (p === 2) return f(p, V.PERMANENTLY_SET);
if (p === 4) return f(p, b2v(cs.modes.insertMode));
if (p === 12) return f(p, V.PERMANENTLY_RESET);
if (p === 20) return f(p, b2v(opts.convertEol));
return f(p, V.NOT_RECOGNIZED);
}
if (p === 1) return f(p, b2v(dm.applicationCursorKeys));
if (p === 3) return f(p, opts.windowOptions.setWinLines ? (cols === 80 ? V.RESET : cols === 132 ? V.SET : V.NOT_RECOGNIZED) : V.NOT_RECOGNIZED);
if (p === 6) return f(p, b2v(dm.origin));
if (p === 7) return f(p, b2v(dm.wraparound));
if (p === 8) return f(p, V.PERMANENTLY_SET);
if (p === 9) return f(p, b2v(mouseProtocol === 'X10'));
if (p === 12) return f(p, b2v(opts.cursorBlink));
if (p === 25) return f(p, b2v(!cs.isCursorHidden));
if (p === 45) return f(p, b2v(dm.reverseWraparound));
if (p === 66) return f(p, b2v(dm.applicationKeypad));
if (p === 1000) return f(p, b2v(mouseProtocol === 'VT200'));
if (p === 1002) return f(p, b2v(mouseProtocol === 'DRAG'));
if (p === 1003) return f(p, b2v(mouseProtocol === 'ANY'));
if (p === 1004) return f(p, b2v(dm.sendFocus));
if (p === 1005) return f(p, V.PERMANENTLY_RESET);
if (p === 1006) return f(p, b2v(mouseEncoding === 'SGR'));
if (p === 1015) return f(p, V.PERMANENTLY_RESET);
if (p === 1016) return f(p, b2v(mouseEncoding === 'SGR_PIXELS'));
if (p === 1048) return f(p, V.SET); // xterm always returns SET here
if (p === 47 || p === 1047 || p === 1049) return f(p, b2v(active === alt));
if (p === 2004) return f(p, b2v(dm.bracketedPasteMode));
return f(p, V.NOT_RECOGNIZED);
}
/**
* Helper to write color information packed with color mode.
*/