@wendongfly/myhi 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/lib/xterm/LICENSE +21 -0
  3. package/dist/lib/xterm/README.md +225 -0
  4. package/dist/lib/xterm/css/xterm.css +190 -0
  5. package/dist/lib/xterm/lib/xterm.js +2 -0
  6. package/dist/lib/xterm/lib/xterm.js.map +1 -0
  7. package/dist/lib/xterm/package.json +90 -0
  8. package/dist/lib/xterm/src/browser/AccessibilityManager.ts +301 -0
  9. package/dist/lib/xterm/src/browser/Clipboard.ts +99 -0
  10. package/dist/lib/xterm/src/browser/ColorContrastCache.ts +39 -0
  11. package/dist/lib/xterm/src/browser/ColorManager.ts +268 -0
  12. package/dist/lib/xterm/src/browser/Dom.ts +10 -0
  13. package/dist/lib/xterm/src/browser/Lifecycle.ts +30 -0
  14. package/dist/lib/xterm/src/browser/Linkifier.ts +356 -0
  15. package/dist/lib/xterm/src/browser/Linkifier2.ts +397 -0
  16. package/dist/lib/xterm/src/browser/LocalizableStrings.ts +10 -0
  17. package/dist/lib/xterm/src/browser/MouseZoneManager.ts +236 -0
  18. package/dist/lib/xterm/src/browser/RenderDebouncer.ts +82 -0
  19. package/dist/lib/xterm/src/browser/ScreenDprMonitor.ts +69 -0
  20. package/dist/lib/xterm/src/browser/Terminal.ts +1447 -0
  21. package/dist/lib/xterm/src/browser/TimeBasedDebouncer.ts +86 -0
  22. package/dist/lib/xterm/src/browser/Types.d.ts +317 -0
  23. package/dist/lib/xterm/src/browser/Viewport.ts +276 -0
  24. package/dist/lib/xterm/src/browser/decorations/BufferDecorationRenderer.ts +131 -0
  25. package/dist/lib/xterm/src/browser/decorations/ColorZoneStore.ts +117 -0
  26. package/dist/lib/xterm/src/browser/decorations/OverviewRulerRenderer.ts +228 -0
  27. package/dist/lib/xterm/src/browser/input/CompositionHelper.ts +237 -0
  28. package/dist/lib/xterm/src/browser/input/Mouse.ts +64 -0
  29. package/dist/lib/xterm/src/browser/input/MoveToCell.ts +249 -0
  30. package/dist/lib/xterm/src/browser/public/Terminal.ts +298 -0
  31. package/dist/lib/xterm/src/browser/renderer/BaseRenderLayer.ts +582 -0
  32. package/dist/lib/xterm/src/browser/renderer/CursorRenderLayer.ts +378 -0
  33. package/dist/lib/xterm/src/browser/renderer/CustomGlyphs.ts +632 -0
  34. package/dist/lib/xterm/src/browser/renderer/GridCache.ts +33 -0
  35. package/dist/lib/xterm/src/browser/renderer/LinkRenderLayer.ts +84 -0
  36. package/dist/lib/xterm/src/browser/renderer/Renderer.ts +219 -0
  37. package/dist/lib/xterm/src/browser/renderer/RendererUtils.ts +26 -0
  38. package/dist/lib/xterm/src/browser/renderer/SelectionRenderLayer.ts +131 -0
  39. package/dist/lib/xterm/src/browser/renderer/TextRenderLayer.ts +344 -0
  40. package/dist/lib/xterm/src/browser/renderer/Types.d.ts +109 -0
  41. package/dist/lib/xterm/src/browser/renderer/atlas/BaseCharAtlas.ts +58 -0
  42. package/dist/lib/xterm/src/browser/renderer/atlas/CharAtlasCache.ts +95 -0
  43. package/dist/lib/xterm/src/browser/renderer/atlas/CharAtlasUtils.ts +54 -0
  44. package/dist/lib/xterm/src/browser/renderer/atlas/Constants.ts +15 -0
  45. package/dist/lib/xterm/src/browser/renderer/atlas/DynamicCharAtlas.ts +404 -0
  46. package/dist/lib/xterm/src/browser/renderer/atlas/LRUMap.ts +136 -0
  47. package/dist/lib/xterm/src/browser/renderer/atlas/Types.d.ts +29 -0
  48. package/dist/lib/xterm/src/browser/renderer/dom/DomRenderer.ts +403 -0
  49. package/dist/lib/xterm/src/browser/renderer/dom/DomRendererRowFactory.ts +344 -0
  50. package/dist/lib/xterm/src/browser/selection/SelectionModel.ts +144 -0
  51. package/dist/lib/xterm/src/browser/selection/Types.d.ts +15 -0
  52. package/dist/lib/xterm/src/browser/services/CharSizeService.ts +87 -0
  53. package/dist/lib/xterm/src/browser/services/CharacterJoinerService.ts +339 -0
  54. package/dist/lib/xterm/src/browser/services/CoreBrowserService.ts +20 -0
  55. package/dist/lib/xterm/src/browser/services/MouseService.ts +36 -0
  56. package/dist/lib/xterm/src/browser/services/RenderService.ts +237 -0
  57. package/dist/lib/xterm/src/browser/services/SelectionService.ts +1027 -0
  58. package/dist/lib/xterm/src/browser/services/Services.ts +123 -0
  59. package/dist/lib/xterm/src/browser/services/SoundService.ts +63 -0
  60. package/dist/lib/xterm/src/common/CircularList.ts +239 -0
  61. package/dist/lib/xterm/src/common/Clone.ts +23 -0
  62. package/dist/lib/xterm/src/common/Color.ts +285 -0
  63. package/dist/lib/xterm/src/common/CoreTerminal.ts +300 -0
  64. package/dist/lib/xterm/src/common/EventEmitter.ts +69 -0
  65. package/dist/lib/xterm/src/common/InputHandler.ts +3230 -0
  66. package/dist/lib/xterm/src/common/Lifecycle.ts +68 -0
  67. package/dist/lib/xterm/src/common/Platform.ts +31 -0
  68. package/dist/lib/xterm/src/common/SortedList.ts +88 -0
  69. package/dist/lib/xterm/src/common/TypedArrayUtils.ts +50 -0
  70. package/dist/lib/xterm/src/common/Types.d.ts +489 -0
  71. package/dist/lib/xterm/src/common/WindowsMode.ts +27 -0
  72. package/dist/lib/xterm/src/common/buffer/AttributeData.ts +148 -0
  73. package/dist/lib/xterm/src/common/buffer/Buffer.ts +711 -0
  74. package/dist/lib/xterm/src/common/buffer/BufferLine.ts +441 -0
  75. package/dist/lib/xterm/src/common/buffer/BufferRange.ts +13 -0
  76. package/dist/lib/xterm/src/common/buffer/BufferReflow.ts +220 -0
  77. package/dist/lib/xterm/src/common/buffer/BufferSet.ts +131 -0
  78. package/dist/lib/xterm/src/common/buffer/CellData.ts +94 -0
  79. package/dist/lib/xterm/src/common/buffer/Constants.ts +139 -0
  80. package/dist/lib/xterm/src/common/buffer/Marker.ts +37 -0
  81. package/dist/lib/xterm/src/common/buffer/Types.d.ts +64 -0
  82. package/dist/lib/xterm/src/common/data/Charsets.ts +256 -0
  83. package/dist/lib/xterm/src/common/data/EscapeSequences.ts +153 -0
  84. package/dist/lib/xterm/src/common/input/Keyboard.ts +398 -0
  85. package/dist/lib/xterm/src/common/input/TextDecoder.ts +346 -0
  86. package/dist/lib/xterm/src/common/input/UnicodeV6.ts +133 -0
  87. package/dist/lib/xterm/src/common/input/WriteBuffer.ts +229 -0
  88. package/dist/lib/xterm/src/common/input/XParseColor.ts +80 -0
  89. package/dist/lib/xterm/src/common/parser/Constants.ts +58 -0
  90. package/dist/lib/xterm/src/common/parser/DcsParser.ts +192 -0
  91. package/dist/lib/xterm/src/common/parser/EscapeSequenceParser.ts +796 -0
  92. package/dist/lib/xterm/src/common/parser/OscParser.ts +238 -0
  93. package/dist/lib/xterm/src/common/parser/Params.ts +229 -0
  94. package/dist/lib/xterm/src/common/parser/Types.d.ts +274 -0
  95. package/dist/lib/xterm/src/common/public/AddonManager.ts +56 -0
  96. package/dist/lib/xterm/src/common/public/BufferApiView.ts +35 -0
  97. package/dist/lib/xterm/src/common/public/BufferLineApiView.ts +29 -0
  98. package/dist/lib/xterm/src/common/public/BufferNamespaceApi.ts +33 -0
  99. package/dist/lib/xterm/src/common/public/ParserApi.ts +37 -0
  100. package/dist/lib/xterm/src/common/public/UnicodeApi.ts +27 -0
  101. package/dist/lib/xterm/src/common/services/BufferService.ts +185 -0
  102. package/dist/lib/xterm/src/common/services/CharsetService.ts +34 -0
  103. package/dist/lib/xterm/src/common/services/CoreMouseService.ts +309 -0
  104. package/dist/lib/xterm/src/common/services/CoreService.ts +92 -0
  105. package/dist/lib/xterm/src/common/services/DecorationService.ts +139 -0
  106. package/dist/lib/xterm/src/common/services/DirtyRowService.ts +53 -0
  107. package/dist/lib/xterm/src/common/services/InstantiationService.ts +83 -0
  108. package/dist/lib/xterm/src/common/services/LogService.ts +88 -0
  109. package/dist/lib/xterm/src/common/services/OptionsService.ts +178 -0
  110. package/dist/lib/xterm/src/common/services/ServiceRegistry.ts +49 -0
  111. package/dist/lib/xterm/src/common/services/Services.ts +323 -0
  112. package/dist/lib/xterm/src/common/services/UnicodeService.ts +82 -0
  113. package/dist/lib/xterm/src/headless/Terminal.ts +170 -0
  114. package/dist/lib/xterm/src/headless/Types.d.ts +31 -0
  115. package/dist/lib/xterm/src/headless/public/Terminal.ts +216 -0
  116. package/dist/lib/xterm/typings/xterm.d.ts +1872 -0
  117. package/dist/lib/xterm-fit/LICENSE +19 -0
  118. package/dist/lib/xterm-fit/README.md +24 -0
  119. package/dist/lib/xterm-fit/lib/xterm-addon-fit.js +2 -0
  120. package/dist/lib/xterm-fit/lib/xterm-addon-fit.js.map +1 -0
  121. package/dist/lib/xterm-fit/out/FitAddon.js +58 -0
  122. package/dist/lib/xterm-fit/out/FitAddon.js.map +1 -0
  123. package/dist/lib/xterm-fit/out-test/FitAddon.api.js.map +1 -0
  124. package/dist/lib/xterm-fit/package.json +21 -0
  125. package/dist/lib/xterm-fit/src/FitAddon.ts +86 -0
  126. package/dist/lib/xterm-fit/typings/xterm-addon-fit.d.ts +55 -0
  127. package/dist/lib/xterm-links/LICENSE +19 -0
  128. package/dist/lib/xterm-links/README.md +21 -0
  129. package/dist/lib/xterm-links/lib/xterm-addon-web-links.js +2 -0
  130. package/dist/lib/xterm-links/lib/xterm-addon-web-links.js.map +1 -0
  131. package/dist/lib/xterm-links/package.json +26 -0
  132. package/dist/lib/xterm-links/src/WebLinkProvider.ts +145 -0
  133. package/dist/lib/xterm-links/src/WebLinksAddon.ts +77 -0
  134. package/dist/lib/xterm-links/typings/xterm-addon-web-links.d.ts +58 -0
  135. package/package.json +1 -1
