Revert "Merge pull request #4166 from Tyriar/event_with_emitter"

This reverts commit d22f7c9edd, reversing
changes made to 1f8e6f0952.
This commit is contained in:
Daniel Imms
2022-10-06 09:48:54 -07:00
parent 5f1651ffbc
commit 4d97729010
34 changed files with 329 additions and 283 deletions
+58 -45
View File
@@ -11,7 +11,7 @@ import { EscapeSequenceParser } from 'common/parser/EscapeSequenceParser';
import { Disposable } from 'common/Lifecycle';
import { StringToUtf32, stringFromCodePoint, Utf8ToUtf32 } from 'common/input/TextDecoder';
import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
import { EventEmitter, IEvent, initEvent } from 'common/EventEmitter';
import { EventEmitter, IEvent } from 'common/EventEmitter';
import { IParsingState, IEscapeSequenceParser, IParams, IFunctionIdentifier } from 'common/parser/Types';
import { NULL_CELL_CODE, NULL_CELL_WIDTH, Attributes, FgFlags, BgFlags, Content, UnderlineStyle } from 'common/buffer/Constants';
import { CellData } from 'common/buffer/CellData';
@@ -132,20 +132,33 @@ export class InputHandler extends Disposable implements IInputHandler {
private _activeBuffer: IBuffer;
public readonly onRequestBell = initEvent<void>();
public readonly onRequestRefreshRows = initEvent<number, number>();
public readonly onRequestReset = initEvent<void>();
public readonly onRequestSendFocus = initEvent<void>();
public readonly onRequestSyncScrollBar = initEvent<void>();
public readonly onRequestWindowsOptionsReport = initEvent<WindowsOptionsReportType>();
private readonly _onRequestBell = new EventEmitter<void>();
public readonly onRequestBell = this._onRequestBell.event;
private readonly _onRequestRefreshRows = new EventEmitter<number, number>();
public readonly onRequestRefreshRows = this._onRequestRefreshRows.event;
private readonly _onRequestReset = new EventEmitter<void>();
public readonly onRequestReset = this._onRequestReset.event;
private readonly _onRequestSendFocus = new EventEmitter<void>();
public readonly onRequestSendFocus = this._onRequestSendFocus.event;
private readonly _onRequestSyncScrollBar = new EventEmitter<void>();
public readonly onRequestSyncScrollBar = this._onRequestSyncScrollBar.event;
private readonly _onRequestWindowsOptionsReport = new EventEmitter<WindowsOptionsReportType>();
public readonly onRequestWindowsOptionsReport = this._onRequestWindowsOptionsReport.event;
public readonly onA11yChar = initEvent<string>();
public readonly onA11yTab = initEvent<number>();
public readonly onCursorMove = initEvent<void>();
public readonly onLineFeed = initEvent<void>();
public readonly onScroll = initEvent<number>();
public readonly onTitleChange = initEvent<string>();
public readonly onColor = initEvent<IColorEvent>();
private readonly _onA11yChar = new EventEmitter<string>();
public readonly onA11yChar = this._onA11yChar.event;
private readonly _onA11yTab = new EventEmitter<number>();
public readonly onA11yTab = this._onA11yTab.event;
private readonly _onCursorMove = new EventEmitter<void>();
public readonly onCursorMove = this._onCursorMove.event;
private readonly _onLineFeed = new EventEmitter<void>();
public readonly onLineFeed = this._onLineFeed.event;
private readonly _onScroll = new EventEmitter<number>();
public readonly onScroll = this._onScroll.event;
private readonly _onTitleChange = new EventEmitter<string>();
public readonly onTitleChange = this._onTitleChange.event;
private readonly _onColor = new EventEmitter<IColorEvent>();
public readonly onColor = this._onColor.event;
private _parseStack: IParseStack = {
paused: false,
@@ -479,11 +492,11 @@ export class InputHandler extends Disposable implements IInputHandler {
}
if (this._activeBuffer.x !== cursorStartX || this._activeBuffer.y !== cursorStartY) {
this.onCursorMove.fire();
this._onCursorMove.fire();
}
// Refresh any dirty rows accumulated as part of parsing
this.onRequestRefreshRows.fire(this._dirtyRowTracker.start, this._dirtyRowTracker.end);
this._onRequestRefreshRows.fire(this._dirtyRowTracker.start, this._dirtyRowTracker.end);
}
public print(data: Uint32Array, start: number, end: number): void {
@@ -522,7 +535,7 @@ export class InputHandler extends Disposable implements IInputHandler {
}
if (screenReaderMode) {
this.onA11yChar.fire(stringFromCodePoint(code));
this._onA11yChar.fire(stringFromCodePoint(code));
}
if (this._currentLinkId !== undefined) {
this._oscLinkService.addLineToLink(this._currentLinkId, this._activeBuffer.ybase + this._activeBuffer.y);
@@ -674,7 +687,7 @@ export class InputHandler extends Disposable implements IInputHandler {
* and `ITerminalOptions.bellSound`.
*/
public bell(): boolean {
this.onRequestBell.fire();
this._onRequestBell.fire();
return true;
}
@@ -706,7 +719,7 @@ export class InputHandler extends Disposable implements IInputHandler {
}
this._dirtyRowTracker.markDirty(this._activeBuffer.y);
this.onLineFeed.fire();
this._onLineFeed.fire();
return true;
}
@@ -795,7 +808,7 @@ export class InputHandler extends Disposable implements IInputHandler {
const originalX = this._activeBuffer.x;
this._activeBuffer.x = this._activeBuffer.nextStop();
if (this._optionsService.rawOptions.screenReaderMode) {
this.onA11yTab.fire(this._activeBuffer.x - originalX);
this._onA11yTab.fire(this._activeBuffer.x - originalX);
}
return true;
}
@@ -1205,7 +1218,7 @@ export class InputHandler extends Disposable implements IInputHandler {
this._activeBuffer.ybase = Math.max(this._activeBuffer.ybase - scrollBackSize, 0);
this._activeBuffer.ydisp = Math.max(this._activeBuffer.ydisp - scrollBackSize, 0);
// Force a scroll event to refresh viewport
this.onScroll.fire(0);
this._onScroll.fire(0);
}
break;
}
@@ -1836,7 +1849,7 @@ export class InputHandler extends Disposable implements IInputHandler {
*/
if (this._optionsService.rawOptions.windowOptions.setWinLines) {
this._bufferService.resize(132, this._bufferService.rows);
this.onRequestReset.fire();
this._onRequestReset.fire();
}
break;
case 6:
@@ -1855,7 +1868,7 @@ export class InputHandler extends Disposable implements IInputHandler {
case 66:
this._logService.debug('Serial port requested application keypad.');
this._coreService.decPrivateModes.applicationKeypad = true;
this.onRequestSyncScrollBar.fire();
this._onRequestSyncScrollBar.fire();
break;
case 9: // X10 Mouse
// no release, no motion, no wheel, no modifiers.
@@ -1877,7 +1890,7 @@ export class InputHandler extends Disposable implements IInputHandler {
// focusin: ^[[I
// focusout: ^[[O
this._coreService.decPrivateModes.sendFocus = true;
this.onRequestSendFocus.fire();
this._onRequestSendFocus.fire();
break;
case 1005: // utf8 ext mode mouse - removed in #2507
this._logService.debug('DECSET 1005 not supported (see #2507)');
@@ -1904,8 +1917,8 @@ export class InputHandler extends Disposable implements IInputHandler {
case 1047: // alt screen buffer
this._bufferService.buffers.activateAltBuffer(this._eraseAttrData());
this._coreService.isCursorInitialized = true;
this.onRequestRefreshRows.fire(0, this._bufferService.rows - 1);
this.onRequestSyncScrollBar.fire();
this._onRequestRefreshRows.fire(0, this._bufferService.rows - 1);
this._onRequestSyncScrollBar.fire();
break;
case 2004: // bracketed paste mode (https://cirw.in/blog/bracketed-paste)
this._coreService.decPrivateModes.bracketedPasteMode = true;
@@ -2074,7 +2087,7 @@ export class InputHandler extends Disposable implements IInputHandler {
*/
if (this._optionsService.rawOptions.windowOptions.setWinLines) {
this._bufferService.resize(80, this._bufferService.rows);
this.onRequestReset.fire();
this._onRequestReset.fire();
}
break;
case 6:
@@ -2093,7 +2106,7 @@ export class InputHandler extends Disposable implements IInputHandler {
case 66:
this._logService.debug('Switching back to normal keypad.');
this._coreService.decPrivateModes.applicationKeypad = false;
this.onRequestSyncScrollBar.fire();
this._onRequestSyncScrollBar.fire();
break;
case 9: // X10 Mouse
case 1000: // vt200 mouse
@@ -2132,8 +2145,8 @@ export class InputHandler extends Disposable implements IInputHandler {
this.restoreCursor();
}
this._coreService.isCursorInitialized = true;
this.onRequestRefreshRows.fire(0, this._bufferService.rows - 1);
this.onRequestSyncScrollBar.fire();
this._onRequestRefreshRows.fire(0, this._bufferService.rows - 1);
this._onRequestSyncScrollBar.fire();
break;
case 2004: // bracketed paste mode (https://cirw.in/blog/bracketed-paste)
this._coreService.decPrivateModes.bracketedPasteMode = false;
@@ -2632,7 +2645,7 @@ export class InputHandler extends Disposable implements IInputHandler {
*/
public softReset(params: IParams): boolean {
this._coreService.isCursorHidden = false;
this.onRequestSyncScrollBar.fire();
this._onRequestSyncScrollBar.fire();
this._activeBuffer.scrollTop = 0;
this._activeBuffer.scrollBottom = this._bufferService.rows - 1;
this._curAttrData = DEFAULT_ATTR_DATA.clone();
@@ -2752,11 +2765,11 @@ export class InputHandler extends Disposable implements IInputHandler {
switch (params.params[0]) {
case 14: // GetWinSizePixels, returns CSI 4 ; height ; width t
if (second !== 2) {
this.onRequestWindowsOptionsReport.fire(WindowsOptionsReportType.GET_WIN_SIZE_PIXELS);
this._onRequestWindowsOptionsReport.fire(WindowsOptionsReportType.GET_WIN_SIZE_PIXELS);
}
break;
case 16: // GetCellSizePixels, returns CSI 6 ; height ; width t
this.onRequestWindowsOptionsReport.fire(WindowsOptionsReportType.GET_CELL_SIZE_PIXELS);
this._onRequestWindowsOptionsReport.fire(WindowsOptionsReportType.GET_CELL_SIZE_PIXELS);
break;
case 18: // GetWinSizeChars, returns CSI 8 ; height ; width t
if (this._bufferService) {
@@ -2846,7 +2859,7 @@ export class InputHandler extends Disposable implements IInputHandler {
*/
public setTitle(data: string): boolean {
this._windowTitle = data;
this.onTitleChange.fire(data);
this._onTitleChange.fire(data);
return true;
}
@@ -2888,7 +2901,7 @@ export class InputHandler extends Disposable implements IInputHandler {
}
}
if (event.length) {
this.onColor.fire(event);
this._onColor.fire(event);
}
return true;
}
@@ -2962,11 +2975,11 @@ export class InputHandler extends Disposable implements IInputHandler {
for (let i = 0; i < slots.length; ++i, ++offset) {
if (offset >= this._specialColors.length) break;
if (slots[i] === '?') {
this.onColor.fire([{ type: ColorRequestType.REPORT, index: this._specialColors[offset] }]);
this._onColor.fire([{ type: ColorRequestType.REPORT, index: this._specialColors[offset] }]);
} else {
const color = parseColor(slots[i]);
if (color) {
this.onColor.fire([{ type: ColorRequestType.SET, index: this._specialColors[offset], color }]);
this._onColor.fire([{ type: ColorRequestType.SET, index: this._specialColors[offset], color }]);
}
}
}
@@ -3027,7 +3040,7 @@ export class InputHandler extends Disposable implements IInputHandler {
*/
public restoreIndexedColor(data: string): boolean {
if (!data) {
this.onColor.fire([{ type: ColorRequestType.RESTORE }]);
this._onColor.fire([{ type: ColorRequestType.RESTORE }]);
return true;
}
const event: IColorEvent = [];
@@ -3041,7 +3054,7 @@ export class InputHandler extends Disposable implements IInputHandler {
}
}
if (event.length) {
this.onColor.fire(event);
this._onColor.fire(event);
}
return true;
}
@@ -3052,7 +3065,7 @@ export class InputHandler extends Disposable implements IInputHandler {
* @vt: #Y OSC 110 "Restore default foreground color" "OSC 110 BEL" "Restore default foreground to themed color."
*/
public restoreFgColor(data: string): boolean {
this.onColor.fire([{ type: ColorRequestType.RESTORE, index: ColorIndex.FOREGROUND }]);
this._onColor.fire([{ type: ColorRequestType.RESTORE, index: ColorIndex.FOREGROUND }]);
return true;
}
@@ -3062,7 +3075,7 @@ export class InputHandler extends Disposable implements IInputHandler {
* @vt: #Y OSC 111 "Restore default background color" "OSC 111 BEL" "Restore default background to themed color."
*/
public restoreBgColor(data: string): boolean {
this.onColor.fire([{ type: ColorRequestType.RESTORE, index: ColorIndex.BACKGROUND }]);
this._onColor.fire([{ type: ColorRequestType.RESTORE, index: ColorIndex.BACKGROUND }]);
return true;
}
@@ -3072,7 +3085,7 @@ export class InputHandler extends Disposable implements IInputHandler {
* @vt: #Y OSC 112 "Restore default cursor color" "OSC 112 BEL" "Restore default cursor to themed color."
*/
public restoreCursorColor(data: string): boolean {
this.onColor.fire([{ type: ColorRequestType.RESTORE, index: ColorIndex.CURSOR }]);
this._onColor.fire([{ type: ColorRequestType.RESTORE, index: ColorIndex.CURSOR }]);
return true;
}
@@ -3099,7 +3112,7 @@ export class InputHandler extends Disposable implements IInputHandler {
public keypadApplicationMode(): boolean {
this._logService.debug('Serial port requested application keypad.');
this._coreService.decPrivateModes.applicationKeypad = true;
this.onRequestSyncScrollBar.fire();
this._onRequestSyncScrollBar.fire();
return true;
}
@@ -3111,7 +3124,7 @@ export class InputHandler extends Disposable implements IInputHandler {
public keypadNumericMode(): boolean {
this._logService.debug('Switching back to normal keypad.');
this._coreService.decPrivateModes.applicationKeypad = false;
this.onRequestSyncScrollBar.fire();
this._onRequestSyncScrollBar.fire();
return true;
}
@@ -3225,7 +3238,7 @@ export class InputHandler extends Disposable implements IInputHandler {
*/
public fullReset(): boolean {
this._parser.reset();
this.onRequestReset.fire();
this._onRequestReset.fire();
return true;
}