@@ -0,0 +1,3230 @@
1
+ /**
2
+ * Copyright (c) 2014 The xterm.js authors. All rights reserved.
3
+ * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
4
+ * @license MIT
5
+ */
6
+
7
+ import { IInputHandler, IAttributeData, IDisposable, IWindowOptions, IColorEvent, IParseStack, ColorIndex, ColorRequestType } from 'common/Types';
8
+ import { C0, C1 } from 'common/data/EscapeSequences';
9
+ import { CHARSETS, DEFAULT_CHARSET } from 'common/data/Charsets';
10
+ import { EscapeSequenceParser } from 'common/parser/EscapeSequenceParser';
11
+ import { Disposable } from 'common/Lifecycle';
12
+ import { concat } from 'common/TypedArrayUtils';
13
+ import { StringToUtf32, stringFromCodePoint, utf32ToString, Utf8ToUtf32 } from 'common/input/TextDecoder';
14
+ import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
15
+ import { EventEmitter, IEvent } from 'common/EventEmitter';
16
+ import { IParsingState, IDcsHandler, IEscapeSequenceParser, IParams, IFunctionIdentifier } from 'common/parser/Types';
17
+ import { NULL_CELL_CODE, NULL_CELL_WIDTH, Attributes, FgFlags, BgFlags, Content, UnderlineStyle } from 'common/buffer/Constants';
18
+ import { CellData } from 'common/buffer/CellData';
19
+ import { AttributeData } from 'common/buffer/AttributeData';
20
+ import { ICoreService, IBufferService, IOptionsService, ILogService, IDirtyRowService, ICoreMouseService, ICharsetService, IUnicodeService, LogLevelEnum } from 'common/services/Services';
21
+ import { OscHandler } from 'common/parser/OscParser';
22
+ import { DcsHandler } from 'common/parser/DcsParser';
23
+ import { IBuffer } from 'common/buffer/Types';
24
+ import { parseColor } from 'common/input/XParseColor';
25
+
26
+ /**
27
+ * Map collect to glevel. Used in `selectCharset`.
28
+ */
29
+ const GLEVEL: { [key: string]: number } = { '(': 0, ')': 1, '*': 2, '+': 3, '-': 1, '.': 2 };
30
+
31
+ /**
32
+ * VT commands done by the parser - FIXME: move this to the parser?
33
+ */
34
+ // @vt: #Y ESC CSI "Control Sequence Introducer" "ESC [" "Start of a CSI sequence."
35
+ // @vt: #Y ESC OSC "Operating System Command" "ESC ]" "Start of an OSC sequence."
36
+ // @vt: #Y ESC DCS "Device Control String" "ESC P" "Start of a DCS sequence."
37
+ // @vt: #Y ESC ST "String Terminator" "ESC \" "Terminator used for string type sequences."
38
+ // @vt: #Y ESC PM "Privacy Message" "ESC ^" "Start of a privacy message."
39
+ // @vt: #Y ESC APC "Application Program Command" "ESC _" "Start of an APC sequence."
40
+ // @vt: #Y C1 CSI "Control Sequence Introducer" "\x9B" "Start of a CSI sequence."
41
+ // @vt: #Y C1 OSC "Operating System Command" "\x9D" "Start of an OSC sequence."
42
+ // @vt: #Y C1 DCS "Device Control String" "\x90" "Start of a DCS sequence."
43
+ // @vt: #Y C1 ST "String Terminator" "\x9C" "Terminator used for string type sequences."
44
+ // @vt: #Y C1 PM "Privacy Message" "\x9E" "Start of a privacy message."
45
+ // @vt: #Y C1 APC "Application Program Command" "\x9F" "Start of an APC sequence."
46
+ // @vt: #Y C0 NUL "Null" "\0, \x00" "NUL is ignored."
47
+ // @vt: #Y C0 ESC "Escape" "\e, \x1B" "Start of a sequence. Cancels any other sequence."
48
+
49
+ /**
50
+ * Document common VT features here that are currently unsupported
51
+ */
52
+ // @vt: #N DCS SIXEL "SIXEL Graphics" "DCS Ps ; Ps ; Ps ; q Pt ST" "Draw SIXEL image starting at cursor position."
53
+ // @vt: #N OSC 1 "Set Icon Name" "OSC 1 ; Pt BEL" "Set icon name."
54
+
55
+ /**
56
+ * Max length of the UTF32 input buffer. Real memory consumption is 4 times higher.
57
+ */
58
+ const MAX_PARSEBUFFER_LENGTH = 131072;
59
+
60
+ /**
61
+ * Limit length of title and icon name stacks.
62
+ */
63
+ const STACK_LIMIT = 10;
64
+
65
+ // map params to window option
66
+ function paramToWindowOption(n: number, opts: IWindowOptions): boolean {
67
+ if (n > 24) {
68
+ return opts.setWinLines || false;
69
+ }
70
+ switch (n) {
71
+ case 1: return !!opts.restoreWin;
72
+ case 2: return !!opts.minimizeWin;
73
+ case 3: return !!opts.setWinPosition;
74
+ case 4: return !!opts.setWinSizePixels;
75
+ case 5: return !!opts.raiseWin;
76
+ case 6: return !!opts.lowerWin;
77
+ case 7: return !!opts.refreshWin;
78
+ case 8: return !!opts.setWinSizeChars;
79
+ case 9: return !!opts.maximizeWin;
80
+ case 10: return !!opts.fullscreenWin;
81
+ case 11: return !!opts.getWinState;
82
+ case 13: return !!opts.getWinPosition;
83
+ case 14: return !!opts.getWinSizePixels;
84
+ case 15: return !!opts.getScreenSizePixels;
85
+ case 16: return !!opts.getCellSizePixels;
86
+ case 18: return !!opts.getWinSizeChars;
87
+ case 19: return !!opts.getScreenSizeChars;
88
+ case 20: return !!opts.getIconTitle;
89
+ case 21: return !!opts.getWinTitle;
90
+ case 22: return !!opts.pushTitle;
91
+ case 23: return !!opts.popTitle;
92
+ case 24: return !!opts.setWinLines;
93
+ }
94
+ return false;
95
+ }
96
+
97
+ export enum WindowsOptionsReportType {
98
+ GET_WIN_SIZE_PIXELS = 0,
99
+ GET_CELL_SIZE_PIXELS = 1
100
+ }
101
+
102
+ // create a warning log if an async handler takes longer than the limit (in ms)
103
+ const SLOW_ASYNC_LIMIT = 5000;
104
+
105
+ /**
106
+ * DCS subparser implementations
107
+ */
108
+
109
+ /**
110
+ * DCS $ q Pt ST
111
+ * DECRQSS (https://vt100.net/docs/vt510-rm/DECRQSS.html)
112
+ * Request Status String (DECRQSS), VT420 and up.
113
+ * Response: DECRPSS (https://vt100.net/docs/vt510-rm/DECRPSS.html)
114
+ *
115
+ * @vt: #P[See limited support below.] DCS DECRQSS "Request Selection or Setting" "DCS $ q Pt ST" "Request several terminal settings."
116
+ * Response is in the form `ESC P 1 $ r Pt ST` for valid requests, where `Pt` contains the corresponding CSI string,
117
+ * `ESC P 0 ST` for invalid requests.
118
+ *
119
+ * Supported requests and responses:
120
+ *
121
+ * | Type | Request | Response (`Pt`) |
122
+ * | -------------------------------- | ----------------- | ----------------------------------------------------- |
123
+ * | Graphic Rendition (SGR) | `DCS $ q m ST` | always reporting `0m` (currently broken) |
124
+ * | Top and Bottom Margins (DECSTBM) | `DCS $ q r ST` | `Ps ; Ps r` |
125
+ * | Cursor Style (DECSCUSR) | `DCS $ q SP q ST` | `Ps SP q` |
126
+ * | Protection Attribute (DECSCA) | `DCS $ q " q ST` | always reporting `0 " q` (DECSCA is unsupported) |
127
+ * | Conformance Level (DECSCL) | `DCS $ q " p ST` | always reporting `61 ; 1 " p` (DECSCL is unsupported) |
128
+ *
129
+ *
130
+ * TODO:
131
+ * - fix SGR report
132
+ * - either implement DECSCA or remove the report
133
+ * - either check which conformance is better suited or remove the report completely
134
+ * --> we are currently a mixture of all up to VT400 but dont follow anyone strictly
135
+ */
136
+ class DECRQSS implements IDcsHandler {
137
+ private _data: Uint32Array = new Uint32Array(0);
138
+
139
+ constructor(
140
+ private _bufferService: IBufferService,
141
+ private _coreService: ICoreService,
142
+ private _logService: ILogService,
143
+ private _optionsService: IOptionsService
144
+ ) { }
145
+
146
+ public hook(params: IParams): void {
147
+ this._data = new Uint32Array(0);
148
+ }
149
+
150
+ public put(data: Uint32Array, start: number, end: number): void {
151
+ this._data = concat(this._data, data.subarray(start, end));
152
+ }
153
+
154
+ public unhook(success: boolean): boolean {
155
+ if (!success) {
156
+ this._data = new Uint32Array(0);
157
+ return true;
158
+ }
159
+ const data = utf32ToString(this._data);
160
+ this._data = new Uint32Array(0);
161
+ switch (data) {
162
+ // valid: DCS 1 $ r Pt ST (xterm)
163
+ case '"q': // DECSCA
164
+ this._coreService.triggerDataEvent(`${C0.ESC}P1$r0"q${C0.ESC}\\`);
165
+ break;
166
+ case '"p': // DECSCL
167
+ this._coreService.triggerDataEvent(`${C0.ESC}P1$r61;1"p${C0.ESC}\\`);
168
+ break;
169
+ case 'r': // DECSTBM
170
+ const pt = '' + (this._bufferService.buffer.scrollTop + 1) +
171
+ ';' + (this._bufferService.buffer.scrollBottom + 1) + 'r';
172
+ this._coreService.triggerDataEvent(`${C0.ESC}P1$r${pt}${C0.ESC}\\`);
173
+ break;
174
+ case 'm': // SGR
175
+ // TODO: report real settings instead of 0m
176
+ this._coreService.triggerDataEvent(`${C0.ESC}P1$r0m${C0.ESC}\\`);
177
+ break;
178
+ case ' q': // DECSCUSR
179
+ const STYLES: { [key: string]: number } = { 'block': 2, 'underline': 4, 'bar': 6 };
180
+ let style = STYLES[this._optionsService.rawOptions.cursorStyle];
181
+ style -= this._optionsService.rawOptions.cursorBlink ? 1 : 0;
182
+ this._coreService.triggerDataEvent(`${C0.ESC}P1$r${style} q${C0.ESC}\\`);
183
+ break;
184
+ default:
185
+ // invalid: DCS 0 $ r Pt ST (xterm)
186
+ this._logService.debug('Unknown DCS $q %s', data);
187
+ this._coreService.triggerDataEvent(`${C0.ESC}P0$r${C0.ESC}\\`);
188
+ }
189
+ return true;
190
+ }
191
+ }
192
+
193
+ /**
194
+ * DCS Ps; Ps| Pt ST
195
+ * DECUDK (https://vt100.net/docs/vt510-rm/DECUDK.html)
196
+ * not supported
197
+ *
198
+ * @vt: #N DCS DECUDK "User Defined Keys" "DCS Ps ; Ps | Pt ST" "Definitions for user-defined keys."
199
+ */
200
+
201
+ /**
202
+ * DCS + q Pt ST (xterm)
203
+ * Request Terminfo String
204
+ * not implemented
205
+ *
206
+ * @vt: #N DCS XTGETTCAP "Request Terminfo String" "DCS + q Pt ST" "Request Terminfo String."
207
+ */
208
+
209
+ /**
210
+ * DCS + p Pt ST (xterm)
211
+ * Set Terminfo Data
212
+ * not supported
213
+ *
214
+ * @vt: #N DCS XTSETTCAP "Set Terminfo Data" "DCS + p Pt ST" "Set Terminfo Data."
215
+ */
216
+
217
+
218
+
219
+ /**
220
+ * The terminal's standard implementation of IInputHandler, this handles all
221
+ * input from the Parser.
222
+ *
223
+ * Refer to http://invisible-island.net/xterm/ctlseqs/ctlseqs.html to understand
224
+ * each function's header comment.
225
+ */
226
+ export class InputHandler extends Disposable implements IInputHandler {
227
+ private _parseBuffer: Uint32Array = new Uint32Array(4096);
228
+ private _stringDecoder: StringToUtf32 = new StringToUtf32();
229
+ private _utf8Decoder: Utf8ToUtf32 = new Utf8ToUtf32();
230
+ private _workCell: CellData = new CellData();
231
+ private _windowTitle = '';
232
+ private _iconName = '';
233
+ protected _windowTitleStack: string[] = [];
234
+ protected _iconNameStack: string[] = [];
235
+
236
+ private _curAttrData: IAttributeData = DEFAULT_ATTR_DATA.clone();
237
+ private _eraseAttrDataInternal: IAttributeData = DEFAULT_ATTR_DATA.clone();
238
+
239
+ private _activeBuffer: IBuffer;
240
+
241
+ private _onRequestBell = new EventEmitter<void>();
242
+ public get onRequestBell(): IEvent<void> { return this._onRequestBell.event; }
243
+ private _onRequestRefreshRows = new EventEmitter<number, number>();
244
+ public get onRequestRefreshRows(): IEvent<number, number> { return this._onRequestRefreshRows.event; }
245
+ private _onRequestReset = new EventEmitter<void>();
246
+ public get onRequestReset(): IEvent<void> { return this._onRequestReset.event; }
247
+ private _onRequestSendFocus = new EventEmitter<void>();
248
+ public get onRequestSendFocus(): IEvent<void> { return this._onRequestSendFocus.event; }
249
+ private _onRequestSyncScrollBar = new EventEmitter<void>();
250
+ public get onRequestSyncScrollBar(): IEvent<void> { return this._onRequestSyncScrollBar.event; }
251
+ private _onRequestWindowsOptionsReport = new EventEmitter<WindowsOptionsReportType>();
252
+ public get onRequestWindowsOptionsReport(): IEvent<WindowsOptionsReportType> { return this._onRequestWindowsOptionsReport.event; }
253
+
254
+ private _onA11yChar = new EventEmitter<string>();
255
+ public get onA11yChar(): IEvent<string> { return this._onA11yChar.event; }
256
+ private _onA11yTab = new EventEmitter<number>();
257
+ public get onA11yTab(): IEvent<number> { return this._onA11yTab.event; }
258
+ private _onCursorMove = new EventEmitter<void>();
259
+ public get onCursorMove(): IEvent<void> { return this._onCursorMove.event; }
260
+ private _onLineFeed = new EventEmitter<void>();
261
+ public get onLineFeed(): IEvent<void> { return this._onLineFeed.event; }
262
+ private _onScroll = new EventEmitter<number>();
263
+ public get onScroll(): IEvent<number> { return this._onScroll.event; }
264
+ private _onTitleChange = new EventEmitter<string>();
265
+ public get onTitleChange(): IEvent<string> { return this._onTitleChange.event; }
266
+ private _onColor = new EventEmitter<IColorEvent>();
267
+ public get onColor(): IEvent<IColorEvent> { return this._onColor.event; }
268
+
269
+ private _parseStack: IParseStack = {
270
+ paused: false,
271
+ cursorStartX: 0,
272
+ cursorStartY: 0,
273
+ decodedLength: 0,
274
+ position: 0
275
+ };
276
+
277
+ constructor(
278
+ private readonly _bufferService: IBufferService,
279
+ private readonly _charsetService: ICharsetService,
280
+ private readonly _coreService: ICoreService,
281
+ private readonly _dirtyRowService: IDirtyRowService,
282
+ private readonly _logService: ILogService,
283
+ private readonly _optionsService: IOptionsService,
284
+ private readonly _coreMouseService: ICoreMouseService,
285
+ private readonly _unicodeService: IUnicodeService,
286
+ private readonly _parser: IEscapeSequenceParser = new EscapeSequenceParser()
287
+ ) {
288
+ super();
289
+ this.register(this._parser);
290
+
291
+ // Track properties used in performance critical code manually to avoid using slow getters
292
+ this._activeBuffer = this._bufferService.buffer;
293
+ this.register(this._bufferService.buffers.onBufferActivate(e => this._activeBuffer = e.activeBuffer));
294
+
295
+ /**
296
+ * custom fallback handlers
297
+ */
298
+ this._parser.setCsiHandlerFallback((ident, params) => {
299
+ this._logService.debug('Unknown CSI code: ', { identifier: this._parser.identToString(ident), params: params.toArray() });
300
+ });
301
+ this._parser.setEscHandlerFallback(ident => {
302
+ this._logService.debug('Unknown ESC code: ', { identifier: this._parser.identToString(ident) });
303
+ });
304
+ this._parser.setExecuteHandlerFallback(code => {
305
+ this._logService.debug('Unknown EXECUTE code: ', { code });
306
+ });
307
+ this._parser.setOscHandlerFallback((identifier, action, data) => {
308
+ this._logService.debug('Unknown OSC code: ', { identifier, action, data });
309
+ });
310
+ this._parser.setDcsHandlerFallback((ident, action, payload) => {
311
+ if (action === 'HOOK') {
312
+ payload = payload.toArray();
313
+ }
314
+ this._logService.debug('Unknown DCS code: ', { identifier: this._parser.identToString(ident), action, payload });
315
+ });
316
+
317
+ /**
318
+ * print handler
319
+ */
320
+ this._parser.setPrintHandler((data, start, end) => this.print(data, start, end));
321
+
322
+ /**
323
+ * CSI handler
324
+ */
325
+ this._parser.registerCsiHandler({ final: '@' }, params => this.insertChars(params));
326
+ this._parser.registerCsiHandler({ intermediates: ' ', final: '@' }, params => this.scrollLeft(params));
327
+ this._parser.registerCsiHandler({ final: 'A' }, params => this.cursorUp(params));
328
+ this._parser.registerCsiHandler({ intermediates: ' ', final: 'A' }, params => this.scrollRight(params));
329
+ this._parser.registerCsiHandler({ final: 'B' }, params => this.cursorDown(params));
330
+ this._parser.registerCsiHandler({ final: 'C' }, params => this.cursorForward(params));
331
+ this._parser.registerCsiHandler({ final: 'D' }, params => this.cursorBackward(params));
332
+ this._parser.registerCsiHandler({ final: 'E' }, params => this.cursorNextLine(params));
333
+ this._parser.registerCsiHandler({ final: 'F' }, params => this.cursorPrecedingLine(params));
334
+ this._parser.registerCsiHandler({ final: 'G' }, params => this.cursorCharAbsolute(params));
335
+ this._parser.registerCsiHandler({ final: 'H' }, params => this.cursorPosition(params));
336
+ this._parser.registerCsiHandler({ final: 'I' }, params => this.cursorForwardTab(params));
337
+ this._parser.registerCsiHandler({ final: 'J' }, params => this.eraseInDisplay(params));
338
+ this._parser.registerCsiHandler({ prefix: '?', final: 'J' }, params => this.eraseInDisplay(params));
339
+ this._parser.registerCsiHandler({ final: 'K' }, params => this.eraseInLine(params));
340
+ this._parser.registerCsiHandler({ prefix: '?', final: 'K' }, params => this.eraseInLine(params));
341
+ this._parser.registerCsiHandler({ final: 'L' }, params => this.insertLines(params));
342
+ this._parser.registerCsiHandler({ final: 'M' }, params => this.deleteLines(params));
343
+ this._parser.registerCsiHandler({ final: 'P' }, params => this.deleteChars(params));
344
+ this._parser.registerCsiHandler({ final: 'S' }, params => this.scrollUp(params));
345
+ this._parser.registerCsiHandler({ final: 'T' }, params => this.scrollDown(params));
346
+ this._parser.registerCsiHandler({ final: 'X' }, params => this.eraseChars(params));
347
+ this._parser.registerCsiHandler({ final: 'Z' }, params => this.cursorBackwardTab(params));
348
+ this._parser.registerCsiHandler({ final: '`' }, params => this.charPosAbsolute(params));
349
+ this._parser.registerCsiHandler({ final: 'a' }, params => this.hPositionRelative(params));
350
+ this._parser.registerCsiHandler({ final: 'b' }, params => this.repeatPrecedingCharacter(params));
351
+ this._parser.registerCsiHandler({ final: 'c' }, params => this.sendDeviceAttributesPrimary(params));
352
+ this._parser.registerCsiHandler({ prefix: '>', final: 'c' }, params => this.sendDeviceAttributesSecondary(params));
353
+ this._parser.registerCsiHandler({ final: 'd' }, params => this.linePosAbsolute(params));
354
+ this._parser.registerCsiHandler({ final: 'e' }, params => this.vPositionRelative(params));
355
+ this._parser.registerCsiHandler({ final: 'f' }, params => this.hVPosition(params));
356
+ this._parser.registerCsiHandler({ final: 'g' }, params => this.tabClear(params));
357
+ this._parser.registerCsiHandler({ final: 'h' }, params => this.setMode(params));
358
+ this._parser.registerCsiHandler({ prefix: '?', final: 'h' }, params => this.setModePrivate(params));
359
+ this._parser.registerCsiHandler({ final: 'l' }, params => this.resetMode(params));
360
+ this._parser.registerCsiHandler({ prefix: '?', final: 'l' }, params => this.resetModePrivate(params));
361
+ this._parser.registerCsiHandler({ final: 'm' }, params => this.charAttributes(params));
362
+ this._parser.registerCsiHandler({ final: 'n' }, params => this.deviceStatus(params));
363
+ this._parser.registerCsiHandler({ prefix: '?', final: 'n' }, params => this.deviceStatusPrivate(params));
364
+ this._parser.registerCsiHandler({ intermediates: '!', final: 'p' }, params => this.softReset(params));
365
+ this._parser.registerCsiHandler({ intermediates: ' ', final: 'q' }, params => this.setCursorStyle(params));
366
+ this._parser.registerCsiHandler({ final: 'r' }, params => this.setScrollRegion(params));
367
+ this._parser.registerCsiHandler({ final: 's' }, params => this.saveCursor(params));
368
+ this._parser.registerCsiHandler({ final: 't' }, params => this.windowOptions(params));
369
+ this._parser.registerCsiHandler({ final: 'u' }, params => this.restoreCursor(params));
370
+ this._parser.registerCsiHandler({ intermediates: '\'', final: '}' }, params => this.insertColumns(params));
371
+ this._parser.registerCsiHandler({ intermediates: '\'', final: '~' }, params => this.deleteColumns(params));
372
+
373
+ /**
374
+ * execute handler
375
+ */
376
+ this._parser.setExecuteHandler(C0.BEL, () => this.bell());
377
+ this._parser.setExecuteHandler(C0.LF, () => this.lineFeed());
378
+ this._parser.setExecuteHandler(C0.VT, () => this.lineFeed());
379
+ this._parser.setExecuteHandler(C0.FF, () => this.lineFeed());
380
+ this._parser.setExecuteHandler(C0.CR, () => this.carriageReturn());
381
+ this._parser.setExecuteHandler(C0.BS, () => this.backspace());
382
+ this._parser.setExecuteHandler(C0.HT, () => this.tab());
383
+ this._parser.setExecuteHandler(C0.SO, () => this.shiftOut());
384
+ this._parser.setExecuteHandler(C0.SI, () => this.shiftIn());
385
+ // FIXME: What do to with missing? Old code just added those to print.
386
+
387
+ this._parser.setExecuteHandler(C1.IND, () => this.index());
388
+ this._parser.setExecuteHandler(C1.NEL, () => this.nextLine());
389
+ this._parser.setExecuteHandler(C1.HTS, () => this.tabSet());
390
+
391
+ /**
392
+ * OSC handler
393
+ */
394
+ // 0 - icon name + title
395
+ this._parser.registerOscHandler(0, new OscHandler(data => { this.setTitle(data); this.setIconName(data); return true; }));
396
+ // 1 - icon name
397
+ this._parser.registerOscHandler(1, new OscHandler(data => this.setIconName(data)));
398
+ // 2 - title
399
+ this._parser.registerOscHandler(2, new OscHandler(data => this.setTitle(data)));
400
+ // 3 - set property X in the form "prop=value"
401
+ // 4 - Change Color Number
402
+ this._parser.registerOscHandler(4, new OscHandler(data => this.setOrReportIndexedColor(data)));
403
+ // 5 - Change Special Color Number
404
+ // 6 - Enable/disable Special Color Number c
405
+ // 7 - current directory? (not in xterm spec, see https://gitlab.com/gnachman/iterm2/issues/3939)
406
+ // 10 - Change VT100 text foreground color to Pt.
407
+ this._parser.registerOscHandler(10, new OscHandler(data => this.setOrReportFgColor(data)));
408
+ // 11 - Change VT100 text background color to Pt.
409
+ this._parser.registerOscHandler(11, new OscHandler(data => this.setOrReportBgColor(data)));
410
+ // 12 - Change text cursor color to Pt.
411
+ this._parser.registerOscHandler(12, new OscHandler(data => this.setOrReportCursorColor(data)));
412
+ // 13 - Change mouse foreground color to Pt.
413
+ // 14 - Change mouse background color to Pt.
414
+ // 15 - Change Tektronix foreground color to Pt.
415
+ // 16 - Change Tektronix background color to Pt.
416
+ // 17 - Change highlight background color to Pt.
417
+ // 18 - Change Tektronix cursor color to Pt.
418
+ // 19 - Change highlight foreground color to Pt.
419
+ // 46 - Change Log File to Pt.
420
+ // 50 - Set Font to Pt.
421
+ // 51 - reserved for Emacs shell.
422
+ // 52 - Manipulate Selection Data.
423
+ // 104 ; c - Reset Color Number c.
424
+ this._parser.registerOscHandler(104, new OscHandler(data => this.restoreIndexedColor(data)));
425
+ // 105 ; c - Reset Special Color Number c.
426
+ // 106 ; c; f - Enable/disable Special Color Number c.
427
+ // 110 - Reset VT100 text foreground color.
428
+ this._parser.registerOscHandler(110, new OscHandler(data => this.restoreFgColor(data)));
429
+ // 111 - Reset VT100 text background color.
430
+ this._parser.registerOscHandler(111, new OscHandler(data => this.restoreBgColor(data)));
431
+ // 112 - Reset text cursor color.
432
+ this._parser.registerOscHandler(112, new OscHandler(data => this.restoreCursorColor(data)));
433
+ // 113 - Reset mouse foreground color.
434
+ // 114 - Reset mouse background color.
435
+ // 115 - Reset Tektronix foreground color.
436
+ // 116 - Reset Tektronix background color.
437
+ // 117 - Reset highlight color.
438
+ // 118 - Reset Tektronix cursor color.
439
+ // 119 - Reset highlight foreground color.
440
+
441
+ /**
442
+ * ESC handlers
443
+ */
444
+ this._parser.registerEscHandler({ final: '7' }, () => this.saveCursor());
445
+ this._parser.registerEscHandler({ final: '8' }, () => this.restoreCursor());
446
+ this._parser.registerEscHandler({ final: 'D' }, () => this.index());
447
+ this._parser.registerEscHandler({ final: 'E' }, () => this.nextLine());
448
+ this._parser.registerEscHandler({ final: 'H' }, () => this.tabSet());
449
+ this._parser.registerEscHandler({ final: 'M' }, () => this.reverseIndex());
450
+ this._parser.registerEscHandler({ final: '=' }, () => this.keypadApplicationMode());
451
+ this._parser.registerEscHandler({ final: '>' }, () => this.keypadNumericMode());
452
+ this._parser.registerEscHandler({ final: 'c' }, () => this.fullReset());
453
+ this._parser.registerEscHandler({ final: 'n' }, () => this.setgLevel(2));
454
+ this._parser.registerEscHandler({ final: 'o' }, () => this.setgLevel(3));
455
+ this._parser.registerEscHandler({ final: '|' }, () => this.setgLevel(3));
456
+ this._parser.registerEscHandler({ final: '}' }, () => this.setgLevel(2));
457
+ this._parser.registerEscHandler({ final: '~' }, () => this.setgLevel(1));
458
+ this._parser.registerEscHandler({ intermediates: '%', final: '@' }, () => this.selectDefaultCharset());
459
+ this._parser.registerEscHandler({ intermediates: '%', final: 'G' }, () => this.selectDefaultCharset());
460
+ for (const flag in CHARSETS) {
461
+ this._parser.registerEscHandler({ intermediates: '(', final: flag }, () => this.selectCharset('(' + flag));
462
+ this._parser.registerEscHandler({ intermediates: ')', final: flag }, () => this.selectCharset(')' + flag));
463
+ this._parser.registerEscHandler({ intermediates: '*', final: flag }, () => this.selectCharset('*' + flag));
464
+ this._parser.registerEscHandler({ intermediates: '+', final: flag }, () => this.selectCharset('+' + flag));
465
+ this._parser.registerEscHandler({ intermediates: '-', final: flag }, () => this.selectCharset('-' + flag));
466
+ this._parser.registerEscHandler({ intermediates: '.', final: flag }, () => this.selectCharset('.' + flag));
467
+ this._parser.registerEscHandler({ intermediates: '/', final: flag }, () => this.selectCharset('/' + flag)); // TODO: supported?
468
+ }
469
+ this._parser.registerEscHandler({ intermediates: '#', final: '8' }, () => this.screenAlignmentPattern());
470
+
471
+ /**
472
+ * error handler
473
+ */
474
+ this._parser.setErrorHandler((state: IParsingState) => {
475
+ this._logService.error('Parsing error: ', state);
476
+ return state;
477
+ });
478
+
479
+ /**
480
+ * DCS handler
481
+ */
482
+ this._parser.registerDcsHandler({ intermediates: '$', final: 'q' }, new DECRQSS(this._bufferService, this._coreService, this._logService, this._optionsService));
483
+ }
484
+
485
+ public dispose(): void {
486
+ super.dispose();
487
+ }
488
+
489
+ /**
490
+ * Async parse support.
491
+ */
492
+ private _preserveStack(cursorStartX: number, cursorStartY: number, decodedLength: number, position: number): void {
493
+ this._parseStack.paused = true;
494
+ this._parseStack.cursorStartX = cursorStartX;
495
+ this._parseStack.cursorStartY = cursorStartY;
496
+ this._parseStack.decodedLength = decodedLength;
497
+ this._parseStack.position = position;
498
+ }
499
+
500
+ private _logSlowResolvingAsync(p: Promise<boolean>): void {
501
+ // log a limited warning about an async handler taking too long
502
+ if (this._logService.logLevel <= LogLevelEnum.WARN) {
503
+ Promise.race([p, new Promise((res, rej) => setTimeout(() => rej('#SLOW_TIMEOUT'), SLOW_ASYNC_LIMIT))])
504
+ .catch(err => {
505
+ if (err !== '#SLOW_TIMEOUT') {
506
+ throw err;
507
+ }
508
+ console.warn(`async parser handler taking longer than ${SLOW_ASYNC_LIMIT} ms`);
509
+ });
510
+ }
511
+ }
512
+
513
+ /**
514
+ * Parse call with async handler support.
515
+ *
516
+ * Whether the stack state got preserved for the next call, is indicated by the return value:
517
+ * - undefined (void):
518
+ * all handlers were sync, no stack save, continue normally with next chunk
519
+ * - Promise\<boolean\>:
520
+ * execution stopped at async handler, stack saved, continue with
521
+ * same chunk and the promise resolve value as `promiseResult` until the method returns `undefined`
522
+ *
523
+ * Note: This method should only be called by `Terminal.write` to ensure correct execution order and
524
+ * proper continuation of async parser handlers.
525
+ */
526
+ public parse(data: string | Uint8Array, promiseResult?: boolean): void | Promise<boolean> {
527
+ let result: void | Promise<boolean>;
528
+ let cursorStartX = this._activeBuffer.x;
529
+ let cursorStartY = this._activeBuffer.y;
530
+ let start = 0;
531
+ const wasPaused = this._parseStack.paused;
532
+
533
+ if (wasPaused) {
534
+ // assumption: _parseBuffer never mutates between async calls
535
+ if (result = this._parser.parse(this._parseBuffer, this._parseStack.decodedLength, promiseResult)) {
536
+ this._logSlowResolvingAsync(result);
537
+ return result;
538
+ }
539
+ cursorStartX = this._parseStack.cursorStartX;
540
+ cursorStartY = this._parseStack.cursorStartY;
541
+ this._parseStack.paused = false;
542
+ if (data.length > MAX_PARSEBUFFER_LENGTH) {
543
+ start = this._parseStack.position + MAX_PARSEBUFFER_LENGTH;
544
+ }
545
+ }
546
+
547
+ // Log debug data, the log level gate is to prevent extra work in this hot path
548
+ if (this._logService.logLevel <= LogLevelEnum.DEBUG) {
549
+ this._logService.debug(`parsing data${typeof data === 'string' ? ` "${data}"` : ` "${Array.prototype.map.call(data, e => String.fromCharCode(e)).join('')}"`}`, typeof data === 'string'
550
+ ? data.split('').map(e => e.charCodeAt(0))
551
+ : data
552
+ );
553
+ }
554
+
555
+ // resize input buffer if needed
556
+ if (this._parseBuffer.length < data.length) {
557
+ if (this._parseBuffer.length < MAX_PARSEBUFFER_LENGTH) {
558
+ this._parseBuffer = new Uint32Array(Math.min(data.length, MAX_PARSEBUFFER_LENGTH));
559
+ }
560
+ }
561
+
562
+ // Clear the dirty row service so we know which lines changed as a result of parsing
563
+ // Important: do not clear between async calls, otherwise we lost pending update information.
564
+ if (!wasPaused) {
565
+ this._dirtyRowService.clearRange();
566
+ }
567
+
568
+ // process big data in smaller chunks
569
+ if (data.length > MAX_PARSEBUFFER_LENGTH) {
570
+ for (let i = start; i < data.length; i += MAX_PARSEBUFFER_LENGTH) {
571
+ const end = i + MAX_PARSEBUFFER_LENGTH < data.length ? i + MAX_PARSEBUFFER_LENGTH : data.length;
572
+ const len = (typeof data === 'string')
573
+ ? this._stringDecoder.decode(data.substring(i, end), this._parseBuffer)
574
+ : this._utf8Decoder.decode(data.subarray(i, end), this._parseBuffer);
575
+ if (result = this._parser.parse(this._parseBuffer, len)) {
576
+ this._preserveStack(cursorStartX, cursorStartY, len, i);
577
+ this._logSlowResolvingAsync(result);
578
+ return result;
579
+ }
580
+ }
581
+ } else {
582
+ if (!wasPaused) {
583
+ const len = (typeof data === 'string')
584
+ ? this._stringDecoder.decode(data, this._parseBuffer)
585
+ : this._utf8Decoder.decode(data, this._parseBuffer);
586
+ if (result = this._parser.parse(this._parseBuffer, len)) {
587
+ this._preserveStack(cursorStartX, cursorStartY, len, 0);
588
+ this._logSlowResolvingAsync(result);
589
+ return result;
590
+ }
591
+ }
592
+ }
593
+
594
+ if (this._activeBuffer.x !== cursorStartX || this._activeBuffer.y !== cursorStartY) {
595
+ this._onCursorMove.fire();
596
+ }
597
+
598
+ // Refresh any dirty rows accumulated as part of parsing
599
+ this._onRequestRefreshRows.fire(this._dirtyRowService.start, this._dirtyRowService.end);
600
+ }
601
+
602
+ public print(data: Uint32Array, start: number, end: number): void {
603
+ let code: number;
604
+ let chWidth: number;
605
+ const charset = this._charsetService.charset;
606
+ const screenReaderMode = this._optionsService.rawOptions.screenReaderMode;
607
+ const cols = this._bufferService.cols;
608
+ const wraparoundMode = this._coreService.decPrivateModes.wraparound;
609
+ const insertMode = this._coreService.modes.insertMode;
610
+ const curAttr = this._curAttrData;
611
+ let bufferRow = this._activeBuffer.lines.get(this._activeBuffer.ybase + this._activeBuffer.y)!;
612
+
613
+ this._dirtyRowService.markDirty(this._activeBuffer.y);
614
+
615
+ // handle wide chars: reset start_cell-1 if we would overwrite the second cell of a wide char
616
+ if (this._activeBuffer.x && end - start > 0 && bufferRow.getWidth(this._activeBuffer.x - 1) === 2) {
617
+ bufferRow.setCellFromCodePoint(this._activeBuffer.x - 1, 0, 1, curAttr.fg, curAttr.bg, curAttr.extended);
618
+ }
619
+
620
+ for (let pos = start; pos < end; ++pos) {
621
+ code = data[pos];
622
+
623
+ // calculate print space
624
+ // expensive call, therefore we save width in line buffer
625
+ chWidth = this._unicodeService.wcwidth(code);
626
+
627
+ // get charset replacement character
628
+ // charset is only defined for ASCII, therefore we only
629
+ // search for an replacement char if code < 127
630
+ if (code < 127 && charset) {
631
+ const ch = charset[String.fromCharCode(code)];
632
+ if (ch) {
633
+ code = ch.charCodeAt(0);
634
+ }
635
+ }
636
+
637
+ if (screenReaderMode) {
638
+ this._onA11yChar.fire(stringFromCodePoint(code));
639
+ }
640
+
641
+ // insert combining char at last cursor position
642
+ // this._activeBuffer.x should never be 0 for a combining char
643
+ // since they always follow a cell consuming char
644
+ // therefore we can test for this._activeBuffer.x to avoid overflow left
645
+ if (!chWidth && this._activeBuffer.x) {
646
+ if (!bufferRow.getWidth(this._activeBuffer.x - 1)) {
647
+ // found empty cell after fullwidth, need to go 2 cells back
648
+ // it is save to step 2 cells back here
649
+ // since an empty cell is only set by fullwidth chars
650
+ bufferRow.addCodepointToCell(this._activeBuffer.x - 2, code);
651
+ } else {
652
+ bufferRow.addCodepointToCell(this._activeBuffer.x - 1, code);
653
+ }
654
+ continue;
655
+ }
656
+
657
+ // goto next line if ch would overflow
658
+ // NOTE: To avoid costly width checks here,
659
+ // the terminal does not allow a cols < 2.
660
+ if (this._activeBuffer.x + chWidth - 1 >= cols) {
661
+ // autowrap - DECAWM
662
+ // automatically wraps to the beginning of the next line
663
+ if (wraparoundMode) {
664
+ // clear left over cells to the right
665
+ while (this._activeBuffer.x < cols) {
666
+ bufferRow.setCellFromCodePoint(this._activeBuffer.x++, 0, 1, curAttr.fg, curAttr.bg, curAttr.extended);
667
+ }
668
+ this._activeBuffer.x = 0;
669
+ this._activeBuffer.y++;
670
+ if (this._activeBuffer.y === this._activeBuffer.scrollBottom + 1) {
671
+ this._activeBuffer.y--;
672
+ this._bufferService.scroll(this._eraseAttrData(), true);
673
+ } else {
674
+ if (this._activeBuffer.y >= this._bufferService.rows) {
675
+ this._activeBuffer.y = this._bufferService.rows - 1;
676
+ }
677
+ // The line already exists (eg. the initial viewport), mark it as a
678
+ // wrapped line
679
+ this._activeBuffer.lines.get(this._activeBuffer.ybase + this._activeBuffer.y)!.isWrapped = true;
680
+ }
681
+ // row changed, get it again
682
+ bufferRow = this._activeBuffer.lines.get(this._activeBuffer.ybase + this._activeBuffer.y)!;
683
+ } else {
684
+ this._activeBuffer.x = cols - 1;
685
+ if (chWidth === 2) {
686
+ // FIXME: check for xterm behavior
687
+ // What to do here? We got a wide char that does not fit into last cell
688
+ continue;
689
+ }
690
+ }
691
+ }
692
+
693
+ // insert mode: move characters to right
694
+ if (insertMode) {
695
+ // right shift cells according to the width
696
+ bufferRow.insertCells(this._activeBuffer.x, chWidth, this._activeBuffer.getNullCell(curAttr), curAttr);
697
+ // test last cell - since the last cell has only room for
698
+ // a halfwidth char any fullwidth shifted there is lost
699
+ // and will be set to empty cell
700
+ if (bufferRow.getWidth(cols - 1) === 2) {
701
+ bufferRow.setCellFromCodePoint(cols - 1, NULL_CELL_CODE, NULL_CELL_WIDTH, curAttr.fg, curAttr.bg, curAttr.extended);
702
+ }
703
+ }
704
+
705
+ // write current char to buffer and advance cursor
706
+ bufferRow.setCellFromCodePoint(this._activeBuffer.x++, code, chWidth, curAttr.fg, curAttr.bg, curAttr.extended);
707
+
708
+ // fullwidth char - also set next cell to placeholder stub and advance cursor
709
+ // for graphemes bigger than fullwidth we can simply loop to zero
710
+ // we already made sure above, that this._activeBuffer.x + chWidth will not overflow right
711
+ if (chWidth > 0) {
712
+ while (--chWidth) {
713
+ // other than a regular empty cell a cell following a wide char has no width
714
+ bufferRow.setCellFromCodePoint(this._activeBuffer.x++, 0, 0, curAttr.fg, curAttr.bg, curAttr.extended);
715
+ }
716
+ }
717
+ }
718
+ // store last char in Parser.precedingCodepoint for REP to work correctly
719
+ // This needs to check whether:
720
+ // - fullwidth + surrogates: reset
721
+ // - combining: only base char gets carried on (bug in xterm?)
722
+ if (end - start > 0) {
723
+ bufferRow.loadCell(this._activeBuffer.x - 1, this._workCell);
724
+ if (this._workCell.getWidth() === 2 || this._workCell.getCode() > 0xFFFF) {
725
+ this._parser.precedingCodepoint = 0;
726
+ } else if (this._workCell.isCombined()) {
727
+ this._parser.precedingCodepoint = this._workCell.getChars().charCodeAt(0);
728
+ } else {
729
+ this._parser.precedingCodepoint = this._workCell.content;
730
+ }
731
+ }
732
+
733
+ // handle wide chars: reset cell to the right if it is second cell of a wide char
734
+ if (this._activeBuffer.x < cols && end - start > 0 && bufferRow.getWidth(this._activeBuffer.x) === 0 && !bufferRow.hasContent(this._activeBuffer.x)) {
735
+ bufferRow.setCellFromCodePoint(this._activeBuffer.x, 0, 1, curAttr.fg, curAttr.bg, curAttr.extended);
736
+ }
737
+
738
+ this._dirtyRowService.markDirty(this._activeBuffer.y);
739
+ }
740
+
741
+ /**
742
+ * Forward registerCsiHandler from parser.
743
+ */
744
+ public registerCsiHandler(id: IFunctionIdentifier, callback: (params: IParams) => boolean | Promise<boolean>): IDisposable {
745
+ if (id.final === 't' && !id.prefix && !id.intermediates) {
746
+ // security: always check whether window option is allowed
747
+ return this._parser.registerCsiHandler(id, params => {
748
+ if (!paramToWindowOption(params.params[0], this._optionsService.rawOptions.windowOptions)) {
749
+ return true;
750
+ }
751
+ return callback(params);
752
+ });
753
+ }
754
+ return this._parser.registerCsiHandler(id, callback);
755
+ }
756
+
757
+ /**
758
+ * Forward registerDcsHandler from parser.
759
+ */
760
+ public registerDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: IParams) => boolean | Promise<boolean>): IDisposable {
761
+ return this._parser.registerDcsHandler(id, new DcsHandler(callback));
762
+ }
763
+
764
+ /**
765
+ * Forward registerEscHandler from parser.
766
+ */
767
+ public registerEscHandler(id: IFunctionIdentifier, callback: () => boolean | Promise<boolean>): IDisposable {
768
+ return this._parser.registerEscHandler(id, callback);
769
+ }
770
+
771
+ /**
772
+ * Forward registerOscHandler from parser.
773
+ */
774
+ public registerOscHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable {
775
+ return this._parser.registerOscHandler(ident, new OscHandler(callback));
776
+ }
777
+
778
+ /**
779
+ * BEL
780
+ * Bell (Ctrl-G).
781
+ *
782
+ * @vt: #Y C0 BEL "Bell" "\a, \x07" "Ring the bell."
783
+ * The behavior of the bell is further customizable with `ITerminalOptions.bellStyle`
784
+ * and `ITerminalOptions.bellSound`.
785
+ */
786
+ public bell(): boolean {
787
+ this._onRequestBell.fire();
788
+ return true;
789
+ }
790
+
791
+ /**
792
+ * LF
793
+ * Line Feed or New Line (NL). (LF is Ctrl-J).
794
+ *
795
+ * @vt: #Y C0 LF "Line Feed" "\n, \x0A" "Move the cursor one row down, scrolling if needed."
796
+ * Scrolling is restricted to scroll margins and will only happen on the bottom line.
797
+ *
798
+ * @vt: #Y C0 VT "Vertical Tabulation" "\v, \x0B" "Treated as LF."
799
+ * @vt: #Y C0 FF "Form Feed" "\f, \x0C" "Treated as LF."
800
+ */
801
+ public lineFeed(): boolean {
802
+ this._dirtyRowService.markDirty(this._activeBuffer.y);
803
+ if (this._optionsService.rawOptions.convertEol) {
804
+ this._activeBuffer.x = 0;
805
+ }
806
+ this._activeBuffer.y++;
807
+ if (this._activeBuffer.y === this._activeBuffer.scrollBottom + 1) {
808
+ this._activeBuffer.y--;
809
+ this._bufferService.scroll(this._eraseAttrData());
810
+ } else if (this._activeBuffer.y >= this._bufferService.rows) {
811
+ this._activeBuffer.y = this._bufferService.rows - 1;
812
+ }
813
+ // If the end of the line is hit, prevent this action from wrapping around to the next line.
814
+ if (this._activeBuffer.x >= this._bufferService.cols) {
815
+ this._activeBuffer.x--;
816
+ }
817
+ this._dirtyRowService.markDirty(this._activeBuffer.y);
818
+
819
+ this._onLineFeed.fire();
820
+ return true;
821
+ }
822
+
823
+ /**
824
+ * CR
825
+ * Carriage Return (Ctrl-M).
826
+ *
827
+ * @vt: #Y C0 CR "Carriage Return" "\r, \x0D" "Move the cursor to the beginning of the row."
828
+ */
829
+ public carriageReturn(): boolean {
830
+ this._activeBuffer.x = 0;
831
+ return true;
832
+ }
833
+
834
+ /**
835
+ * BS
836
+ * Backspace (Ctrl-H).
837
+ *
838
+ * @vt: #Y C0 BS "Backspace" "\b, \x08" "Move the cursor one position to the left."
839
+ * By default it is not possible to move the cursor past the leftmost position.
840
+ * If `reverse wrap-around` (`CSI ? 45 h`) is set, a previous soft line wrap (DECAWM)
841
+ * can be undone with BS within the scroll margins. In that case the cursor will wrap back
842
+ * to the end of the previous row. Note that it is not possible to peek back into the scrollbuffer
843
+ * with the cursor, thus at the home position (top-leftmost cell) this has no effect.
844
+ */
845
+ public backspace(): boolean {
846
+ // reverse wrap-around is disabled
847
+ if (!this._coreService.decPrivateModes.reverseWraparound) {
848
+ this._restrictCursor();
849
+ if (this._activeBuffer.x > 0) {
850
+ this._activeBuffer.x--;
851
+ }
852
+ return true;
853
+ }
854
+
855
+ // reverse wrap-around is enabled
856
+ // other than for normal operation mode, reverse wrap-around allows the cursor
857
+ // to be at x=cols to be able to address the last cell of a row by BS
858
+ this._restrictCursor(this._bufferService.cols);
859
+
860
+ if (this._activeBuffer.x > 0) {
861
+ this._activeBuffer.x--;
862
+ } else {
863
+ /**
864
+ * reverse wrap-around handling:
865
+ * Our implementation deviates from xterm on purpose. Details:
866
+ * - only previous soft NLs can be reversed (isWrapped=true)
867
+ * - only works within scrollborders (top/bottom, left/right not yet supported)
868
+ * - cannot peek into scrollbuffer
869
+ * - any cursor movement sequence keeps working as expected
870
+ */
871
+ if (this._activeBuffer.x === 0
872
+ && this._activeBuffer.y > this._activeBuffer.scrollTop
873
+ && this._activeBuffer.y <= this._activeBuffer.scrollBottom
874
+ && this._activeBuffer.lines.get(this._activeBuffer.ybase + this._activeBuffer.y)?.isWrapped) {
875
+ this._activeBuffer.lines.get(this._activeBuffer.ybase + this._activeBuffer.y)!.isWrapped = false;
876
+ this._activeBuffer.y--;
877
+ this._activeBuffer.x = this._bufferService.cols - 1;
878
+ // find last taken cell - last cell can have 3 different states:
879
+ // - hasContent(true) + hasWidth(1): narrow char - we are done
880
+ // - hasWidth(0): second part of wide char - we are done
881
+ // - hasContent(false) + hasWidth(1): empty cell due to early wrapping wide char, go one cell further back
882
+ const line = this._activeBuffer.lines.get(this._activeBuffer.ybase + this._activeBuffer.y)!;
883
+ if (line.hasWidth(this._activeBuffer.x) && !line.hasContent(this._activeBuffer.x)) {
884
+ this._activeBuffer.x--;
885
+ // We do this only once, since width=1 + hasContent=false currently happens only once before
886
+ // early wrapping of a wide char.
887
+ // This needs to be fixed once we support graphemes taking more than 2 cells.
888
+ }
889
+ }
890
+ }
891
+ this._restrictCursor();
892
+ return true;
893
+ }
894
+
895
+ /**
896
+ * TAB
897
+ * Horizontal Tab (HT) (Ctrl-I).
898
+ *
899
+ * @vt: #Y C0 HT "Horizontal Tabulation" "\t, \x09" "Move the cursor to the next character tab stop."
900
+ */
901
+ public tab(): boolean {
902
+ if (this._activeBuffer.x >= this._bufferService.cols) {
903
+ return true;
904
+ }
905
+ const originalX = this._activeBuffer.x;
906
+ this._activeBuffer.x = this._activeBuffer.nextStop();
907
+ if (this._optionsService.rawOptions.screenReaderMode) {
908
+ this._onA11yTab.fire(this._activeBuffer.x - originalX);
909
+ }
910
+ return true;
911
+ }
912
+
913
+ /**
914
+ * SO
915
+ * Shift Out (Ctrl-N) -> Switch to Alternate Character Set. This invokes the
916
+ * G1 character set.
917
+ *
918
+ * @vt: #P[Only limited ISO-2022 charset support.] C0 SO "Shift Out" "\x0E" "Switch to an alternative character set."
919
+ */
920
+ public shiftOut(): boolean {
921
+ this._charsetService.setgLevel(1);
922
+ return true;
923
+ }
924
+
925
+ /**
926
+ * SI
927
+ * Shift In (Ctrl-O) -> Switch to Standard Character Set. This invokes the G0
928
+ * character set (the default).
929
+ *
930
+ * @vt: #Y C0 SI "Shift In" "\x0F" "Return to regular character set after Shift Out."
931
+ */
932
+ public shiftIn(): boolean {
933
+ this._charsetService.setgLevel(0);
934
+ return true;
935
+ }
936
+
937
+ /**
938
+ * Restrict cursor to viewport size / scroll margin (origin mode).
939
+ */
940
+ private _restrictCursor(maxCol: number = this._bufferService.cols - 1): void {
941
+ this._activeBuffer.x = Math.min(maxCol, Math.max(0, this._activeBuffer.x));
942
+ this._activeBuffer.y = this._coreService.decPrivateModes.origin
943
+ ? Math.min(this._activeBuffer.scrollBottom, Math.max(this._activeBuffer.scrollTop, this._activeBuffer.y))
944
+ : Math.min(this._bufferService.rows - 1, Math.max(0, this._activeBuffer.y));
945
+ this._dirtyRowService.markDirty(this._activeBuffer.y);
946
+ }
947
+
948
+ /**
949
+ * Set absolute cursor position.
950
+ */
951
+ private _setCursor(x: number, y: number): void {
952
+ this._dirtyRowService.markDirty(this._activeBuffer.y);
953
+ if (this._coreService.decPrivateModes.origin) {
954
+ this._activeBuffer.x = x;
955
+ this._activeBuffer.y = this._activeBuffer.scrollTop + y;
956
+ } else {
957
+ this._activeBuffer.x = x;
958
+ this._activeBuffer.y = y;
959
+ }
960
+ this._restrictCursor();
961
+ this._dirtyRowService.markDirty(this._activeBuffer.y);
962
+ }
963
+
964
+ /**
965
+ * Set relative cursor position.
966
+ */
967
+ private _moveCursor(x: number, y: number): void {
968
+ // for relative changes we have to make sure we are within 0 .. cols/rows - 1
969
+ // before calculating the new position
970
+ this._restrictCursor();
971
+ this._setCursor(this._activeBuffer.x + x, this._activeBuffer.y + y);
972
+ }
973
+
974
+ /**
975
+ * CSI Ps A
976
+ * Cursor Up Ps Times (default = 1) (CUU).
977
+ *
978
+ * @vt: #Y CSI CUU "Cursor Up" "CSI Ps A" "Move cursor `Ps` times up (default=1)."
979
+ * If the cursor would pass the top scroll margin, it will stop there.
980
+ */
981
+ public cursorUp(params: IParams): boolean {
982
+ // stop at scrollTop
983
+ const diffToTop = this._activeBuffer.y - this._activeBuffer.scrollTop;
984
+ if (diffToTop >= 0) {
985
+ this._moveCursor(0, -Math.min(diffToTop, params.params[0] || 1));
986
+ } else {
987
+ this._moveCursor(0, -(params.params[0] || 1));
988
+ }
989
+ return true;
990
+ }
991
+
992
+ /**
993
+ * CSI Ps B
994
+ * Cursor Down Ps Times (default = 1) (CUD).
995
+ *
996
+ * @vt: #Y CSI CUD "Cursor Down" "CSI Ps B" "Move cursor `Ps` times down (default=1)."
997
+ * If the cursor would pass the bottom scroll margin, it will stop there.
998
+ */
999
+ public cursorDown(params: IParams): boolean {
1000
+ // stop at scrollBottom
1001
+ const diffToBottom = this._activeBuffer.scrollBottom - this._activeBuffer.y;
1002
+ if (diffToBottom >= 0) {
1003
+ this._moveCursor(0, Math.min(diffToBottom, params.params[0] || 1));
1004
+ } else {
1005
+ this._moveCursor(0, params.params[0] || 1);
1006
+ }
1007
+ return true;
1008
+ }
1009
+
1010
+ /**
1011
+ * CSI Ps C
1012
+ * Cursor Forward Ps Times (default = 1) (CUF).
1013
+ *
1014
+ * @vt: #Y CSI CUF "Cursor Forward" "CSI Ps C" "Move cursor `Ps` times forward (default=1)."
1015
+ */
1016
+ public cursorForward(params: IParams): boolean {
1017
+ this._moveCursor(params.params[0] || 1, 0);
1018
+ return true;
1019
+ }
1020
+
1021
+ /**
1022
+ * CSI Ps D
1023
+ * Cursor Backward Ps Times (default = 1) (CUB).
1024
+ *
1025
+ * @vt: #Y CSI CUB "Cursor Backward" "CSI Ps D" "Move cursor `Ps` times backward (default=1)."
1026
+ */
1027
+ public cursorBackward(params: IParams): boolean {
1028
+ this._moveCursor(-(params.params[0] || 1), 0);
1029
+ return true;
1030
+ }
1031
+
1032
+ /**
1033
+ * CSI Ps E
1034
+ * Cursor Next Line Ps Times (default = 1) (CNL).
1035
+ * Other than cursorDown (CUD) also set the cursor to first column.
1036
+ *
1037
+ * @vt: #Y CSI CNL "Cursor Next Line" "CSI Ps E" "Move cursor `Ps` times down (default=1) and to the first column."
1038
+ * Same as CUD, additionally places the cursor at the first column.
1039
+ */
1040
+ public cursorNextLine(params: IParams): boolean {
1041
+ this.cursorDown(params);
1042
+ this._activeBuffer.x = 0;
1043
+ return true;
1044
+ }
1045
+
1046
+ /**
1047
+ * CSI Ps F
1048
+ * Cursor Previous Line Ps Times (default = 1) (CPL).
1049
+ * Other than cursorUp (CUU) also set the cursor to first column.
1050
+ *
1051
+ * @vt: #Y CSI CPL "Cursor Backward" "CSI Ps F" "Move cursor `Ps` times up (default=1) and to the first column."
1052
+ * Same as CUU, additionally places the cursor at the first column.
1053
+ */
1054
+ public cursorPrecedingLine(params: IParams): boolean {
1055
+ this.cursorUp(params);
1056
+ this._activeBuffer.x = 0;
1057
+ return true;
1058
+ }
1059
+
1060
+ /**
1061
+ * CSI Ps G
1062
+ * Cursor Character Absolute [column] (default = [row,1]) (CHA).
1063
+ *
1064
+ * @vt: #Y CSI CHA "Cursor Horizontal Absolute" "CSI Ps G" "Move cursor to `Ps`-th column of the active row (default=1)."
1065
+ */
1066
+ public cursorCharAbsolute(params: IParams): boolean {
1067
+ this._setCursor((params.params[0] || 1) - 1, this._activeBuffer.y);
1068
+ return true;
1069
+ }
1070
+
1071
+ /**
1072
+ * CSI Ps ; Ps H
1073
+ * Cursor Position [row;column] (default = [1,1]) (CUP).
1074
+ *
1075
+ * @vt: #Y CSI CUP "Cursor Position" "CSI Ps ; Ps H" "Set cursor to position [`Ps`, `Ps`] (default = [1, 1])."
1076
+ * If ORIGIN mode is set, places the cursor to the absolute position within the scroll margins.
1077
+ * If ORIGIN mode is not set, places the cursor to the absolute position within the viewport.
1078
+ * Note that the coordinates are 1-based, thus the top left position starts at `1 ; 1`.
1079
+ */
1080
+ public cursorPosition(params: IParams): boolean {
1081
+ this._setCursor(
1082
+ // col
1083
+ (params.length >= 2) ? (params.params[1] || 1) - 1 : 0,
1084
+ // row
1085
+ (params.params[0] || 1) - 1
1086
+ );
1087
+ return true;
1088
+ }
1089
+
1090
+ /**
1091
+ * CSI Pm ` Character Position Absolute
1092
+ * [column] (default = [row,1]) (HPA).
1093
+ * Currently same functionality as CHA.
1094
+ *
1095
+ * @vt: #Y CSI HPA "Horizontal Position Absolute" "CSI Ps ` " "Same as CHA."
1096
+ */
1097
+ public charPosAbsolute(params: IParams): boolean {
1098
+ this._setCursor((params.params[0] || 1) - 1, this._activeBuffer.y);
1099
+ return true;
1100
+ }
1101
+
1102
+ /**
1103
+ * CSI Pm a Character Position Relative
1104
+ * [columns] (default = [row,col+1]) (HPR)
1105
+ *
1106
+ * @vt: #Y CSI HPR "Horizontal Position Relative" "CSI Ps a" "Same as CUF."
1107
+ */
1108
+ public hPositionRelative(params: IParams): boolean {
1109
+ this._moveCursor(params.params[0] || 1, 0);
1110
+ return true;
1111
+ }
1112
+
1113
+ /**
1114
+ * CSI Pm d Vertical Position Absolute (VPA)
1115
+ * [row] (default = [1,column])
1116
+ *
1117
+ * @vt: #Y CSI VPA "Vertical Position Absolute" "CSI Ps d" "Move cursor to `Ps`-th row (default=1)."
1118
+ */
1119
+ public linePosAbsolute(params: IParams): boolean {
1120
+ this._setCursor(this._activeBuffer.x, (params.params[0] || 1) - 1);
1121
+ return true;
1122
+ }
1123
+
1124
+ /**
1125
+ * CSI Pm e Vertical Position Relative (VPR)
1126
+ * [rows] (default = [row+1,column])
1127
+ * reuse CSI Ps B ?
1128
+ *
1129
+ * @vt: #Y CSI VPR "Vertical Position Relative" "CSI Ps e" "Move cursor `Ps` times down (default=1)."
1130
+ */
1131
+ public vPositionRelative(params: IParams): boolean {
1132
+ this._moveCursor(0, params.params[0] || 1);
1133
+ return true;
1134
+ }
1135
+
1136
+ /**
1137
+ * CSI Ps ; Ps f
1138
+ * Horizontal and Vertical Position [row;column] (default =
1139
+ * [1,1]) (HVP).
1140
+ * Same as CUP.
1141
+ *
1142
+ * @vt: #Y CSI HVP "Horizontal and Vertical Position" "CSI Ps ; Ps f" "Same as CUP."
1143
+ */
1144
+ public hVPosition(params: IParams): boolean {
1145
+ this.cursorPosition(params);
1146
+ return true;
1147
+ }
1148
+
1149
+ /**
1150
+ * CSI Ps g Tab Clear (TBC).
1151
+ * Ps = 0 -> Clear Current Column (default).
1152
+ * Ps = 3 -> Clear All.
1153
+ * Potentially:
1154
+ * Ps = 2 -> Clear Stops on Line.
1155
+ * http://vt100.net/annarbor/aaa-ug/section6.html
1156
+ *
1157
+ * @vt: #Y CSI TBC "Tab Clear" "CSI Ps g" "Clear tab stops at current position (0) or all (3) (default=0)."
1158
+ * Clearing tabstops off the active row (Ps = 2, VT100) is currently not supported.
1159
+ */
1160
+ public tabClear(params: IParams): boolean {
1161
+ const param = params.params[0];
1162
+ if (param === 0) {
1163
+ delete this._activeBuffer.tabs[this._activeBuffer.x];
1164
+ } else if (param === 3) {
1165
+ this._activeBuffer.tabs = {};
1166
+ }
1167
+ return true;
1168
+ }
1169
+
1170
+ /**
1171
+ * CSI Ps I
1172
+ * Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
1173
+ *
1174
+ * @vt: #Y CSI CHT "Cursor Horizontal Tabulation" "CSI Ps I" "Move cursor `Ps` times tabs forward (default=1)."
1175
+ */
1176
+ public cursorForwardTab(params: IParams): boolean {
1177
+ if (this._activeBuffer.x >= this._bufferService.cols) {
1178
+ return true;
1179
+ }
1180
+ let param = params.params[0] || 1;
1181
+ while (param--) {
1182
+ this._activeBuffer.x = this._activeBuffer.nextStop();
1183
+ }
1184
+ return true;
1185
+ }
1186
+
1187
+ /**
1188
+ * CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
1189
+ *
1190
+ * @vt: #Y CSI CBT "Cursor Backward Tabulation" "CSI Ps Z" "Move cursor `Ps` tabs backward (default=1)."
1191
+ */
1192
+ public cursorBackwardTab(params: IParams): boolean {
1193
+ if (this._activeBuffer.x >= this._bufferService.cols) {
1194
+ return true;
1195
+ }
1196
+ let param = params.params[0] || 1;
1197
+
1198
+ while (param--) {
1199
+ this._activeBuffer.x = this._activeBuffer.prevStop();
1200
+ }
1201
+ return true;
1202
+ }
1203
+
1204
+
1205
+ /**
1206
+ * Helper method to erase cells in a terminal row.
1207
+ * The cell gets replaced with the eraseChar of the terminal.
1208
+ * @param y row index
1209
+ * @param start first cell index to be erased
1210
+ * @param end end - 1 is last erased cell
1211
+ * @param cleanWrap clear the isWrapped flag
1212
+ */
1213
+ private _eraseInBufferLine(y: number, start: number, end: number, clearWrap: boolean = false): void {
1214
+ const line = this._activeBuffer.lines.get(this._activeBuffer.ybase + y)!;
1215
+ line.replaceCells(
1216
+ start,
1217
+ end,
1218
+ this._activeBuffer.getNullCell(this._eraseAttrData()),
1219
+ this._eraseAttrData()
1220
+ );
1221
+ if (clearWrap) {
1222
+ line.isWrapped = false;
1223
+ }
1224
+ }
1225
+
1226
+ /**
1227
+ * Helper method to reset cells in a terminal row.
1228
+ * The cell gets replaced with the eraseChar of the terminal and the isWrapped property is set to false.
1229
+ * @param y row index
1230
+ */
1231
+ private _resetBufferLine(y: number): void {
1232
+ const line = this._activeBuffer.lines.get(this._activeBuffer.ybase + y)!;
1233
+ line.fill(this._activeBuffer.getNullCell(this._eraseAttrData()));
1234
+ this._bufferService.buffer.clearMarkers(this._activeBuffer.ybase + y);
1235
+ line.isWrapped = false;
1236
+ }
1237
+
1238
+ /**
1239
+ * CSI Ps J Erase in Display (ED).
1240
+ * Ps = 0 -> Erase Below (default).
1241
+ * Ps = 1 -> Erase Above.
1242
+ * Ps = 2 -> Erase All.
1243
+ * Ps = 3 -> Erase Saved Lines (xterm).
1244
+ * CSI ? Ps J
1245
+ * Erase in Display (DECSED).
1246
+ * Ps = 0 -> Selective Erase Below (default).
1247
+ * Ps = 1 -> Selective Erase Above.
1248
+ * Ps = 2 -> Selective Erase All.
1249
+ *
1250
+ * @vt: #Y CSI ED "Erase In Display" "CSI Ps J" "Erase various parts of the viewport."
1251
+ * Supported param values:
1252
+ *
1253
+ * | Ps | Effect |
1254
+ * | -- | ------------------------------------------------------------ |
1255
+ * | 0 | Erase from the cursor through the end of the viewport. |
1256
+ * | 1 | Erase from the beginning of the viewport through the cursor. |
1257
+ * | 2 | Erase complete viewport. |
1258
+ * | 3 | Erase scrollback. |
1259
+ *
1260
+ * @vt: #P[Protection attributes are not supported.] CSI DECSED "Selective Erase In Display" "CSI ? Ps J" "Currently the same as ED."
1261
+ */
1262
+ public eraseInDisplay(params: IParams): boolean {
1263
+ this._restrictCursor(this._bufferService.cols);
1264
+ let j;
1265
+ switch (params.params[0]) {
1266
+ case 0:
1267
+ j = this._activeBuffer.y;
1268
+ this._dirtyRowService.markDirty(j);
1269
+ this._eraseInBufferLine(j++, this._activeBuffer.x, this._bufferService.cols, this._activeBuffer.x === 0);
1270
+ for (; j < this._bufferService.rows; j++) {
1271
+ this._resetBufferLine(j);
1272
+ }
1273
+ this._dirtyRowService.markDirty(j);
1274
+ break;
1275
+ case 1:
1276
+ j = this._activeBuffer.y;
1277
+ this._dirtyRowService.markDirty(j);
1278
+ // Deleted front part of line and everything before. This line will no longer be wrapped.
1279
+ this._eraseInBufferLine(j, 0, this._activeBuffer.x + 1, true);
1280
+ if (this._activeBuffer.x + 1 >= this._bufferService.cols) {
1281
+ // Deleted entire previous line. This next line can no longer be wrapped.
1282
+ this._activeBuffer.lines.get(j + 1)!.isWrapped = false;
1283
+ }
1284
+ while (j--) {
1285
+ this._resetBufferLine(j);
1286
+ }
1287
+ this._dirtyRowService.markDirty(0);
1288
+ break;
1289
+ case 2:
1290
+ j = this._bufferService.rows;
1291
+ this._dirtyRowService.markDirty(j - 1);
1292
+ while (j--) {
1293
+ this._resetBufferLine(j);
1294
+ }
1295
+ this._dirtyRowService.markDirty(0);
1296
+ break;
1297
+ case 3:
1298
+ // Clear scrollback (everything not in viewport)
1299
+ const scrollBackSize = this._activeBuffer.lines.length - this._bufferService.rows;
1300
+ if (scrollBackSize > 0) {
1301
+ this._activeBuffer.lines.trimStart(scrollBackSize);
1302
+ this._activeBuffer.ybase = Math.max(this._activeBuffer.ybase - scrollBackSize, 0);
1303
+ this._activeBuffer.ydisp = Math.max(this._activeBuffer.ydisp - scrollBackSize, 0);
1304
+ // Force a scroll event to refresh viewport
1305
+ this._onScroll.fire(0);
1306
+ }
1307
+ break;
1308
+ }
1309
+ return true;
1310
+ }
1311
+
1312
+ /**
1313
+ * CSI Ps K Erase in Line (EL).
1314
+ * Ps = 0 -> Erase to Right (default).
1315
+ * Ps = 1 -> Erase to Left.
1316
+ * Ps = 2 -> Erase All.
1317
+ * CSI ? Ps K
1318
+ * Erase in Line (DECSEL).
1319
+ * Ps = 0 -> Selective Erase to Right (default).
1320
+ * Ps = 1 -> Selective Erase to Left.
1321
+ * Ps = 2 -> Selective Erase All.
1322
+ *
1323
+ * @vt: #Y CSI EL "Erase In Line" "CSI Ps K" "Erase various parts of the active row."
1324
+ * Supported param values:
1325
+ *
1326
+ * | Ps | Effect |
1327
+ * | -- | -------------------------------------------------------- |
1328
+ * | 0 | Erase from the cursor through the end of the row. |
1329
+ * | 1 | Erase from the beginning of the line through the cursor. |
1330
+ * | 2 | Erase complete line. |
1331
+ *
1332
+ * @vt: #P[Protection attributes are not supported.] CSI DECSEL "Selective Erase In Line" "CSI ? Ps K" "Currently the same as EL."
1333
+ */
1334
+ public eraseInLine(params: IParams): boolean {
1335
+ this._restrictCursor(this._bufferService.cols);
1336
+ switch (params.params[0]) {
1337
+ case 0:
1338
+ this._eraseInBufferLine(this._activeBuffer.y, this._activeBuffer.x, this._bufferService.cols, this._activeBuffer.x === 0);
1339
+ break;
1340
+ case 1:
1341
+ this._eraseInBufferLine(this._activeBuffer.y, 0, this._activeBuffer.x + 1, false);
1342
+ break;
1343
+ case 2:
1344
+ this._eraseInBufferLine(this._activeBuffer.y, 0, this._bufferService.cols, true);
1345
+ break;
1346
+ }
1347
+ this._dirtyRowService.markDirty(this._activeBuffer.y);
1348
+ return true;
1349
+ }
1350
+
1351
+ /**
1352
+ * CSI Ps L
1353
+ * Insert Ps Line(s) (default = 1) (IL).
1354
+ *
1355
+ * @vt: #Y CSI IL "Insert Line" "CSI Ps L" "Insert `Ps` blank lines at active row (default=1)."
1356
+ * For every inserted line at the scroll top one line at the scroll bottom gets removed.
1357
+ * The cursor is set to the first column.
1358
+ * IL has no effect if the cursor is outside the scroll margins.
1359
+ */
1360
+ public insertLines(params: IParams): boolean {
1361
+ this._restrictCursor();
1362
+ let param = params.params[0] || 1;
1363
+
1364
+ if (this._activeBuffer.y > this._activeBuffer.scrollBottom || this._activeBuffer.y < this._activeBuffer.scrollTop) {
1365
+ return true;
1366
+ }
1367
+
1368
+ const row: number = this._activeBuffer.ybase + this._activeBuffer.y;
1369
+
1370
+ const scrollBottomRowsOffset = this._bufferService.rows - 1 - this._activeBuffer.scrollBottom;
1371
+ const scrollBottomAbsolute = this._bufferService.rows - 1 + this._activeBuffer.ybase - scrollBottomRowsOffset + 1;
1372
+ while (param--) {
1373
+ // test: echo -e '\e[44m\e[1L\e[0m'
1374
+ // blankLine(true) - xterm/linux behavior
1375
+ this._activeBuffer.lines.splice(scrollBottomAbsolute - 1, 1);
1376
+ this._activeBuffer.lines.splice(row, 0, this._activeBuffer.getBlankLine(this._eraseAttrData()));
1377
+ }
1378
+
1379
+ this._dirtyRowService.markRangeDirty(this._activeBuffer.y, this._activeBuffer.scrollBottom);
1380
+ this._activeBuffer.x = 0; // see https://vt100.net/docs/vt220-rm/chapter4.html - vt220 only?
1381
+ return true;
1382
+ }
1383
+
1384
+ /**
1385
+ * CSI Ps M
1386
+ * Delete Ps Line(s) (default = 1) (DL).
1387
+ *
1388
+ * @vt: #Y CSI DL "Delete Line" "CSI Ps M" "Delete `Ps` lines at active row (default=1)."
1389
+ * For every deleted line at the scroll top one blank line at the scroll bottom gets appended.
1390
+ * The cursor is set to the first column.
1391
+ * DL has no effect if the cursor is outside the scroll margins.
1392
+ */
1393
+ public deleteLines(params: IParams): boolean {
1394
+ this._restrictCursor();
1395
+ let param = params.params[0] || 1;
1396
+
1397
+ if (this._activeBuffer.y > this._activeBuffer.scrollBottom || this._activeBuffer.y < this._activeBuffer.scrollTop) {
1398
+ return true;
1399
+ }
1400
+
1401
+ const row: number = this._activeBuffer.ybase + this._activeBuffer.y;
1402
+
1403
+ let j: number;
1404
+ j = this._bufferService.rows - 1 - this._activeBuffer.scrollBottom;
1405
+ j = this._bufferService.rows - 1 + this._activeBuffer.ybase - j;
1406
+ while (param--) {
1407
+ // test: echo -e '\e[44m\e[1M\e[0m'
1408
+ // blankLine(true) - xterm/linux behavior
1409
+ this._activeBuffer.lines.splice(row, 1);
1410
+ this._activeBuffer.lines.splice(j, 0, this._activeBuffer.getBlankLine(this._eraseAttrData()));
1411
+ }
1412
+
1413
+ this._dirtyRowService.markRangeDirty(this._activeBuffer.y, this._activeBuffer.scrollBottom);
1414
+ this._activeBuffer.x = 0; // see https://vt100.net/docs/vt220-rm/chapter4.html - vt220 only?
1415
+ return true;
1416
+ }
1417
+
1418
+ /**
1419
+ * CSI Ps @
1420
+ * Insert Ps (Blank) Character(s) (default = 1) (ICH).
1421
+ *
1422
+ * @vt: #Y CSI ICH "Insert Characters" "CSI Ps @" "Insert `Ps` (blank) characters (default = 1)."
1423
+ * The ICH sequence inserts `Ps` blank characters. The cursor remains at the beginning of the blank characters.
1424
+ * Text between the cursor and right margin moves to the right. Characters moved past the right margin are lost.
1425
+ *
1426
+ *
1427
+ * FIXME: check against xterm - should not work outside of scroll margins (see VT520 manual)
1428
+ */
1429
+ public insertChars(params: IParams): boolean {
1430
+ this._restrictCursor();
1431
+ const line = this._activeBuffer.lines.get(this._activeBuffer.ybase + this._activeBuffer.y);
1432
+ if (line) {
1433
+ line.insertCells(
1434
+ this._activeBuffer.x,
1435
+ params.params[0] || 1,
1436
+ this._activeBuffer.getNullCell(this._eraseAttrData()),
1437
+ this._eraseAttrData()
1438
+ );
1439
+ this._dirtyRowService.markDirty(this._activeBuffer.y);
1440
+ }
1441
+ return true;
1442
+ }
1443
+
1444
+ /**
1445
+ * CSI Ps P
1446
+ * Delete Ps Character(s) (default = 1) (DCH).
1447
+ *
1448
+ * @vt: #Y CSI DCH "Delete Character" "CSI Ps P" "Delete `Ps` characters (default=1)."
1449
+ * As characters are deleted, the remaining characters between the cursor and right margin move to the left.
1450
+ * Character attributes move with the characters. The terminal adds blank characters at the right margin.
1451
+ *
1452
+ *
1453
+ * FIXME: check against xterm - should not work outside of scroll margins (see VT520 manual)
1454
+ */
1455
+ public deleteChars(params: IParams): boolean {
1456
+ this._restrictCursor();
1457
+ const line = this._activeBuffer.lines.get(this._activeBuffer.ybase + this._activeBuffer.y);
1458
+ if (line) {
1459
+ line.deleteCells(
1460
+ this._activeBuffer.x,
1461
+ params.params[0] || 1,
1462
+ this._activeBuffer.getNullCell(this._eraseAttrData()),
1463
+ this._eraseAttrData()
1464
+ );
1465
+ this._dirtyRowService.markDirty(this._activeBuffer.y);
1466
+ }
1467
+ return true;
1468
+ }
1469
+
1470
+ /**
1471
+ * CSI Ps S Scroll up Ps lines (default = 1) (SU).
1472
+ *
1473
+ * @vt: #Y CSI SU "Scroll Up" "CSI Ps S" "Scroll `Ps` lines up (default=1)."
1474
+ *
1475
+ *
1476
+ * FIXME: scrolled out lines at top = 1 should add to scrollback (xterm)
1477
+ */
1478
+ public scrollUp(params: IParams): boolean {
1479
+ let param = params.params[0] || 1;
1480
+
1481
+ while (param--) {
1482
+ this._activeBuffer.lines.splice(this._activeBuffer.ybase + this._activeBuffer.scrollTop, 1);
1483
+ this._activeBuffer.lines.splice(this._activeBuffer.ybase + this._activeBuffer.scrollBottom, 0, this._activeBuffer.getBlankLine(this._eraseAttrData()));
1484
+ }
1485
+ this._dirtyRowService.markRangeDirty(this._activeBuffer.scrollTop, this._activeBuffer.scrollBottom);
1486
+ return true;
1487
+ }
1488
+
1489
+ /**
1490
+ * CSI Ps T Scroll down Ps lines (default = 1) (SD).
1491
+ *
1492
+ * @vt: #Y CSI SD "Scroll Down" "CSI Ps T" "Scroll `Ps` lines down (default=1)."
1493
+ */
1494
+ public scrollDown(params: IParams): boolean {
1495
+ let param = params.params[0] || 1;
1496
+
1497
+ while (param--) {
1498
+ this._activeBuffer.lines.splice(this._activeBuffer.ybase + this._activeBuffer.scrollBottom, 1);
1499
+ this._activeBuffer.lines.splice(this._activeBuffer.ybase + this._activeBuffer.scrollTop, 0, this._activeBuffer.getBlankLine(DEFAULT_ATTR_DATA));
1500
+ }
1501
+ this._dirtyRowService.markRangeDirty(this._activeBuffer.scrollTop, this._activeBuffer.scrollBottom);
1502
+ return true;
1503
+ }
1504
+
1505
+ /**
1506
+ * CSI Ps SP @ Scroll left Ps columns (default = 1) (SL) ECMA-48
1507
+ *
1508
+ * Notation: (Pn)
1509
+ * Representation: CSI Pn 02/00 04/00
1510
+ * Parameter default value: Pn = 1
1511
+ * SL causes the data in the presentation component to be moved by n character positions
1512
+ * if the line orientation is horizontal, or by n line positions if the line orientation
1513
+ * is vertical, such that the data appear to move to the left; where n equals the value of Pn.
1514
+ * The active presentation position is not affected by this control function.
1515
+ *
1516
+ * Supported:
1517
+ * - always left shift (no line orientation setting respected)
1518
+ *
1519
+ * @vt: #Y CSI SL "Scroll Left" "CSI Ps SP @" "Scroll viewport `Ps` times to the left."
1520
+ * SL moves the content of all lines within the scroll margins `Ps` times to the left.
1521
+ * SL has no effect outside of the scroll margins.
1522
+ */
1523
+ public scrollLeft(params: IParams): boolean {
1524
+ if (this._activeBuffer.y > this._activeBuffer.scrollBottom || this._activeBuffer.y < this._activeBuffer.scrollTop) {
1525
+ return true;
1526
+ }
1527
+ const param = params.params[0] || 1;
1528
+ for (let y = this._activeBuffer.scrollTop; y <= this._activeBuffer.scrollBottom; ++y) {
1529
+ const line = this._activeBuffer.lines.get(this._activeBuffer.ybase + y)!;
1530
+ line.deleteCells(0, param, this._activeBuffer.getNullCell(this._eraseAttrData()), this._eraseAttrData());
1531
+ line.isWrapped = false;
1532
+ }
1533
+ this._dirtyRowService.markRangeDirty(this._activeBuffer.scrollTop, this._activeBuffer.scrollBottom);
1534
+ return true;
1535
+ }
1536
+
1537
+ /**
1538
+ * CSI Ps SP A Scroll right Ps columns (default = 1) (SR) ECMA-48
1539
+ *
1540
+ * Notation: (Pn)
1541
+ * Representation: CSI Pn 02/00 04/01
1542
+ * Parameter default value: Pn = 1
1543
+ * SR causes the data in the presentation component to be moved by n character positions
1544
+ * if the line orientation is horizontal, or by n line positions if the line orientation
1545
+ * is vertical, such that the data appear to move to the right; where n equals the value of Pn.
1546
+ * The active presentation position is not affected by this control function.
1547
+ *
1548
+ * Supported:
1549
+ * - always right shift (no line orientation setting respected)
1550
+ *
1551
+ * @vt: #Y CSI SR "Scroll Right" "CSI Ps SP A" "Scroll viewport `Ps` times to the right."
1552
+ * SL moves the content of all lines within the scroll margins `Ps` times to the right.
1553
+ * Content at the right margin is lost.
1554
+ * SL has no effect outside of the scroll margins.
1555
+ */
1556
+ public scrollRight(params: IParams): boolean {
1557
+ if (this._activeBuffer.y > this._activeBuffer.scrollBottom || this._activeBuffer.y < this._activeBuffer.scrollTop) {
1558
+ return true;
1559
+ }
1560
+ const param = params.params[0] || 1;
1561
+ for (let y = this._activeBuffer.scrollTop; y <= this._activeBuffer.scrollBottom; ++y) {
1562
+ const line = this._activeBuffer.lines.get(this._activeBuffer.ybase + y)!;
1563
+ line.insertCells(0, param, this._activeBuffer.getNullCell(this._eraseAttrData()), this._eraseAttrData());
1564
+ line.isWrapped = false;
1565
+ }
1566
+ this._dirtyRowService.markRangeDirty(this._activeBuffer.scrollTop, this._activeBuffer.scrollBottom);
1567
+ return true;
1568
+ }
1569
+
1570
+ /**
1571
+ * CSI Pm ' }
1572
+ * Insert Ps Column(s) (default = 1) (DECIC), VT420 and up.
1573
+ *
1574
+ * @vt: #Y CSI DECIC "Insert Columns" "CSI Ps ' }" "Insert `Ps` columns at cursor position."
1575
+ * DECIC inserts `Ps` times blank columns at the cursor position for all lines with the scroll margins,
1576
+ * moving content to the right. Content at the right margin is lost.
1577
+ * DECIC has no effect outside the scrolling margins.
1578
+ */
1579
+ public insertColumns(params: IParams): boolean {
1580
+ if (this._activeBuffer.y > this._activeBuffer.scrollBottom || this._activeBuffer.y < this._activeBuffer.scrollTop) {
1581
+ return true;
1582
+ }
1583
+ const param = params.params[0] || 1;
1584
+ for (let y = this._activeBuffer.scrollTop; y <= this._activeBuffer.scrollBottom; ++y) {
1585
+ const line = this._activeBuffer.lines.get(this._activeBuffer.ybase + y)!;
1586
+ line.insertCells(this._activeBuffer.x, param, this._activeBuffer.getNullCell(this._eraseAttrData()), this._eraseAttrData());
1587
+ line.isWrapped = false;
1588
+ }
1589
+ this._dirtyRowService.markRangeDirty(this._activeBuffer.scrollTop, this._activeBuffer.scrollBottom);
1590
+ return true;
1591
+ }
1592
+
1593
+ /**
1594
+ * CSI Pm ' ~
1595
+ * Delete Ps Column(s) (default = 1) (DECDC), VT420 and up.
1596
+ *
1597
+ * @vt: #Y CSI DECDC "Delete Columns" "CSI Ps ' ~" "Delete `Ps` columns at cursor position."
1598
+ * DECDC deletes `Ps` times columns at the cursor position for all lines with the scroll margins,
1599
+ * moving content to the left. Blank columns are added at the right margin.
1600
+ * DECDC has no effect outside the scrolling margins.
1601
+ */
1602
+ public deleteColumns(params: IParams): boolean {
1603
+ if (this._activeBuffer.y > this._activeBuffer.scrollBottom || this._activeBuffer.y < this._activeBuffer.scrollTop) {
1604
+ return true;
1605
+ }
1606
+ const param = params.params[0] || 1;
1607
+ for (let y = this._activeBuffer.scrollTop; y <= this._activeBuffer.scrollBottom; ++y) {
1608
+ const line = this._activeBuffer.lines.get(this._activeBuffer.ybase + y)!;
1609
+ line.deleteCells(this._activeBuffer.x, param, this._activeBuffer.getNullCell(this._eraseAttrData()), this._eraseAttrData());
1610
+ line.isWrapped = false;
1611
+ }
1612
+ this._dirtyRowService.markRangeDirty(this._activeBuffer.scrollTop, this._activeBuffer.scrollBottom);
1613
+ return true;
1614
+ }
1615
+
1616
+ /**
1617
+ * CSI Ps X
1618
+ * Erase Ps Character(s) (default = 1) (ECH).
1619
+ *
1620
+ * @vt: #Y CSI ECH "Erase Character" "CSI Ps X" "Erase `Ps` characters from current cursor position to the right (default=1)."
1621
+ * ED erases `Ps` characters from current cursor position to the right.
1622
+ * ED works inside or outside the scrolling margins.
1623
+ */
1624
+ public eraseChars(params: IParams): boolean {
1625
+ this._restrictCursor();
1626
+ const line = this._activeBuffer.lines.get(this._activeBuffer.ybase + this._activeBuffer.y);
1627
+ if (line) {
1628
+ line.replaceCells(
1629
+ this._activeBuffer.x,
1630
+ this._activeBuffer.x + (params.params[0] || 1),
1631
+ this._activeBuffer.getNullCell(this._eraseAttrData()),
1632
+ this._eraseAttrData()
1633
+ );
1634
+ this._dirtyRowService.markDirty(this._activeBuffer.y);
1635
+ }
1636
+ return true;
1637
+ }
1638
+
1639
+ /**
1640
+ * CSI Ps b Repeat the preceding graphic character Ps times (REP).
1641
+ * From ECMA 48 (@see http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf)
1642
+ * Notation: (Pn)
1643
+ * Representation: CSI Pn 06/02
1644
+ * Parameter default value: Pn = 1
1645
+ * REP is used to indicate that the preceding character in the data stream,
1646
+ * if it is a graphic character (represented by one or more bit combinations) including SPACE,
1647
+ * is to be repeated n times, where n equals the value of Pn.
1648
+ * If the character preceding REP is a control function or part of a control function,
1649
+ * the effect of REP is not defined by this Standard.
1650
+ *
1651
+ * Since we propagate the terminal as xterm-256color we have to follow xterm's behavior:
1652
+ * - fullwidth + surrogate chars are ignored
1653
+ * - for combining chars only the base char gets repeated
1654
+ * - text attrs are applied normally
1655
+ * - wrap around is respected
1656
+ * - any valid sequence resets the carried forward char
1657
+ *
1658
+ * Note: To get reset on a valid sequence working correctly without much runtime penalty,
1659
+ * the preceding codepoint is stored on the parser in `this.print` and reset during `parser.parse`.
1660
+ *
1661
+ * @vt: #Y CSI REP "Repeat Preceding Character" "CSI Ps b" "Repeat preceding character `Ps` times (default=1)."
1662
+ * REP repeats the previous character `Ps` times advancing the cursor, also wrapping if DECAWM is set.
1663
+ * REP has no effect if the sequence does not follow a printable ASCII character
1664
+ * (NOOP for any other sequence in between or NON ASCII characters).
1665
+ */
1666
+ public repeatPrecedingCharacter(params: IParams): boolean {
1667
+ if (!this._parser.precedingCodepoint) {
1668
+ return true;
1669
+ }
1670
+ // call print to insert the chars and handle correct wrapping
1671
+ const length = params.params[0] || 1;
1672
+ const data = new Uint32Array(length);
1673
+ for (let i = 0; i < length; ++i) {
1674
+ data[i] = this._parser.precedingCodepoint;
1675
+ }
1676
+ this.print(data, 0, data.length);
1677
+ return true;
1678
+ }
1679
+
1680
+ /**
1681
+ * CSI Ps c Send Device Attributes (Primary DA).
1682
+ * Ps = 0 or omitted -> request attributes from terminal. The
1683
+ * response depends on the decTerminalID resource setting.
1684
+ * -> CSI ? 1 ; 2 c (``VT100 with Advanced Video Option'')
1685
+ * -> CSI ? 1 ; 0 c (``VT101 with No Options'')
1686
+ * -> CSI ? 6 c (``VT102'')
1687
+ * -> CSI ? 6 0 ; 1 ; 2 ; 6 ; 8 ; 9 ; 1 5 ; c (``VT220'')
1688
+ * The VT100-style response parameters do not mean anything by
1689
+ * themselves. VT220 parameters do, telling the host what fea-
1690
+ * tures the terminal supports:
1691
+ * Ps = 1 -> 132-columns.
1692
+ * Ps = 2 -> Printer.
1693
+ * Ps = 6 -> Selective erase.
1694
+ * Ps = 8 -> User-defined keys.
1695
+ * Ps = 9 -> National replacement character sets.
1696
+ * Ps = 1 5 -> Technical characters.
1697
+ * Ps = 2 2 -> ANSI color, e.g., VT525.
1698
+ * Ps = 2 9 -> ANSI text locator (i.e., DEC Locator mode).
1699
+ *
1700
+ * @vt: #Y CSI DA1 "Primary Device Attributes" "CSI c" "Send primary device attributes."
1701
+ *
1702
+ *
1703
+ * TODO: fix and cleanup response
1704
+ */
1705
+ public sendDeviceAttributesPrimary(params: IParams): boolean {
1706
+ if (params.params[0] > 0) {
1707
+ return true;
1708
+ }
1709
+ if (this._is('xterm') || this._is('rxvt-unicode') || this._is('screen')) {
1710
+ this._coreService.triggerDataEvent(C0.ESC + '[?1;2c');
1711
+ } else if (this._is('linux')) {
1712
+ this._coreService.triggerDataEvent(C0.ESC + '[?6c');
1713
+ }
1714
+ return true;
1715
+ }
1716
+
1717
+ /**
1718
+ * CSI > Ps c
1719
+ * Send Device Attributes (Secondary DA).
1720
+ * Ps = 0 or omitted -> request the terminal's identification
1721
+ * code. The response depends on the decTerminalID resource set-
1722
+ * ting. It should apply only to VT220 and up, but xterm extends
1723
+ * this to VT100.
1724
+ * -> CSI > Pp ; Pv ; Pc c
1725
+ * where Pp denotes the terminal type
1726
+ * Pp = 0 -> ``VT100''.
1727
+ * Pp = 1 -> ``VT220''.
1728
+ * and Pv is the firmware version (for xterm, this was originally
1729
+ * the XFree86 patch number, starting with 95). In a DEC termi-
1730
+ * nal, Pc indicates the ROM cartridge registration number and is
1731
+ * always zero.
1732
+ * More information:
1733
+ * xterm/charproc.c - line 2012, for more information.
1734
+ * vim responds with ^[[?0c or ^[[?1c after the terminal's response (?)
1735
+ *
1736
+ * @vt: #Y CSI DA2 "Secondary Device Attributes" "CSI > c" "Send primary device attributes."
1737
+ *
1738
+ *
1739
+ * TODO: fix and cleanup response
1740
+ */
1741
+ public sendDeviceAttributesSecondary(params: IParams): boolean {
1742
+ if (params.params[0] > 0) {
1743
+ return true;
1744
+ }
1745
+ // xterm and urxvt
1746
+ // seem to spit this
1747
+ // out around ~370 times (?).
1748
+ if (this._is('xterm')) {
1749
+ this._coreService.triggerDataEvent(C0.ESC + '[>0;276;0c');
1750
+ } else if (this._is('rxvt-unicode')) {
1751
+ this._coreService.triggerDataEvent(C0.ESC + '[>85;95;0c');
1752
+ } else if (this._is('linux')) {
1753
+ // not supported by linux console.
1754
+ // linux console echoes parameters.
1755
+ this._coreService.triggerDataEvent(params.params[0] + 'c');
1756
+ } else if (this._is('screen')) {
1757
+ this._coreService.triggerDataEvent(C0.ESC + '[>83;40003;0c');
1758
+ }
1759
+ return true;
1760
+ }
1761
+
1762
+ /**
1763
+ * Evaluate if the current terminal is the given argument.
1764
+ * @param term The terminal name to evaluate
1765
+ */
1766
+ private _is(term: string): boolean {
1767
+ return (this._optionsService.rawOptions.termName + '').indexOf(term) === 0;
1768
+ }
1769
+
1770
+ /**
1771
+ * CSI Pm h Set Mode (SM).
1772
+ * Ps = 2 -> Keyboard Action Mode (AM).
1773
+ * Ps = 4 -> Insert Mode (IRM).
1774
+ * Ps = 1 2 -> Send/receive (SRM).
1775
+ * Ps = 2 0 -> Automatic Newline (LNM).
1776
+ *
1777
+ * @vt: #P[Only IRM is supported.] CSI SM "Set Mode" "CSI Pm h" "Set various terminal modes."
1778
+ * Supported param values by SM:
1779
+ *
1780
+ * | Param | Action | Support |
1781
+ * | ----- | -------------------------------------- | ------- |
1782
+ * | 2 | Keyboard Action Mode (KAM). Always on. | #N |
1783
+ * | 4 | Insert Mode (IRM). | #Y |
1784
+ * | 12 | Send/receive (SRM). Always off. | #N |
1785
+ * | 20 | Automatic Newline (LNM). Always off. | #N |
1786
+ */
1787
+ public setMode(params: IParams): boolean {
1788
+ for (let i = 0; i < params.length; i++) {
1789
+ switch (params.params[i]) {
1790
+ case 4:
1791
+ this._coreService.modes.insertMode = true;
1792
+ break;
1793
+ case 20:
1794
+ // this._t.convertEol = true;
1795
+ break;
1796
+ }
1797
+ }
1798
+ return true;
1799
+ }
1800
+
1801
+ /**
1802
+ * CSI ? Pm h
1803
+ * DEC Private Mode Set (DECSET).
1804
+ * Ps = 1 -> Application Cursor Keys (DECCKM).
1805
+ * Ps = 2 -> Designate USASCII for character sets G0-G3
1806
+ * (DECANM), and set VT100 mode.
1807
+ * Ps = 3 -> 132 Column Mode (DECCOLM).
1808
+ * Ps = 4 -> Smooth (Slow) Scroll (DECSCLM).
1809
+ * Ps = 5 -> Reverse Video (DECSCNM).
1810
+ * Ps = 6 -> Origin Mode (DECOM).
1811
+ * Ps = 7 -> Wraparound Mode (DECAWM).
1812
+ * Ps = 8 -> Auto-repeat Keys (DECARM).
1813
+ * Ps = 9 -> Send Mouse X & Y on button press. See the sec-
1814
+ * tion Mouse Tracking.
1815
+ * Ps = 1 0 -> Show toolbar (rxvt).
1816
+ * Ps = 1 2 -> Start Blinking Cursor (att610).
1817
+ * Ps = 1 8 -> Print form feed (DECPFF).
1818
+ * Ps = 1 9 -> Set print extent to full screen (DECPEX).
1819
+ * Ps = 2 5 -> Show Cursor (DECTCEM).
1820
+ * Ps = 3 0 -> Show scrollbar (rxvt).
1821
+ * Ps = 3 5 -> Enable font-shifting functions (rxvt).
1822
+ * Ps = 3 8 -> Enter Tektronix Mode (DECTEK).
1823
+ * Ps = 4 0 -> Allow 80 -> 132 Mode.
1824
+ * Ps = 4 1 -> more(1) fix (see curses resource).
1825
+ * Ps = 4 2 -> Enable Nation Replacement Character sets (DECN-
1826
+ * RCM).
1827
+ * Ps = 4 4 -> Turn On Margin Bell.
1828
+ * Ps = 4 5 -> Reverse-wraparound Mode.
1829
+ * Ps = 4 6 -> Start Logging. This is normally disabled by a
1830
+ * compile-time option.
1831
+ * Ps = 4 7 -> Use Alternate Screen Buffer. (This may be dis-
1832
+ * abled by the titeInhibit resource).
1833
+ * Ps = 6 6 -> Application keypad (DECNKM).
1834
+ * Ps = 6 7 -> Backarrow key sends backspace (DECBKM).
1835
+ * Ps = 1 0 0 0 -> Send Mouse X & Y on button press and
1836
+ * release. See the section Mouse Tracking.
1837
+ * Ps = 1 0 0 1 -> Use Hilite Mouse Tracking.
1838
+ * Ps = 1 0 0 2 -> Use Cell Motion Mouse Tracking.
1839
+ * Ps = 1 0 0 3 -> Use All Motion Mouse Tracking.
1840
+ * Ps = 1 0 0 4 -> Send FocusIn/FocusOut events.
1841
+ * Ps = 1 0 0 5 -> Enable Extended Mouse Mode.
1842
+ * Ps = 1 0 1 0 -> Scroll to bottom on tty output (rxvt).
1843
+ * Ps = 1 0 1 1 -> Scroll to bottom on key press (rxvt).
1844
+ * Ps = 1 0 3 4 -> Interpret "meta" key, sets eighth bit.
1845
+ * (enables the eightBitInput resource).
1846
+ * Ps = 1 0 3 5 -> Enable special modifiers for Alt and Num-
1847
+ * Lock keys. (This enables the numLock resource).
1848
+ * Ps = 1 0 3 6 -> Send ESC when Meta modifies a key. (This
1849
+ * enables the metaSendsEscape resource).
1850
+ * Ps = 1 0 3 7 -> Send DEL from the editing-keypad Delete
1851
+ * key.
1852
+ * Ps = 1 0 3 9 -> Send ESC when Alt modifies a key. (This
1853
+ * enables the altSendsEscape resource).
1854
+ * Ps = 1 0 4 0 -> Keep selection even if not highlighted.
1855
+ * (This enables the keepSelection resource).
1856
+ * Ps = 1 0 4 1 -> Use the CLIPBOARD selection. (This enables
1857
+ * the selectToClipboard resource).
1858
+ * Ps = 1 0 4 2 -> Enable Urgency window manager hint when
1859
+ * Control-G is received. (This enables the bellIsUrgent
1860
+ * resource).
1861
+ * Ps = 1 0 4 3 -> Enable raising of the window when Control-G
1862
+ * is received. (enables the popOnBell resource).
1863
+ * Ps = 1 0 4 7 -> Use Alternate Screen Buffer. (This may be
1864
+ * disabled by the titeInhibit resource).
1865
+ * Ps = 1 0 4 8 -> Save cursor as in DECSC. (This may be dis-
1866
+ * abled by the titeInhibit resource).
1867
+ * Ps = 1 0 4 9 -> Save cursor as in DECSC and use Alternate
1868
+ * Screen Buffer, clearing it first. (This may be disabled by
1869
+ * the titeInhibit resource). This combines the effects of the 1
1870
+ * 0 4 7 and 1 0 4 8 modes. Use this with terminfo-based
1871
+ * applications rather than the 4 7 mode.
1872
+ * Ps = 1 0 5 0 -> Set terminfo/termcap function-key mode.
1873
+ * Ps = 1 0 5 1 -> Set Sun function-key mode.
1874
+ * Ps = 1 0 5 2 -> Set HP function-key mode.
1875
+ * Ps = 1 0 5 3 -> Set SCO function-key mode.
1876
+ * Ps = 1 0 6 0 -> Set legacy keyboard emulation (X11R6).
1877
+ * Ps = 1 0 6 1 -> Set VT220 keyboard emulation.
1878
+ * Ps = 2 0 0 4 -> Set bracketed paste mode.
1879
+ * Modes:
1880
+ * http: *vt100.net/docs/vt220-rm/chapter4.html
1881
+ *
1882
+ * @vt: #P[See below for supported modes.] CSI DECSET "DEC Private Set Mode" "CSI ? Pm h" "Set various terminal attributes."
1883
+ * Supported param values by DECSET:
1884
+ *
1885
+ * | param | Action | Support |
1886
+ * | ----- | ------------------------------------------------------- | --------|
1887
+ * | 1 | Application Cursor Keys (DECCKM). | #Y |
1888
+ * | 2 | Designate US-ASCII for character sets G0-G3 (DECANM). | #Y |
1889
+ * | 3 | 132 Column Mode (DECCOLM). | #Y |
1890
+ * | 6 | Origin Mode (DECOM). | #Y |
1891
+ * | 7 | Auto-wrap Mode (DECAWM). | #Y |
1892
+ * | 8 | Auto-repeat Keys (DECARM). Always on. | #N |
1893
+ * | 9 | X10 xterm mouse protocol. | #Y |
1894
+ * | 12 | Start Blinking Cursor. | #Y |
1895
+ * | 25 | Show Cursor (DECTCEM). | #Y |
1896
+ * | 45 | Reverse wrap-around. | #Y |
1897
+ * | 47 | Use Alternate Screen Buffer. | #Y |
1898
+ * | 66 | Application keypad (DECNKM). | #Y |
1899
+ * | 1000 | X11 xterm mouse protocol. | #Y |
1900
+ * | 1002 | Use Cell Motion Mouse Tracking. | #Y |
1901
+ * | 1003 | Use All Motion Mouse Tracking. | #Y |
1902
+ * | 1004 | Send FocusIn/FocusOut events | #Y |
1903
+ * | 1005 | Enable UTF-8 Mouse Mode. | #N |
1904
+ * | 1006 | Enable SGR Mouse Mode. | #Y |
1905
+ * | 1015 | Enable urxvt Mouse Mode. | #N |
1906
+ * | 1047 | Use Alternate Screen Buffer. | #Y |
1907
+ * | 1048 | Save cursor as in DECSC. | #Y |
1908
+ * | 1049 | Save cursor and switch to alternate buffer clearing it. | #P[Does not clear the alternate buffer.] |
1909
+ * | 2004 | Set bracketed paste mode. | #Y |
1910
+ *
1911
+ *
1912
+ * FIXME: implement DECSCNM, 1049 should clear altbuffer
1913
+ */
1914
+ public setModePrivate(params: IParams): boolean {
1915
+ for (let i = 0; i < params.length; i++) {
1916
+ switch (params.params[i]) {
1917
+ case 1:
1918
+ this._coreService.decPrivateModes.applicationCursorKeys = true;
1919
+ break;
1920
+ case 2:
1921
+ this._charsetService.setgCharset(0, DEFAULT_CHARSET);
1922
+ this._charsetService.setgCharset(1, DEFAULT_CHARSET);
1923
+ this._charsetService.setgCharset(2, DEFAULT_CHARSET);
1924
+ this._charsetService.setgCharset(3, DEFAULT_CHARSET);
1925
+ // set VT100 mode here
1926
+ break;
1927
+ case 3:
1928
+ /**
1929
+ * DECCOLM - 132 column mode.
1930
+ * This is only active if 'SetWinLines' (24) is enabled
1931
+ * through `options.windowsOptions`.
1932
+ */
1933
+ if (this._optionsService.rawOptions.windowOptions.setWinLines) {
1934
+ this._bufferService.resize(132, this._bufferService.rows);
1935
+ this._onRequestReset.fire();
1936
+ }
1937
+ break;
1938
+ case 6:
1939
+ this._coreService.decPrivateModes.origin = true;
1940
+ this._setCursor(0, 0);
1941
+ break;
1942
+ case 7:
1943
+ this._coreService.decPrivateModes.wraparound = true;
1944
+ break;
1945
+ case 12:
1946
+ // this.cursorBlink = true;
1947
+ break;
1948
+ case 45:
1949
+ this._coreService.decPrivateModes.reverseWraparound = true;
1950
+ break;
1951
+ case 66:
1952
+ this._logService.debug('Serial port requested application keypad.');
1953
+ this._coreService.decPrivateModes.applicationKeypad = true;
1954
+ this._onRequestSyncScrollBar.fire();
1955
+ break;
1956
+ case 9: // X10 Mouse
1957
+ // no release, no motion, no wheel, no modifiers.
1958
+ this._coreMouseService.activeProtocol = 'X10';
1959
+ break;
1960
+ case 1000: // vt200 mouse
1961
+ // no motion.
1962
+ this._coreMouseService.activeProtocol = 'VT200';
1963
+ break;
1964
+ case 1002: // button event mouse
1965
+ this._coreMouseService.activeProtocol = 'DRAG';
1966
+ break;
1967
+ case 1003: // any event mouse
1968
+ // any event - sends motion events,
1969
+ // even if there is no button held down.
1970
+ this._coreMouseService.activeProtocol = 'ANY';
1971
+ break;
1972
+ case 1004: // send focusin/focusout events
1973
+ // focusin: ^[[I
1974
+ // focusout: ^[[O
1975
+ this._coreService.decPrivateModes.sendFocus = true;
1976
+ this._onRequestSendFocus.fire();
1977
+ break;
1978
+ case 1005: // utf8 ext mode mouse - removed in #2507
1979
+ this._logService.debug('DECSET 1005 not supported (see #2507)');
1980
+ break;
1981
+ case 1006: // sgr ext mode mouse
1982
+ this._coreMouseService.activeEncoding = 'SGR';
1983
+ break;
1984
+ case 1015: // urxvt ext mode mouse - removed in #2507
1985
+ this._logService.debug('DECSET 1015 not supported (see #2507)');
1986
+ break;
1987
+ case 25: // show cursor
1988
+ this._coreService.isCursorHidden = false;
1989
+ break;
1990
+ case 1048: // alt screen cursor
1991
+ this.saveCursor();
1992
+ break;
1993
+ case 1049: // alt screen buffer cursor
1994
+ this.saveCursor();
1995
+ // FALL-THROUGH
1996
+ case 47: // alt screen buffer
1997
+ case 1047: // alt screen buffer
1998
+ this._bufferService.buffers.activateAltBuffer(this._eraseAttrData());
1999
+ this._coreService.isCursorInitialized = true;
2000
+ this._onRequestRefreshRows.fire(0, this._bufferService.rows - 1);
2001
+ this._onRequestSyncScrollBar.fire();
2002
+ break;
2003
+ case 2004: // bracketed paste mode (https://cirw.in/blog/bracketed-paste)
2004
+ this._coreService.decPrivateModes.bracketedPasteMode = true;
2005
+ break;
2006
+ }
2007
+ }
2008
+ return true;
2009
+ }
2010
+
2011
+
2012
+ /**
2013
+ * CSI Pm l Reset Mode (RM).
2014
+ * Ps = 2 -> Keyboard Action Mode (AM).
2015
+ * Ps = 4 -> Replace Mode (IRM).
2016
+ * Ps = 1 2 -> Send/receive (SRM).
2017
+ * Ps = 2 0 -> Normal Linefeed (LNM).
2018
+ *
2019
+ * @vt: #P[Only IRM is supported.] CSI RM "Reset Mode" "CSI Pm l" "Set various terminal attributes."
2020
+ * Supported param values by RM:
2021
+ *
2022
+ * | Param | Action | Support |
2023
+ * | ----- | -------------------------------------- | ------- |
2024
+ * | 2 | Keyboard Action Mode (KAM). Always on. | #N |
2025
+ * | 4 | Replace Mode (IRM). (default) | #Y |
2026
+ * | 12 | Send/receive (SRM). Always off. | #N |
2027
+ * | 20 | Normal Linefeed (LNM). Always off. | #N |
2028
+ *
2029
+ *
2030
+ * FIXME: why is LNM commented out?
2031
+ */
2032
+ public resetMode(params: IParams): boolean {
2033
+ for (let i = 0; i < params.length; i++) {
2034
+ switch (params.params[i]) {
2035
+ case 4:
2036
+ this._coreService.modes.insertMode = false;
2037
+ break;
2038
+ case 20:
2039
+ // this._t.convertEol = false;
2040
+ break;
2041
+ }
2042
+ }
2043
+ return true;
2044
+ }
2045
+
2046
+ /**
2047
+ * CSI ? Pm l
2048
+ * DEC Private Mode Reset (DECRST).
2049
+ * Ps = 1 -> Normal Cursor Keys (DECCKM).
2050
+ * Ps = 2 -> Designate VT52 mode (DECANM).
2051
+ * Ps = 3 -> 80 Column Mode (DECCOLM).
2052
+ * Ps = 4 -> Jump (Fast) Scroll (DECSCLM).
2053
+ * Ps = 5 -> Normal Video (DECSCNM).
2054
+ * Ps = 6 -> Normal Cursor Mode (DECOM).
2055
+ * Ps = 7 -> No Wraparound Mode (DECAWM).
2056
+ * Ps = 8 -> No Auto-repeat Keys (DECARM).
2057
+ * Ps = 9 -> Don't send Mouse X & Y on button press.
2058
+ * Ps = 1 0 -> Hide toolbar (rxvt).
2059
+ * Ps = 1 2 -> Stop Blinking Cursor (att610).
2060
+ * Ps = 1 8 -> Don't print form feed (DECPFF).
2061
+ * Ps = 1 9 -> Limit print to scrolling region (DECPEX).
2062
+ * Ps = 2 5 -> Hide Cursor (DECTCEM).
2063
+ * Ps = 3 0 -> Don't show scrollbar (rxvt).
2064
+ * Ps = 3 5 -> Disable font-shifting functions (rxvt).
2065
+ * Ps = 4 0 -> Disallow 80 -> 132 Mode.
2066
+ * Ps = 4 1 -> No more(1) fix (see curses resource).
2067
+ * Ps = 4 2 -> Disable Nation Replacement Character sets (DEC-
2068
+ * NRCM).
2069
+ * Ps = 4 4 -> Turn Off Margin Bell.
2070
+ * Ps = 4 5 -> No Reverse-wraparound Mode.
2071
+ * Ps = 4 6 -> Stop Logging. (This is normally disabled by a
2072
+ * compile-time option).
2073
+ * Ps = 4 7 -> Use Normal Screen Buffer.
2074
+ * Ps = 6 6 -> Numeric keypad (DECNKM).
2075
+ * Ps = 6 7 -> Backarrow key sends delete (DECBKM).
2076
+ * Ps = 1 0 0 0 -> Don't send Mouse X & Y on button press and
2077
+ * release. See the section Mouse Tracking.
2078
+ * Ps = 1 0 0 1 -> Don't use Hilite Mouse Tracking.
2079
+ * Ps = 1 0 0 2 -> Don't use Cell Motion Mouse Tracking.
2080
+ * Ps = 1 0 0 3 -> Don't use All Motion Mouse Tracking.
2081
+ * Ps = 1 0 0 4 -> Don't send FocusIn/FocusOut events.
2082
+ * Ps = 1 0 0 5 -> Disable Extended Mouse Mode.
2083
+ * Ps = 1 0 1 0 -> Don't scroll to bottom on tty output
2084
+ * (rxvt).
2085
+ * Ps = 1 0 1 1 -> Don't scroll to bottom on key press (rxvt).
2086
+ * Ps = 1 0 3 4 -> Don't interpret "meta" key. (This disables
2087
+ * the eightBitInput resource).
2088
+ * Ps = 1 0 3 5 -> Disable special modifiers for Alt and Num-
2089
+ * Lock keys. (This disables the numLock resource).
2090
+ * Ps = 1 0 3 6 -> Don't send ESC when Meta modifies a key.
2091
+ * (This disables the metaSendsEscape resource).
2092
+ * Ps = 1 0 3 7 -> Send VT220 Remove from the editing-keypad
2093
+ * Delete key.
2094
+ * Ps = 1 0 3 9 -> Don't send ESC when Alt modifies a key.
2095
+ * (This disables the altSendsEscape resource).
2096
+ * Ps = 1 0 4 0 -> Do not keep selection when not highlighted.
2097
+ * (This disables the keepSelection resource).
2098
+ * Ps = 1 0 4 1 -> Use the PRIMARY selection. (This disables
2099
+ * the selectToClipboard resource).
2100
+ * Ps = 1 0 4 2 -> Disable Urgency window manager hint when
2101
+ * Control-G is received. (This disables the bellIsUrgent
2102
+ * resource).
2103
+ * Ps = 1 0 4 3 -> Disable raising of the window when Control-
2104
+ * G is received. (This disables the popOnBell resource).
2105
+ * Ps = 1 0 4 7 -> Use Normal Screen Buffer, clearing screen
2106
+ * first if in the Alternate Screen. (This may be disabled by
2107
+ * the titeInhibit resource).
2108
+ * Ps = 1 0 4 8 -> Restore cursor as in DECRC. (This may be
2109
+ * disabled by the titeInhibit resource).
2110
+ * Ps = 1 0 4 9 -> Use Normal Screen Buffer and restore cursor
2111
+ * as in DECRC. (This may be disabled by the titeInhibit
2112
+ * resource). This combines the effects of the 1 0 4 7 and 1 0
2113
+ * 4 8 modes. Use this with terminfo-based applications rather
2114
+ * than the 4 7 mode.
2115
+ * Ps = 1 0 5 0 -> Reset terminfo/termcap function-key mode.
2116
+ * Ps = 1 0 5 1 -> Reset Sun function-key mode.
2117
+ * Ps = 1 0 5 2 -> Reset HP function-key mode.
2118
+ * Ps = 1 0 5 3 -> Reset SCO function-key mode.
2119
+ * Ps = 1 0 6 0 -> Reset legacy keyboard emulation (X11R6).
2120
+ * Ps = 1 0 6 1 -> Reset keyboard emulation to Sun/PC style.
2121
+ * Ps = 2 0 0 4 -> Reset bracketed paste mode.
2122
+ *
2123
+ * @vt: #P[See below for supported modes.] CSI DECRST "DEC Private Reset Mode" "CSI ? Pm l" "Reset various terminal attributes."
2124
+ * Supported param values by DECRST:
2125
+ *
2126
+ * | param | Action | Support |
2127
+ * | ----- | ------------------------------------------------------- | ------- |
2128
+ * | 1 | Normal Cursor Keys (DECCKM). | #Y |
2129
+ * | 2 | Designate VT52 mode (DECANM). | #N |
2130
+ * | 3 | 80 Column Mode (DECCOLM). | #B[Switches to old column width instead of 80.] |
2131
+ * | 6 | Normal Cursor Mode (DECOM). | #Y |
2132
+ * | 7 | No Wraparound Mode (DECAWM). | #Y |
2133
+ * | 8 | No Auto-repeat Keys (DECARM). | #N |
2134
+ * | 9 | Don't send Mouse X & Y on button press. | #Y |
2135
+ * | 12 | Stop Blinking Cursor. | #Y |
2136
+ * | 25 | Hide Cursor (DECTCEM). | #Y |
2137
+ * | 45 | No reverse wrap-around. | #Y |
2138
+ * | 47 | Use Normal Screen Buffer. | #Y |
2139
+ * | 66 | Numeric keypad (DECNKM). | #Y |
2140
+ * | 1000 | Don't send Mouse reports. | #Y |
2141
+ * | 1002 | Don't use Cell Motion Mouse Tracking. | #Y |
2142
+ * | 1003 | Don't use All Motion Mouse Tracking. | #Y |
2143
+ * | 1004 | Don't send FocusIn/FocusOut events. | #Y |
2144
+ * | 1005 | Disable UTF-8 Mouse Mode. | #N |
2145
+ * | 1006 | Disable SGR Mouse Mode. | #Y |
2146
+ * | 1015 | Disable urxvt Mouse Mode. | #N |
2147
+ * | 1047 | Use Normal Screen Buffer (clearing screen if in alt). | #Y |
2148
+ * | 1048 | Restore cursor as in DECRC. | #Y |
2149
+ * | 1049 | Use Normal Screen Buffer and restore cursor. | #Y |
2150
+ * | 2004 | Reset bracketed paste mode. | #Y |
2151
+ *
2152
+ *
2153
+ * FIXME: DECCOLM is currently broken (already fixed in window options PR)
2154
+ */
2155
+ public resetModePrivate(params: IParams): boolean {
2156
+ for (let i = 0; i < params.length; i++) {
2157
+ switch (params.params[i]) {
2158
+ case 1:
2159
+ this._coreService.decPrivateModes.applicationCursorKeys = false;
2160
+ break;
2161
+ case 3:
2162
+ /**
2163
+ * DECCOLM - 80 column mode.
2164
+ * This is only active if 'SetWinLines' (24) is enabled
2165
+ * through `options.windowsOptions`.
2166
+ */
2167
+ if (this._optionsService.rawOptions.windowOptions.setWinLines) {
2168
+ this._bufferService.resize(80, this._bufferService.rows);
2169
+ this._onRequestReset.fire();
2170
+ }
2171
+ break;
2172
+ case 6:
2173
+ this._coreService.decPrivateModes.origin = false;
2174
+ this._setCursor(0, 0);
2175
+ break;
2176
+ case 7:
2177
+ this._coreService.decPrivateModes.wraparound = false;
2178
+ break;
2179
+ case 12:
2180
+ // this.cursorBlink = false;
2181
+ break;
2182
+ case 45:
2183
+ this._coreService.decPrivateModes.reverseWraparound = false;
2184
+ break;
2185
+ case 66:
2186
+ this._logService.debug('Switching back to normal keypad.');
2187
+ this._coreService.decPrivateModes.applicationKeypad = false;
2188
+ this._onRequestSyncScrollBar.fire();
2189
+ break;
2190
+ case 9: // X10 Mouse
2191
+ case 1000: // vt200 mouse
2192
+ case 1002: // button event mouse
2193
+ case 1003: // any event mouse
2194
+ this._coreMouseService.activeProtocol = 'NONE';
2195
+ break;
2196
+ case 1004: // send focusin/focusout events
2197
+ this._coreService.decPrivateModes.sendFocus = false;
2198
+ break;
2199
+ case 1005: // utf8 ext mode mouse - removed in #2507
2200
+ this._logService.debug('DECRST 1005 not supported (see #2507)');
2201
+ break;
2202
+ case 1006: // sgr ext mode mouse
2203
+ this._coreMouseService.activeEncoding = 'DEFAULT';
2204
+ break;
2205
+ case 1015: // urxvt ext mode mouse - removed in #2507
2206
+ this._logService.debug('DECRST 1015 not supported (see #2507)');
2207
+ break;
2208
+ case 25: // hide cursor
2209
+ this._coreService.isCursorHidden = true;
2210
+ break;
2211
+ case 1048: // alt screen cursor
2212
+ this.restoreCursor();
2213
+ break;
2214
+ case 1049: // alt screen buffer cursor
2215
+ // FALL-THROUGH
2216
+ case 47: // normal screen buffer
2217
+ case 1047: // normal screen buffer - clearing it first
2218
+ // Ensure the selection manager has the correct buffer
2219
+ this._bufferService.buffers.activateNormalBuffer();
2220
+ if (params.params[i] === 1049) {
2221
+ this.restoreCursor();
2222
+ }
2223
+ this._coreService.isCursorInitialized = true;
2224
+ this._onRequestRefreshRows.fire(0, this._bufferService.rows - 1);
2225
+ this._onRequestSyncScrollBar.fire();
2226
+ break;
2227
+ case 2004: // bracketed paste mode (https://cirw.in/blog/bracketed-paste)
2228
+ this._coreService.decPrivateModes.bracketedPasteMode = false;
2229
+ break;
2230
+ }
2231
+ }
2232
+ return true;
2233
+ }
2234
+
2235
+ /**
2236
+ * Helper to write color information packed with color mode.
2237
+ */
2238
+ private _updateAttrColor(color: number, mode: number, c1: number, c2: number, c3: number): number {
2239
+ if (mode === 2) {
2240
+ color |= Attributes.CM_RGB;
2241
+ color &= ~Attributes.RGB_MASK;
2242
+ color |= AttributeData.fromColorRGB([c1, c2, c3]);
2243
+ } else if (mode === 5) {
2244
+ color &= ~(Attributes.CM_MASK | Attributes.PCOLOR_MASK);
2245
+ color |= Attributes.CM_P256 | (c1 & 0xff);
2246
+ }
2247
+ return color;
2248
+ }
2249
+
2250
+ /**
2251
+ * Helper to extract and apply color params/subparams.
2252
+ * Returns advance for params index.
2253
+ */
2254
+ private _extractColor(params: IParams, pos: number, attr: IAttributeData): number {
2255
+ // normalize params
2256
+ // meaning: [target, CM, ign, val, val, val]
2257
+ // RGB : [ 38/48, 2, ign, r, g, b]
2258
+ // P256 : [ 38/48, 5, ign, v, ign, ign]
2259
+ const accu = [0, 0, -1, 0, 0, 0];
2260
+
2261
+ // alignment placeholder for non color space sequences
2262
+ let cSpace = 0;
2263
+
2264
+ // return advance we took in params
2265
+ let advance = 0;
2266
+
2267
+ do {
2268
+ accu[advance + cSpace] = params.params[pos + advance];
2269
+ if (params.hasSubParams(pos + advance)) {
2270
+ const subparams = params.getSubParams(pos + advance)!;
2271
+ let i = 0;
2272
+ do {
2273
+ if (accu[1] === 5) {
2274
+ cSpace = 1;
2275
+ }
2276
+ accu[advance + i + 1 + cSpace] = subparams[i];
2277
+ } while (++i < subparams.length && i + advance + 1 + cSpace < accu.length);
2278
+ break;
2279
+ }
2280
+ // exit early if can decide color mode with semicolons
2281
+ if ((accu[1] === 5 && advance + cSpace >= 2)
2282
+ || (accu[1] === 2 && advance + cSpace >= 5)) {
2283
+ break;
2284
+ }
2285
+ // offset colorSpace slot for semicolon mode
2286
+ if (accu[1]) {
2287
+ cSpace = 1;
2288
+ }
2289
+ } while (++advance + pos < params.length && advance + cSpace < accu.length);
2290
+
2291
+ // set default values to 0
2292
+ for (let i = 2; i < accu.length; ++i) {
2293
+ if (accu[i] === -1) {
2294
+ accu[i] = 0;
2295
+ }
2296
+ }
2297
+
2298
+ // apply colors
2299
+ switch (accu[0]) {
2300
+ case 38:
2301
+ attr.fg = this._updateAttrColor(attr.fg, accu[1], accu[3], accu[4], accu[5]);
2302
+ break;
2303
+ case 48:
2304
+ attr.bg = this._updateAttrColor(attr.bg, accu[1], accu[3], accu[4], accu[5]);
2305
+ break;
2306
+ case 58:
2307
+ attr.extended = attr.extended.clone();
2308
+ attr.extended.underlineColor = this._updateAttrColor(attr.extended.underlineColor, accu[1], accu[3], accu[4], accu[5]);
2309
+ }
2310
+
2311
+ return advance;
2312
+ }
2313
+
2314
+ /**
2315
+ * SGR 4 subparams:
2316
+ * 4:0 - equal to SGR 24 (turn off all underline)
2317
+ * 4:1 - equal to SGR 4 (single underline)
2318
+ * 4:2 - equal to SGR 21 (double underline)
2319
+ * 4:3 - curly underline
2320
+ * 4:4 - dotted underline
2321
+ * 4:5 - dashed underline
2322
+ */
2323
+ private _processUnderline(style: number, attr: IAttributeData): void {
2324
+ // treat extended attrs as immutable, thus always clone from old one
2325
+ // this is needed since the buffer only holds references to it
2326
+ attr.extended = attr.extended.clone();
2327
+
2328
+ // default to 1 == single underline
2329
+ if (!~style || style > 5) {
2330
+ style = 1;
2331
+ }
2332
+ attr.extended.underlineStyle = style;
2333
+ attr.fg |= FgFlags.UNDERLINE;
2334
+
2335
+ // 0 deactivates underline
2336
+ if (style === 0) {
2337
+ attr.fg &= ~FgFlags.UNDERLINE;
2338
+ }
2339
+
2340
+ // update HAS_EXTENDED in BG
2341
+ attr.updateExtended();
2342
+ }
2343
+
2344
+ /**
2345
+ * CSI Pm m Character Attributes (SGR).
2346
+ *
2347
+ * @vt: #P[See below for supported attributes.] CSI SGR "Select Graphic Rendition" "CSI Pm m" "Set/Reset various text attributes."
2348
+ * SGR selects one or more character attributes at the same time. Multiple params (up to 32)
2349
+ * are applied in order from left to right. The changed attributes are applied to all new
2350
+ * characters received. If you move characters in the viewport by scrolling or any other means,
2351
+ * then the attributes move with the characters.
2352
+ *
2353
+ * Supported param values by SGR:
2354
+ *
2355
+ * | Param | Meaning | Support |
2356
+ * | --------- | -------------------------------------------------------- | ------- |
2357
+ * | 0 | Normal (default). Resets any other preceding SGR. | #Y |
2358
+ * | 1 | Bold. (also see `options.drawBoldTextInBrightColors`) | #Y |
2359
+ * | 2 | Faint, decreased intensity. | #Y |
2360
+ * | 3 | Italic. | #Y |
2361
+ * | 4 | Underlined (see below for style support). | #Y |
2362
+ * | 5 | Slowly blinking. | #N |
2363
+ * | 6 | Rapidly blinking. | #N |
2364
+ * | 7 | Inverse. Flips foreground and background color. | #Y |
2365
+ * | 8 | Invisible (hidden). | #Y |
2366
+ * | 9 | Crossed-out characters (strikethrough). | #Y |
2367
+ * | 21 | Doubly underlined. | #P[Currently outputs a single underline.] |
2368
+ * | 22 | Normal (neither bold nor faint). | #Y |
2369
+ * | 23 | No italic. | #Y |
2370
+ * | 24 | Not underlined. | #Y |
2371
+ * | 25 | Steady (not blinking). | #Y |
2372
+ * | 27 | Positive (not inverse). | #Y |
2373
+ * | 28 | Visible (not hidden). | #Y |
2374
+ * | 29 | Not Crossed-out (strikethrough). | #Y |
2375
+ * | 30 | Foreground color: Black. | #Y |
2376
+ * | 31 | Foreground color: Red. | #Y |
2377
+ * | 32 | Foreground color: Green. | #Y |
2378
+ * | 33 | Foreground color: Yellow. | #Y |
2379
+ * | 34 | Foreground color: Blue. | #Y |
2380
+ * | 35 | Foreground color: Magenta. | #Y |
2381
+ * | 36 | Foreground color: Cyan. | #Y |
2382
+ * | 37 | Foreground color: White. | #Y |
2383
+ * | 38 | Foreground color: Extended color. | #P[Support for RGB and indexed colors, see below.] |
2384
+ * | 39 | Foreground color: Default (original). | #Y |
2385
+ * | 40 | Background color: Black. | #Y |
2386
+ * | 41 | Background color: Red. | #Y |
2387
+ * | 42 | Background color: Green. | #Y |
2388
+ * | 43 | Background color: Yellow. | #Y |
2389
+ * | 44 | Background color: Blue. | #Y |
2390
+ * | 45 | Background color: Magenta. | #Y |
2391
+ * | 46 | Background color: Cyan. | #Y |
2392
+ * | 47 | Background color: White. | #Y |
2393
+ * | 48 | Background color: Extended color. | #P[Support for RGB and indexed colors, see below.] |
2394
+ * | 49 | Background color: Default (original). | #Y |
2395
+ * | 90 - 97 | Bright foreground color (analogous to 30 - 37). | #Y |
2396
+ * | 100 - 107 | Bright background color (analogous to 40 - 47). | #Y |
2397
+ *
2398
+ * Underline supports subparams to denote the style in the form `4 : x`:
2399
+ *
2400
+ * | x | Meaning | Support |
2401
+ * | ------ | ------------------------------------------------------------- | ------- |
2402
+ * | 0 | No underline. Same as `SGR 24 m`. | #Y |
2403
+ * | 1 | Single underline. Same as `SGR 4 m`. | #Y |
2404
+ * | 2 | Double underline. | #P[Currently outputs a single underline.] |
2405
+ * | 3 | Curly underline. | #P[Currently outputs a single underline.] |
2406
+ * | 4 | Dotted underline. | #P[Currently outputs a single underline.] |
2407
+ * | 5 | Dashed underline. | #P[Currently outputs a single underline.] |
2408
+ * | other | Single underline. Same as `SGR 4 m`. | #Y |
2409
+ *
2410
+ * Extended colors are supported for foreground (Ps=38) and background (Ps=48) as follows:
2411
+ *
2412
+ * | Ps + 1 | Meaning | Support |
2413
+ * | ------ | ------------------------------------------------------------- | ------- |
2414
+ * | 0 | Implementation defined. | #N |
2415
+ * | 1 | Transparent. | #N |
2416
+ * | 2 | RGB color as `Ps ; 2 ; R ; G ; B` or `Ps : 2 : : R : G : B`. | #Y |
2417
+ * | 3 | CMY color. | #N |
2418
+ * | 4 | CMYK color. | #N |
2419
+ * | 5 | Indexed (256 colors) as `Ps ; 5 ; INDEX` or `Ps : 5 : INDEX`. | #Y |
2420
+ *
2421
+ *
2422
+ * FIXME: blinking is implemented in attrs, but not working in renderers?
2423
+ * FIXME: remove dead branch for p=100
2424
+ */
2425
+ public charAttributes(params: IParams): boolean {
2426
+ // Optimize a single SGR0.
2427
+ if (params.length === 1 && params.params[0] === 0) {
2428
+ this._curAttrData.fg = DEFAULT_ATTR_DATA.fg;
2429
+ this._curAttrData.bg = DEFAULT_ATTR_DATA.bg;
2430
+ return true;
2431
+ }
2432
+
2433
+ const l = params.length;
2434
+ let p;
2435
+ const attr = this._curAttrData;
2436
+
2437
+ for (let i = 0; i < l; i++) {
2438
+ p = params.params[i];
2439
+ if (p >= 30 && p <= 37) {
2440
+ // fg color 8
2441
+ attr.fg &= ~(Attributes.CM_MASK | Attributes.PCOLOR_MASK);
2442
+ attr.fg |= Attributes.CM_P16 | (p - 30);
2443
+ } else if (p >= 40 && p <= 47) {
2444
+ // bg color 8
2445
+ attr.bg &= ~(Attributes.CM_MASK | Attributes.PCOLOR_MASK);
2446
+ attr.bg |= Attributes.CM_P16 | (p - 40);
2447
+ } else if (p >= 90 && p <= 97) {
2448
+ // fg color 16
2449
+ attr.fg &= ~(Attributes.CM_MASK | Attributes.PCOLOR_MASK);
2450
+ attr.fg |= Attributes.CM_P16 | (p - 90) | 8;
2451
+ } else if (p >= 100 && p <= 107) {
2452
+ // bg color 16
2453
+ attr.bg &= ~(Attributes.CM_MASK | Attributes.PCOLOR_MASK);
2454
+ attr.bg |= Attributes.CM_P16 | (p - 100) | 8;
2455
+ } else if (p === 0) {
2456
+ // default
2457
+ attr.fg = DEFAULT_ATTR_DATA.fg;
2458
+ attr.bg = DEFAULT_ATTR_DATA.bg;
2459
+ } else if (p === 1) {
2460
+ // bold text
2461
+ attr.fg |= FgFlags.BOLD;
2462
+ } else if (p === 3) {
2463
+ // italic text
2464
+ attr.bg |= BgFlags.ITALIC;
2465
+ } else if (p === 4) {
2466
+ // underlined text
2467
+ attr.fg |= FgFlags.UNDERLINE;
2468
+ this._processUnderline(params.hasSubParams(i) ? params.getSubParams(i)![0] : UnderlineStyle.SINGLE, attr);
2469
+ } else if (p === 5) {
2470
+ // blink
2471
+ attr.fg |= FgFlags.BLINK;
2472
+ } else if (p === 7) {
2473
+ // inverse and positive
2474
+ // test with: echo -e '\e[31m\e[42mhello\e[7mworld\e[27mhi\e[m'
2475
+ attr.fg |= FgFlags.INVERSE;
2476
+ } else if (p === 8) {
2477
+ // invisible
2478
+ attr.fg |= FgFlags.INVISIBLE;
2479
+ } else if (p === 9) {
2480
+ // strikethrough
2481
+ attr.fg |= FgFlags.STRIKETHROUGH;
2482
+ } else if (p === 2) {
2483
+ // dimmed text
2484
+ attr.bg |= BgFlags.DIM;
2485
+ } else if (p === 21) {
2486
+ // double underline
2487
+ this._processUnderline(UnderlineStyle.DOUBLE, attr);
2488
+ } else if (p === 22) {
2489
+ // not bold nor faint
2490
+ attr.fg &= ~FgFlags.BOLD;
2491
+ attr.bg &= ~BgFlags.DIM;
2492
+ } else if (p === 23) {
2493
+ // not italic
2494
+ attr.bg &= ~BgFlags.ITALIC;
2495
+ } else if (p === 24) {
2496
+ // not underlined
2497
+ attr.fg &= ~FgFlags.UNDERLINE;
2498
+ } else if (p === 25) {
2499
+ // not blink
2500
+ attr.fg &= ~FgFlags.BLINK;
2501
+ } else if (p === 27) {
2502
+ // not inverse
2503
+ attr.fg &= ~FgFlags.INVERSE;
2504
+ } else if (p === 28) {
2505
+ // not invisible
2506
+ attr.fg &= ~FgFlags.INVISIBLE;
2507
+ } else if (p === 29) {
2508
+ // not strikethrough
2509
+ attr.fg &= ~FgFlags.STRIKETHROUGH;
2510
+ } else if (p === 39) {
2511
+ // reset fg
2512
+ attr.fg &= ~(Attributes.CM_MASK | Attributes.RGB_MASK);
2513
+ attr.fg |= DEFAULT_ATTR_DATA.fg & (Attributes.PCOLOR_MASK | Attributes.RGB_MASK);
2514
+ } else if (p === 49) {
2515
+ // reset bg
2516
+ attr.bg &= ~(Attributes.CM_MASK | Attributes.RGB_MASK);
2517
+ attr.bg |= DEFAULT_ATTR_DATA.bg & (Attributes.PCOLOR_MASK | Attributes.RGB_MASK);
2518
+ } else if (p === 38 || p === 48 || p === 58) {
2519
+ // fg color 256 and RGB
2520
+ i += this._extractColor(params, i, attr);
2521
+ } else if (p === 59) {
2522
+ attr.extended = attr.extended.clone();
2523
+ attr.extended.underlineColor = -1;
2524
+ attr.updateExtended();
2525
+ } else if (p === 100) { // FIXME: dead branch, p=100 already handled above!
2526
+ // reset fg/bg
2527
+ attr.fg &= ~(Attributes.CM_MASK | Attributes.RGB_MASK);
2528
+ attr.fg |= DEFAULT_ATTR_DATA.fg & (Attributes.PCOLOR_MASK | Attributes.RGB_MASK);
2529
+ attr.bg &= ~(Attributes.CM_MASK | Attributes.RGB_MASK);
2530
+ attr.bg |= DEFAULT_ATTR_DATA.bg & (Attributes.PCOLOR_MASK | Attributes.RGB_MASK);
2531
+ } else {
2532
+ this._logService.debug('Unknown SGR attribute: %d.', p);
2533
+ }
2534
+ }
2535
+ return true;
2536
+ }
2537
+
2538
+ /**
2539
+ * CSI Ps n Device Status Report (DSR).
2540
+ * Ps = 5 -> Status Report. Result (``OK'') is
2541
+ * CSI 0 n
2542
+ * Ps = 6 -> Report Cursor Position (CPR) [row;column].
2543
+ * Result is
2544
+ * CSI r ; c R
2545
+ * CSI ? Ps n
2546
+ * Device Status Report (DSR, DEC-specific).
2547
+ * Ps = 6 -> Report Cursor Position (CPR) [row;column] as CSI
2548
+ * ? r ; c R (assumes page is zero).
2549
+ * Ps = 1 5 -> Report Printer status as CSI ? 1 0 n (ready).
2550
+ * or CSI ? 1 1 n (not ready).
2551
+ * Ps = 2 5 -> Report UDK status as CSI ? 2 0 n (unlocked)
2552
+ * or CSI ? 2 1 n (locked).
2553
+ * Ps = 2 6 -> Report Keyboard status as
2554
+ * CSI ? 2 7 ; 1 ; 0 ; 0 n (North American).
2555
+ * The last two parameters apply to VT400 & up, and denote key-
2556
+ * board ready and LK01 respectively.
2557
+ * Ps = 5 3 -> Report Locator status as
2558
+ * CSI ? 5 3 n Locator available, if compiled-in, or
2559
+ * CSI ? 5 0 n No Locator, if not.
2560
+ *
2561
+ * @vt: #Y CSI DSR "Device Status Report" "CSI Ps n" "Request cursor position (CPR) with `Ps` = 6."
2562
+ */
2563
+ public deviceStatus(params: IParams): boolean {
2564
+ switch (params.params[0]) {
2565
+ case 5:
2566
+ // status report
2567
+ this._coreService.triggerDataEvent(`${C0.ESC}[0n`);
2568
+ break;
2569
+ case 6:
2570
+ // cursor position
2571
+ const y = this._activeBuffer.y + 1;
2572
+ const x = this._activeBuffer.x + 1;
2573
+ this._coreService.triggerDataEvent(`${C0.ESC}[${y};${x}R`);
2574
+ break;
2575
+ }
2576
+ return true;
2577
+ }
2578
+
2579
+ // @vt: #P[Only CPR is supported.] CSI DECDSR "DEC Device Status Report" "CSI ? Ps n" "Only CPR is supported (same as DSR)."
2580
+ public deviceStatusPrivate(params: IParams): boolean {
2581
+ // modern xterm doesnt seem to
2582
+ // respond to any of these except ?6, 6, and 5
2583
+ switch (params.params[0]) {
2584
+ case 6:
2585
+ // cursor position
2586
+ const y = this._activeBuffer.y + 1;
2587
+ const x = this._activeBuffer.x + 1;
2588
+ this._coreService.triggerDataEvent(`${C0.ESC}[?${y};${x}R`);
2589
+ break;
2590
+ case 15:
2591
+ // no printer
2592
+ // this.handler(C0.ESC + '[?11n');
2593
+ break;
2594
+ case 25:
2595
+ // dont support user defined keys
2596
+ // this.handler(C0.ESC + '[?21n');
2597
+ break;
2598
+ case 26:
2599
+ // north american keyboard
2600
+ // this.handler(C0.ESC + '[?27;1;0;0n');
2601
+ break;
2602
+ case 53:
2603
+ // no dec locator/mouse
2604
+ // this.handler(C0.ESC + '[?50n');
2605
+ break;
2606
+ }
2607
+ return true;
2608
+ }
2609
+
2610
+ /**
2611
+ * CSI ! p Soft terminal reset (DECSTR).
2612
+ * http://vt100.net/docs/vt220-rm/table4-10.html
2613
+ *
2614
+ * @vt: #Y CSI DECSTR "Soft Terminal Reset" "CSI ! p" "Reset several terminal attributes to initial state."
2615
+ * There are two terminal reset sequences - RIS and DECSTR. While RIS performs almost a full terminal bootstrap,
2616
+ * DECSTR only resets certain attributes. For most needs DECSTR should be sufficient.
2617
+ *
2618
+ * The following terminal attributes are reset to default values:
2619
+ * - IRM is reset (dafault = false)
2620
+ * - scroll margins are reset (default = viewport size)
2621
+ * - erase attributes are reset to default
2622
+ * - charsets are reset
2623
+ * - DECSC data is reset to initial values
2624
+ * - DECOM is reset to absolute mode
2625
+ *
2626
+ *
2627
+ * FIXME: there are several more attributes missing (see VT520 manual)
2628
+ */
2629
+ public softReset(params: IParams): boolean {
2630
+ this._coreService.isCursorHidden = false;
2631
+ this._onRequestSyncScrollBar.fire();
2632
+ this._activeBuffer.scrollTop = 0;
2633
+ this._activeBuffer.scrollBottom = this._bufferService.rows - 1;
2634
+ this._curAttrData = DEFAULT_ATTR_DATA.clone();
2635
+ this._coreService.reset();
2636
+ this._charsetService.reset();
2637
+
2638
+ // reset DECSC data
2639
+ this._activeBuffer.savedX = 0;
2640
+ this._activeBuffer.savedY = this._activeBuffer.ybase;
2641
+ this._activeBuffer.savedCurAttrData.fg = this._curAttrData.fg;
2642
+ this._activeBuffer.savedCurAttrData.bg = this._curAttrData.bg;
2643
+ this._activeBuffer.savedCharset = this._charsetService.charset;
2644
+
2645
+ // reset DECOM
2646
+ this._coreService.decPrivateModes.origin = false;
2647
+ return true;
2648
+ }
2649
+
2650
+ /**
2651
+ * CSI Ps SP q Set cursor style (DECSCUSR, VT520).
2652
+ * Ps = 0 -> blinking block.
2653
+ * Ps = 1 -> blinking block (default).
2654
+ * Ps = 2 -> steady block.
2655
+ * Ps = 3 -> blinking underline.
2656
+ * Ps = 4 -> steady underline.
2657
+ * Ps = 5 -> blinking bar (xterm).
2658
+ * Ps = 6 -> steady bar (xterm).
2659
+ *
2660
+ * @vt: #Y CSI DECSCUSR "Set Cursor Style" "CSI Ps SP q" "Set cursor style."
2661
+ * Supported cursor styles:
2662
+ * - empty, 0 or 1: steady block
2663
+ * - 2: blink block
2664
+ * - 3: steady underline
2665
+ * - 4: blink underline
2666
+ * - 5: steady bar
2667
+ * - 6: blink bar
2668
+ */
2669
+ public setCursorStyle(params: IParams): boolean {
2670
+ const param = params.params[0] || 1;
2671
+ switch (param) {
2672
+ case 1:
2673
+ case 2:
2674
+ this._optionsService.options.cursorStyle = 'block';
2675
+ break;
2676
+ case 3:
2677
+ case 4:
2678
+ this._optionsService.options.cursorStyle = 'underline';
2679
+ break;
2680
+ case 5:
2681
+ case 6:
2682
+ this._optionsService.options.cursorStyle = 'bar';
2683
+ break;
2684
+ }
2685
+ const isBlinking = param % 2 === 1;
2686
+ this._optionsService.options.cursorBlink = isBlinking;
2687
+ return true;
2688
+ }
2689
+
2690
+ /**
2691
+ * CSI Ps ; Ps r
2692
+ * Set Scrolling Region [top;bottom] (default = full size of win-
2693
+ * dow) (DECSTBM).
2694
+ *
2695
+ * @vt: #Y CSI DECSTBM "Set Top and Bottom Margin" "CSI Ps ; Ps r" "Set top and bottom margins of the viewport [top;bottom] (default = viewport size)."
2696
+ */
2697
+ public setScrollRegion(params: IParams): boolean {
2698
+ const top = params.params[0] || 1;
2699
+ let bottom: number;
2700
+
2701
+ if (params.length < 2 || (bottom = params.params[1]) > this._bufferService.rows || bottom === 0) {
2702
+ bottom = this._bufferService.rows;
2703
+ }
2704
+
2705
+ if (bottom > top) {
2706
+ this._activeBuffer.scrollTop = top - 1;
2707
+ this._activeBuffer.scrollBottom = bottom - 1;
2708
+ this._setCursor(0, 0);
2709
+ }
2710
+ return true;
2711
+ }
2712
+
2713
+ /**
2714
+ * CSI Ps ; Ps ; Ps t - Various window manipulations and reports (xterm)
2715
+ *
2716
+ * Note: Only those listed below are supported. All others are left to integrators and
2717
+ * need special treatment based on the embedding environment.
2718
+ *
2719
+ * Ps = 1 4 supported
2720
+ * Report xterm text area size in pixels.
2721
+ * Result is CSI 4 ; height ; width t
2722
+ * Ps = 14 ; 2 not implemented
2723
+ * Ps = 16 supported
2724
+ * Report xterm character cell size in pixels.
2725
+ * Result is CSI 6 ; height ; width t
2726
+ * Ps = 18 supported
2727
+ * Report the size of the text area in characters.
2728
+ * Result is CSI 8 ; height ; width t
2729
+ * Ps = 20 supported
2730
+ * Report xterm window's icon label.
2731
+ * Result is OSC L label ST
2732
+ * Ps = 21 supported
2733
+ * Report xterm window's title.
2734
+ * Result is OSC l label ST
2735
+ * Ps = 22 ; 0 -> Save xterm icon and window title on stack. supported
2736
+ * Ps = 22 ; 1 -> Save xterm icon title on stack. supported
2737
+ * Ps = 22 ; 2 -> Save xterm window title on stack. supported
2738
+ * Ps = 23 ; 0 -> Restore xterm icon and window title from stack. supported
2739
+ * Ps = 23 ; 1 -> Restore xterm icon title from stack. supported
2740
+ * Ps = 23 ; 2 -> Restore xterm window title from stack. supported
2741
+ * Ps >= 24 not implemented
2742
+ */
2743
+ public windowOptions(params: IParams): boolean {
2744
+ if (!paramToWindowOption(params.params[0], this._optionsService.rawOptions.windowOptions)) {
2745
+ return true;
2746
+ }
2747
+ const second = (params.length > 1) ? params.params[1] : 0;
2748
+ switch (params.params[0]) {
2749
+ case 14: // GetWinSizePixels, returns CSI 4 ; height ; width t
2750
+ if (second !== 2) {
2751
+ this._onRequestWindowsOptionsReport.fire(WindowsOptionsReportType.GET_WIN_SIZE_PIXELS);
2752
+ }
2753
+ break;
2754
+ case 16: // GetCellSizePixels, returns CSI 6 ; height ; width t
2755
+ this._onRequestWindowsOptionsReport.fire(WindowsOptionsReportType.GET_CELL_SIZE_PIXELS);
2756
+ break;
2757
+ case 18: // GetWinSizeChars, returns CSI 8 ; height ; width t
2758
+ if (this._bufferService) {
2759
+ this._coreService.triggerDataEvent(`${C0.ESC}[8;${this._bufferService.rows};${this._bufferService.cols}t`);
2760
+ }
2761
+ break;
2762
+ case 22: // PushTitle
2763
+ if (second === 0 || second === 2) {
2764
+ this._windowTitleStack.push(this._windowTitle);
2765
+ if (this._windowTitleStack.length > STACK_LIMIT) {
2766
+ this._windowTitleStack.shift();
2767
+ }
2768
+ }
2769
+ if (second === 0 || second === 1) {
2770
+ this._iconNameStack.push(this._iconName);
2771
+ if (this._iconNameStack.length > STACK_LIMIT) {
2772
+ this._iconNameStack.shift();
2773
+ }
2774
+ }
2775
+ break;
2776
+ case 23: // PopTitle
2777
+ if (second === 0 || second === 2) {
2778
+ if (this._windowTitleStack.length) {
2779
+ this.setTitle(this._windowTitleStack.pop()!);
2780
+ }
2781
+ }
2782
+ if (second === 0 || second === 1) {
2783
+ if (this._iconNameStack.length) {
2784
+ this.setIconName(this._iconNameStack.pop()!);
2785
+ }
2786
+ }
2787
+ break;
2788
+ }
2789
+ return true;
2790
+ }
2791
+
2792
+
2793
+ /**
2794
+ * CSI s
2795
+ * ESC 7
2796
+ * Save cursor (ANSI.SYS).
2797
+ *
2798
+ * @vt: #P[TODO...] CSI SCOSC "Save Cursor" "CSI s" "Save cursor position, charmap and text attributes."
2799
+ * @vt: #Y ESC SC "Save Cursor" "ESC 7" "Save cursor position, charmap and text attributes."
2800
+ */
2801
+ public saveCursor(params?: IParams): boolean {
2802
+ this._activeBuffer.savedX = this._activeBuffer.x;
2803
+ this._activeBuffer.savedY = this._activeBuffer.ybase + this._activeBuffer.y;
2804
+ this._activeBuffer.savedCurAttrData.fg = this._curAttrData.fg;
2805
+ this._activeBuffer.savedCurAttrData.bg = this._curAttrData.bg;
2806
+ this._activeBuffer.savedCharset = this._charsetService.charset;
2807
+ return true;
2808
+ }
2809
+
2810
+
2811
+ /**
2812
+ * CSI u
2813
+ * ESC 8
2814
+ * Restore cursor (ANSI.SYS).
2815
+ *
2816
+ * @vt: #P[TODO...] CSI SCORC "Restore Cursor" "CSI u" "Restore cursor position, charmap and text attributes."
2817
+ * @vt: #Y ESC RC "Restore Cursor" "ESC 8" "Restore cursor position, charmap and text attributes."
2818
+ */
2819
+ public restoreCursor(params?: IParams): boolean {
2820
+ this._activeBuffer.x = this._activeBuffer.savedX || 0;
2821
+ this._activeBuffer.y = Math.max(this._activeBuffer.savedY - this._activeBuffer.ybase, 0);
2822
+ this._curAttrData.fg = this._activeBuffer.savedCurAttrData.fg;
2823
+ this._curAttrData.bg = this._activeBuffer.savedCurAttrData.bg;
2824
+ this._charsetService.charset = (this as any)._savedCharset;
2825
+ if (this._activeBuffer.savedCharset) {
2826
+ this._charsetService.charset = this._activeBuffer.savedCharset;
2827
+ }
2828
+ this._restrictCursor();
2829
+ return true;
2830
+ }
2831
+
2832
+
2833
+ /**
2834
+ * OSC 2; <data> ST (set window title)
2835
+ * Proxy to set window title.
2836
+ *
2837
+ * @vt: #P[Icon name is not exposed.] OSC 0 "Set Windows Title and Icon Name" "OSC 0 ; Pt BEL" "Set window title and icon name."
2838
+ * Icon name is not supported. For Window Title see below.
2839
+ *
2840
+ * @vt: #Y OSC 2 "Set Windows Title" "OSC 2 ; Pt BEL" "Set window title."
2841
+ * xterm.js does not manipulate the title directly, instead exposes changes via the event `Terminal.onTitleChange`.
2842
+ */
2843
+ public setTitle(data: string): boolean {
2844
+ this._windowTitle = data;
2845
+ this._onTitleChange.fire(data);
2846
+ return true;
2847
+ }
2848
+
2849
+ /**
2850
+ * OSC 1; <data> ST
2851
+ * Note: Icon name is not exposed.
2852
+ */
2853
+ public setIconName(data: string): boolean {
2854
+ this._iconName = data;
2855
+ return true;
2856
+ }
2857
+
2858
+ /**
2859
+ * OSC 4; <num> ; <text> ST (set ANSI color <num> to <text>)
2860
+ *
2861
+ * @vt: #Y OSC 4 "Set ANSI color" "OSC 4 ; c ; spec BEL" "Change color number `c` to the color specified by `spec`."
2862
+ * `c` is the color index between 0 and 255. The color format of `spec` is derived from `XParseColor` (see OSC 10 for supported formats).
2863
+ * There may be multipe `c ; spec` pairs present in the same instruction.
2864
+ * If `spec` contains `?` the terminal returns a sequence with the currently set color.
2865
+ */
2866
+ public setOrReportIndexedColor(data: string): boolean {
2867
+ const event: IColorEvent = [];
2868
+ const slots = data.split(';');
2869
+ while (slots.length > 1) {
2870
+ const idx = slots.shift() as string;
2871
+ const spec = slots.shift() as string;
2872
+ if (/^\d+$/.exec(idx)) {
2873
+ const index = parseInt(idx);
2874
+ if (0 <= index && index < 256) {
2875
+ if (spec === '?') {
2876
+ event.push({ type: ColorRequestType.REPORT, index });
2877
+ } else {
2878
+ const color = parseColor(spec);
2879
+ if (color) {
2880
+ event.push({ type: ColorRequestType.SET, index, color });
2881
+ }
2882
+ }
2883
+ }
2884
+ }
2885
+ }
2886
+ if (event.length) {
2887
+ this._onColor.fire(event);
2888
+ }
2889
+ return true;
2890
+ }
2891
+
2892
+ // special colors - OSC 10 | 11 | 12
2893
+ private _specialColors = [ColorIndex.FOREGROUND, ColorIndex.BACKGROUND, ColorIndex.CURSOR];
2894
+
2895
+ /**
2896
+ * Apply colors requests for special colors in OSC 10 | 11 | 12.
2897
+ * Since these commands are stacking from multiple parameters,
2898
+ * we handle them in a loop with an entry offset to `_specialColors`.
2899
+ */
2900
+ private _setOrReportSpecialColor(data: string, offset: number): boolean {
2901
+ const slots = data.split(';');
2902
+ for (let i = 0; i < slots.length; ++i, ++offset) {
2903
+ if (offset >= this._specialColors.length) break;
2904
+ if (slots[i] === '?') {
2905
+ this._onColor.fire([{ type: ColorRequestType.REPORT, index: this._specialColors[offset] }]);
2906
+ } else {
2907
+ const color = parseColor(slots[i]);
2908
+ if (color) {
2909
+ this._onColor.fire([{ type: ColorRequestType.SET, index: this._specialColors[offset], color }]);
2910
+ }
2911
+ }
2912
+ }
2913
+ return true;
2914
+ }
2915
+
2916
+ /**
2917
+ * OSC 10 ; <xcolor name>|<?> ST - set or query default foreground color
2918
+ *
2919
+ * @vt: #Y OSC 10 "Set or query default foreground color" "OSC 10 ; Pt BEL" "Set or query default foreground color."
2920
+ * To set the color, the following color specification formats are supported:
2921
+ * - `rgb:<red>/<green>/<blue>` for `<red>, <green>, <blue>` in `h | hh | hhh | hhhh`, where
2922
+ * `h` is a single hexadecimal digit (case insignificant). The different widths scale
2923
+ * from 4 bit (`h`) to 16 bit (`hhhh`) and get converted to 8 bit (`hh`).
2924
+ * - `#RGB` - 4 bits per channel, expanded to `#R0G0B0`
2925
+ * - `#RRGGBB` - 8 bits per channel
2926
+ * - `#RRRGGGBBB` - 12 bits per channel, truncated to `#RRGGBB`
2927
+ * - `#RRRRGGGGBBBB` - 16 bits per channel, truncated to `#RRGGBB`
2928
+ *
2929
+ * **Note:** X11 named colors are currently unsupported.
2930
+ *
2931
+ * If `Pt` contains `?` instead of a color specification, the terminal
2932
+ * returns a sequence with the current default foreground color
2933
+ * (use that sequence to restore the color after changes).
2934
+ *
2935
+ * **Note:** Other than xterm, xterm.js does not support OSC 12 - 19.
2936
+ * Therefore stacking multiple `Pt` separated by `;` only works for the first two entries.
2937
+ */
2938
+ public setOrReportFgColor(data: string): boolean {
2939
+ return this._setOrReportSpecialColor(data, 0);
2940
+ }
2941
+
2942
+ /**
2943
+ * OSC 11 ; <xcolor name>|<?> ST - set or query default background color
2944
+ *
2945
+ * @vt: #Y OSC 11 "Set or query default background color" "OSC 11 ; Pt BEL" "Same as OSC 10, but for default background."
2946
+ */
2947
+ public setOrReportBgColor(data: string): boolean {
2948
+ return this._setOrReportSpecialColor(data, 1);
2949
+ }
2950
+
2951
+ /**
2952
+ * OSC 12 ; <xcolor name>|<?> ST - set or query default cursor color
2953
+ *
2954
+ * @vt: #Y OSC 12 "Set or query default cursor color" "OSC 12 ; Pt BEL" "Same as OSC 10, but for default cursor color."
2955
+ */
2956
+ public setOrReportCursorColor(data: string): boolean {
2957
+ return this._setOrReportSpecialColor(data, 2);
2958
+ }
2959
+
2960
+ /**
2961
+ * OSC 104 ; <num> ST - restore ANSI color <num>
2962
+ *
2963
+ * @vt: #Y OSC 104 "Reset ANSI color" "OSC 104 ; c BEL" "Reset color number `c` to themed color."
2964
+ * `c` is the color index between 0 and 255. This function restores the default color for `c` as
2965
+ * specified by the loaded theme. Any number of `c` parameters may be given.
2966
+ * If no parameters are given, the entire indexed color table will be reset.
2967
+ */
2968
+ public restoreIndexedColor(data: string): boolean {
2969
+ if (!data) {
2970
+ this._onColor.fire([{ type: ColorRequestType.RESTORE }]);
2971
+ return true;
2972
+ }
2973
+ const event: IColorEvent = [];
2974
+ const slots = data.split(';');
2975
+ for (let i = 0; i < slots.length; ++i) {
2976
+ if (/^\d+$/.exec(slots[i])) {
2977
+ const index = parseInt(slots[i]);
2978
+ if (0 <= index && index < 256) {
2979
+ event.push({ type: ColorRequestType.RESTORE, index });
2980
+ }
2981
+ }
2982
+ }
2983
+ if (event.length) {
2984
+ this._onColor.fire(event);
2985
+ }
2986
+ return true;
2987
+ }
2988
+
2989
+ /**
2990
+ * OSC 110 ST - restore default foreground color
2991
+ *
2992
+ * @vt: #Y OSC 110 "Restore default foreground color" "OSC 110 BEL" "Restore default foreground to themed color."
2993
+ */
2994
+ public restoreFgColor(data: string): boolean {
2995
+ this._onColor.fire([{ type: ColorRequestType.RESTORE, index: ColorIndex.FOREGROUND }]);
2996
+ return true;
2997
+ }
2998
+
2999
+ /**
3000
+ * OSC 111 ST - restore default background color
3001
+ *
3002
+ * @vt: #Y OSC 111 "Restore default background color" "OSC 111 BEL" "Restore default background to themed color."
3003
+ */
3004
+ public restoreBgColor(data: string): boolean {
3005
+ this._onColor.fire([{ type: ColorRequestType.RESTORE, index: ColorIndex.BACKGROUND }]);
3006
+ return true;
3007
+ }
3008
+
3009
+ /**
3010
+ * OSC 112 ST - restore default cursor color
3011
+ *
3012
+ * @vt: #Y OSC 112 "Restore default cursor color" "OSC 112 BEL" "Restore default cursor to themed color."
3013
+ */
3014
+ public restoreCursorColor(data: string): boolean {
3015
+ this._onColor.fire([{ type: ColorRequestType.RESTORE, index: ColorIndex.CURSOR }]);
3016
+ return true;
3017
+ }
3018
+
3019
+ /**
3020
+ * ESC E
3021
+ * C1.NEL
3022
+ * DEC mnemonic: NEL (https://vt100.net/docs/vt510-rm/NEL)
3023
+ * Moves cursor to first position on next line.
3024
+ *
3025
+ * @vt: #Y C1 NEL "Next Line" "\x85" "Move the cursor to the beginning of the next row."
3026
+ * @vt: #Y ESC NEL "Next Line" "ESC E" "Move the cursor to the beginning of the next row."
3027
+ */
3028
+ public nextLine(): boolean {
3029
+ this._activeBuffer.x = 0;
3030
+ this.index();
3031
+ return true;
3032
+ }
3033
+
3034
+ /**
3035
+ * ESC =
3036
+ * DEC mnemonic: DECKPAM (https://vt100.net/docs/vt510-rm/DECKPAM.html)
3037
+ * Enables the numeric keypad to send application sequences to the host.
3038
+ */
3039
+ public keypadApplicationMode(): boolean {
3040
+ this._logService.debug('Serial port requested application keypad.');
3041
+ this._coreService.decPrivateModes.applicationKeypad = true;
3042
+ this._onRequestSyncScrollBar.fire();
3043
+ return true;
3044
+ }
3045
+
3046
+ /**
3047
+ * ESC >
3048
+ * DEC mnemonic: DECKPNM (https://vt100.net/docs/vt510-rm/DECKPNM.html)
3049
+ * Enables the keypad to send numeric characters to the host.
3050
+ */
3051
+ public keypadNumericMode(): boolean {
3052
+ this._logService.debug('Switching back to normal keypad.');
3053
+ this._coreService.decPrivateModes.applicationKeypad = false;
3054
+ this._onRequestSyncScrollBar.fire();
3055
+ return true;
3056
+ }
3057
+
3058
+ /**
3059
+ * ESC % @
3060
+ * ESC % G
3061
+ * Select default character set. UTF-8 is not supported (string are unicode anyways)
3062
+ * therefore ESC % G does the same.
3063
+ */
3064
+ public selectDefaultCharset(): boolean {
3065
+ this._charsetService.setgLevel(0);
3066
+ this._charsetService.setgCharset(0, DEFAULT_CHARSET); // US (default)
3067
+ return true;
3068
+ }
3069
+
3070
+ /**
3071
+ * ESC ( C
3072
+ * Designate G0 Character Set, VT100, ISO 2022.
3073
+ * ESC ) C
3074
+ * Designate G1 Character Set (ISO 2022, VT100).
3075
+ * ESC * C
3076
+ * Designate G2 Character Set (ISO 2022, VT220).
3077
+ * ESC + C
3078
+ * Designate G3 Character Set (ISO 2022, VT220).
3079
+ * ESC - C
3080
+ * Designate G1 Character Set (VT300).
3081
+ * ESC . C
3082
+ * Designate G2 Character Set (VT300).
3083
+ * ESC / C
3084
+ * Designate G3 Character Set (VT300). C = A -> ISO Latin-1 Supplemental. - Supported?
3085
+ */
3086
+ public selectCharset(collectAndFlag: string): boolean {
3087
+ if (collectAndFlag.length !== 2) {
3088
+ this.selectDefaultCharset();
3089
+ return true;
3090
+ }
3091
+ if (collectAndFlag[0] === '/') {
3092
+ return true; // TODO: Is this supported?
3093
+ }
3094
+ this._charsetService.setgCharset(GLEVEL[collectAndFlag[0]], CHARSETS[collectAndFlag[1]] || DEFAULT_CHARSET);
3095
+ return true;
3096
+ }
3097
+
3098
+ /**
3099
+ * ESC D
3100
+ * C1.IND
3101
+ * DEC mnemonic: IND (https://vt100.net/docs/vt510-rm/IND.html)
3102
+ * Moves the cursor down one line in the same column.
3103
+ *
3104
+ * @vt: #Y C1 IND "Index" "\x84" "Move the cursor one line down scrolling if needed."
3105
+ * @vt: #Y ESC IND "Index" "ESC D" "Move the cursor one line down scrolling if needed."
3106
+ */
3107
+ public index(): boolean {
3108
+ this._restrictCursor();
3109
+ this._activeBuffer.y++;
3110
+ if (this._activeBuffer.y === this._activeBuffer.scrollBottom + 1) {
3111
+ this._activeBuffer.y--;
3112
+ this._bufferService.scroll(this._eraseAttrData());
3113
+ } else if (this._activeBuffer.y >= this._bufferService.rows) {
3114
+ this._activeBuffer.y = this._bufferService.rows - 1;
3115
+ }
3116
+ this._restrictCursor();
3117
+ return true;
3118
+ }
3119
+
3120
+ /**
3121
+ * ESC H
3122
+ * C1.HTS
3123
+ * DEC mnemonic: HTS (https://vt100.net/docs/vt510-rm/HTS.html)
3124
+ * Sets a horizontal tab stop at the column position indicated by
3125
+ * the value of the active column when the terminal receives an HTS.
3126
+ *
3127
+ * @vt: #Y C1 HTS "Horizontal Tabulation Set" "\x88" "Places a tab stop at the current cursor position."
3128
+ * @vt: #Y ESC HTS "Horizontal Tabulation Set" "ESC H" "Places a tab stop at the current cursor position."
3129
+ */
3130
+ public tabSet(): boolean {
3131
+ this._activeBuffer.tabs[this._activeBuffer.x] = true;
3132
+ return true;
3133
+ }
3134
+
3135
+ /**
3136
+ * ESC M
3137
+ * C1.RI
3138
+ * DEC mnemonic: HTS
3139
+ * Moves the cursor up one line in the same column. If the cursor is at the top margin,
3140
+ * the page scrolls down.
3141
+ *
3142
+ * @vt: #Y ESC IR "Reverse Index" "ESC M" "Move the cursor one line up scrolling if needed."
3143
+ */
3144
+ public reverseIndex(): boolean {
3145
+ this._restrictCursor();
3146
+ if (this._activeBuffer.y === this._activeBuffer.scrollTop) {
3147
+ // possibly move the code below to term.reverseScroll();
3148
+ // test: echo -ne '\e[1;1H\e[44m\eM\e[0m'
3149
+ // blankLine(true) is xterm/linux behavior
3150
+ const scrollRegionHeight = this._activeBuffer.scrollBottom - this._activeBuffer.scrollTop;
3151
+ this._activeBuffer.lines.shiftElements(this._activeBuffer.ybase + this._activeBuffer.y, scrollRegionHeight, 1);
3152
+ this._activeBuffer.lines.set(this._activeBuffer.ybase + this._activeBuffer.y, this._activeBuffer.getBlankLine(this._eraseAttrData()));
3153
+ this._dirtyRowService.markRangeDirty(this._activeBuffer.scrollTop, this._activeBuffer.scrollBottom);
3154
+ } else {
3155
+ this._activeBuffer.y--;
3156
+ this._restrictCursor(); // quickfix to not run out of bounds
3157
+ }
3158
+ return true;
3159
+ }
3160
+
3161
+ /**
3162
+ * ESC c
3163
+ * DEC mnemonic: RIS (https://vt100.net/docs/vt510-rm/RIS.html)
3164
+ * Reset to initial state.
3165
+ */
3166
+ public fullReset(): boolean {
3167
+ this._parser.reset();
3168
+ this._onRequestReset.fire();
3169
+ return true;
3170
+ }
3171
+
3172
+ public reset(): void {
3173
+ this._curAttrData = DEFAULT_ATTR_DATA.clone();
3174
+ this._eraseAttrDataInternal = DEFAULT_ATTR_DATA.clone();
3175
+ }
3176
+
3177
+ /**
3178
+ * back_color_erase feature for xterm.
3179
+ */
3180
+ private _eraseAttrData(): IAttributeData {
3181
+ this._eraseAttrDataInternal.bg &= ~(Attributes.CM_MASK | 0xFFFFFF);
3182
+ this._eraseAttrDataInternal.bg |= this._curAttrData.bg & ~0xFC000000;
3183
+ return this._eraseAttrDataInternal;
3184
+ }
3185
+
3186
+ /**
3187
+ * ESC n
3188
+ * ESC o
3189
+ * ESC |
3190
+ * ESC }
3191
+ * ESC ~
3192
+ * DEC mnemonic: LS (https://vt100.net/docs/vt510-rm/LS.html)
3193
+ * When you use a locking shift, the character set remains in GL or GR until
3194
+ * you use another locking shift. (partly supported)
3195
+ */
3196
+ public setgLevel(level: number): boolean {
3197
+ this._charsetService.setgLevel(level);
3198
+ return true;
3199
+ }
3200
+
3201
+ /**
3202
+ * ESC # 8
3203
+ * DEC mnemonic: DECALN (https://vt100.net/docs/vt510-rm/DECALN.html)
3204
+ * This control function fills the complete screen area with
3205
+ * a test pattern (E) used for adjusting screen alignment.
3206
+ *
3207
+ * @vt: #Y ESC DECALN "Screen Alignment Pattern" "ESC # 8" "Fill viewport with a test pattern (E)."
3208
+ */
3209
+ public screenAlignmentPattern(): boolean {
3210
+ // prepare cell data
3211
+ const cell = new CellData();
3212
+ cell.content = 1 << Content.WIDTH_SHIFT | 'E'.charCodeAt(0);
3213
+ cell.fg = this._curAttrData.fg;
3214
+ cell.bg = this._curAttrData.bg;
3215
+
3216
+
3217
+ this._setCursor(0, 0);
3218
+ for (let yOffset = 0; yOffset < this._bufferService.rows; ++yOffset) {
3219
+ const row = this._activeBuffer.ybase + this._activeBuffer.y + yOffset;
3220
+ const line = this._activeBuffer.lines.get(row);
3221
+ if (line) {
3222
+ line.fill(cell);
3223
+ line.isWrapped = false;
3224
+ }
3225
+ }
3226
+ this._dirtyRowService.markAllDirty();
3227
+ this._setCursor(0, 0);
3228
+ return true;
3229
+ }
3230
+ }