@xterm/xterm 5.4.0-beta.1

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 (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +235 -0
  3. package/css/xterm.css +209 -0
  4. package/lib/xterm.js +2 -0
  5. package/lib/xterm.js.map +1 -0
  6. package/package.json +101 -0
  7. package/src/browser/AccessibilityManager.ts +278 -0
  8. package/src/browser/Clipboard.ts +93 -0
  9. package/src/browser/ColorContrastCache.ts +34 -0
  10. package/src/browser/Lifecycle.ts +33 -0
  11. package/src/browser/Linkifier2.ts +416 -0
  12. package/src/browser/LocalizableStrings.ts +12 -0
  13. package/src/browser/OscLinkProvider.ts +128 -0
  14. package/src/browser/RenderDebouncer.ts +83 -0
  15. package/src/browser/Terminal.ts +1317 -0
  16. package/src/browser/TimeBasedDebouncer.ts +86 -0
  17. package/src/browser/Types.d.ts +181 -0
  18. package/src/browser/Viewport.ts +401 -0
  19. package/src/browser/decorations/BufferDecorationRenderer.ts +134 -0
  20. package/src/browser/decorations/ColorZoneStore.ts +117 -0
  21. package/src/browser/decorations/OverviewRulerRenderer.ts +218 -0
  22. package/src/browser/input/CompositionHelper.ts +246 -0
  23. package/src/browser/input/Mouse.ts +54 -0
  24. package/src/browser/input/MoveToCell.ts +249 -0
  25. package/src/browser/public/Terminal.ts +260 -0
  26. package/src/browser/renderer/dom/DomRenderer.ts +509 -0
  27. package/src/browser/renderer/dom/DomRendererRowFactory.ts +526 -0
  28. package/src/browser/renderer/dom/WidthCache.ts +160 -0
  29. package/src/browser/renderer/shared/CellColorResolver.ts +137 -0
  30. package/src/browser/renderer/shared/CharAtlasCache.ts +96 -0
  31. package/src/browser/renderer/shared/CharAtlasUtils.ts +75 -0
  32. package/src/browser/renderer/shared/Constants.ts +14 -0
  33. package/src/browser/renderer/shared/CursorBlinkStateManager.ts +146 -0
  34. package/src/browser/renderer/shared/CustomGlyphs.ts +687 -0
  35. package/src/browser/renderer/shared/DevicePixelObserver.ts +41 -0
  36. package/src/browser/renderer/shared/README.md +1 -0
  37. package/src/browser/renderer/shared/RendererUtils.ts +58 -0
  38. package/src/browser/renderer/shared/SelectionRenderModel.ts +91 -0
  39. package/src/browser/renderer/shared/TextureAtlas.ts +1082 -0
  40. package/src/browser/renderer/shared/Types.d.ts +173 -0
  41. package/src/browser/selection/SelectionModel.ts +144 -0
  42. package/src/browser/selection/Types.d.ts +15 -0
  43. package/src/browser/services/CharSizeService.ts +102 -0
  44. package/src/browser/services/CharacterJoinerService.ts +339 -0
  45. package/src/browser/services/CoreBrowserService.ts +137 -0
  46. package/src/browser/services/MouseService.ts +46 -0
  47. package/src/browser/services/RenderService.ts +279 -0
  48. package/src/browser/services/SelectionService.ts +1031 -0
  49. package/src/browser/services/Services.ts +147 -0
  50. package/src/browser/services/ThemeService.ts +237 -0
  51. package/src/common/CircularList.ts +241 -0
  52. package/src/common/Clone.ts +23 -0
  53. package/src/common/Color.ts +357 -0
  54. package/src/common/CoreTerminal.ts +284 -0
  55. package/src/common/EventEmitter.ts +78 -0
  56. package/src/common/InputHandler.ts +3461 -0
  57. package/src/common/Lifecycle.ts +108 -0
  58. package/src/common/MultiKeyMap.ts +42 -0
  59. package/src/common/Platform.ts +44 -0
  60. package/src/common/SortedList.ts +118 -0
  61. package/src/common/TaskQueue.ts +166 -0
  62. package/src/common/TypedArrayUtils.ts +17 -0
  63. package/src/common/Types.d.ts +553 -0
  64. package/src/common/WindowsMode.ts +27 -0
  65. package/src/common/buffer/AttributeData.ts +196 -0
  66. package/src/common/buffer/Buffer.ts +654 -0
  67. package/src/common/buffer/BufferLine.ts +524 -0
  68. package/src/common/buffer/BufferRange.ts +13 -0
  69. package/src/common/buffer/BufferReflow.ts +223 -0
  70. package/src/common/buffer/BufferSet.ts +134 -0
  71. package/src/common/buffer/CellData.ts +94 -0
  72. package/src/common/buffer/Constants.ts +149 -0
  73. package/src/common/buffer/Marker.ts +43 -0
  74. package/src/common/buffer/Types.d.ts +52 -0
  75. package/src/common/data/Charsets.ts +256 -0
  76. package/src/common/data/EscapeSequences.ts +153 -0
  77. package/src/common/input/Keyboard.ts +398 -0
  78. package/src/common/input/TextDecoder.ts +346 -0
  79. package/src/common/input/UnicodeV6.ts +145 -0
  80. package/src/common/input/WriteBuffer.ts +246 -0
  81. package/src/common/input/XParseColor.ts +80 -0
  82. package/src/common/parser/Constants.ts +58 -0
  83. package/src/common/parser/DcsParser.ts +192 -0
  84. package/src/common/parser/EscapeSequenceParser.ts +792 -0
  85. package/src/common/parser/OscParser.ts +238 -0
  86. package/src/common/parser/Params.ts +229 -0
  87. package/src/common/parser/Types.d.ts +275 -0
  88. package/src/common/public/AddonManager.ts +53 -0
  89. package/src/common/public/BufferApiView.ts +35 -0
  90. package/src/common/public/BufferLineApiView.ts +29 -0
  91. package/src/common/public/BufferNamespaceApi.ts +36 -0
  92. package/src/common/public/ParserApi.ts +37 -0
  93. package/src/common/public/UnicodeApi.ts +27 -0
  94. package/src/common/services/BufferService.ts +151 -0
  95. package/src/common/services/CharsetService.ts +34 -0
  96. package/src/common/services/CoreMouseService.ts +318 -0
  97. package/src/common/services/CoreService.ts +87 -0
  98. package/src/common/services/DecorationService.ts +140 -0
  99. package/src/common/services/InstantiationService.ts +85 -0
  100. package/src/common/services/LogService.ts +124 -0
  101. package/src/common/services/OptionsService.ts +202 -0
  102. package/src/common/services/OscLinkService.ts +115 -0
  103. package/src/common/services/ServiceRegistry.ts +49 -0
  104. package/src/common/services/Services.ts +373 -0
  105. package/src/common/services/UnicodeService.ts +111 -0
  106. package/src/headless/Terminal.ts +136 -0
  107. package/src/headless/public/Terminal.ts +195 -0
  108. package/typings/xterm.d.ts +1857 -0
@@ -0,0 +1,275 @@
1
+ /**
2
+ * Copyright (c) 2017 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ */
5
+
6
+ import { IDisposable } from 'common/Types';
7
+ import { ParserState } from 'common/parser/Constants';
8
+
9
+
10
+ /** sequence params serialized to js arrays */
11
+ export type ParamsArray = (number | number[])[];
12
+
13
+ /** Params constructor type. */
14
+ export interface IParamsConstructor {
15
+ new(maxLength: number, maxSubParamsLength: number): IParams;
16
+
17
+ /** create params from ParamsArray */
18
+ fromArray(values: ParamsArray): IParams;
19
+ }
20
+
21
+ /** Interface of Params storage class. */
22
+ export interface IParams {
23
+ /** from ctor */
24
+ maxLength: number;
25
+ maxSubParamsLength: number;
26
+
27
+ /** param values and its length */
28
+ params: Int32Array;
29
+ length: number;
30
+
31
+ /** methods */
32
+ clone(): IParams;
33
+ toArray(): ParamsArray;
34
+ reset(): void;
35
+ addParam(value: number): void;
36
+ addSubParam(value: number): void;
37
+ hasSubParams(idx: number): boolean;
38
+ getSubParams(idx: number): Int32Array | null;
39
+ getSubParamsAll(): {[idx: number]: Int32Array};
40
+ }
41
+
42
+ /**
43
+ * Internal state of EscapeSequenceParser.
44
+ * Used as argument of the error handler to allow
45
+ * introspection at runtime on parse errors.
46
+ * Return it with altered values to recover from
47
+ * faulty states (not yet supported).
48
+ * Set `abort` to `true` to abort the current parsing.
49
+ */
50
+ export interface IParsingState {
51
+ // position in parse string
52
+ position: number;
53
+ // actual character code
54
+ code: number;
55
+ // current parser state
56
+ currentState: ParserState;
57
+ // collect buffer with intermediate characters
58
+ collect: number;
59
+ // params buffer
60
+ params: IParams;
61
+ // should abort (default: false)
62
+ abort: boolean;
63
+ }
64
+
65
+ /**
66
+ * Command handler interfaces.
67
+ */
68
+
69
+ /**
70
+ * CSI handler types.
71
+ * Note: `params` is borrowed.
72
+ */
73
+ export type CsiHandlerType = (params: IParams) => boolean | Promise<boolean>;
74
+ export type CsiFallbackHandlerType = (ident: number, params: IParams) => void;
75
+
76
+ /**
77
+ * DCS handler types.
78
+ */
79
+ export interface IDcsHandler {
80
+ /**
81
+ * Called when a DCS command starts.
82
+ * Prepare needed data structures here.
83
+ * Note: `params` is borrowed.
84
+ */
85
+ hook(params: IParams): void;
86
+ /**
87
+ * Incoming payload chunk.
88
+ * Note: `params` is borrowed.
89
+ */
90
+ put(data: Uint32Array, start: number, end: number): void;
91
+ /**
92
+ * End of DCS command. `success` indicates whether the
93
+ * command finished normally or got aborted, thus final
94
+ * execution of the command should depend on `success`.
95
+ * To save memory also cleanup data structures here.
96
+ */
97
+ unhook(success: boolean): boolean | Promise<boolean>;
98
+ }
99
+ export type DcsFallbackHandlerType = (ident: number, action: 'HOOK' | 'PUT' | 'UNHOOK', payload?: any) => void;
100
+
101
+ /**
102
+ * ESC handler types.
103
+ */
104
+ export type EscHandlerType = () => boolean | Promise<boolean>;
105
+ export type EscFallbackHandlerType = (identifier: number) => void;
106
+
107
+ /**
108
+ * EXECUTE handler types.
109
+ */
110
+ export type ExecuteHandlerType = () => boolean;
111
+ export type ExecuteFallbackHandlerType = (ident: number) => void;
112
+
113
+ /**
114
+ * OSC handler types.
115
+ */
116
+ export interface IOscHandler {
117
+ /**
118
+ * Announces start of this OSC command.
119
+ * Prepare needed data structures here.
120
+ */
121
+ start(): void;
122
+ /**
123
+ * Incoming data chunk.
124
+ * Note: Data is borrowed.
125
+ */
126
+ put(data: Uint32Array, start: number, end: number): void;
127
+ /**
128
+ * End of OSC command. `success` indicates whether the
129
+ * command finished normally or got aborted, thus final
130
+ * execution of the command should depend on `success`.
131
+ * To save memory also cleanup data structures here.
132
+ */
133
+ end(success: boolean): boolean | Promise<boolean>;
134
+ }
135
+ export type OscFallbackHandlerType = (ident: number, action: 'START' | 'PUT' | 'END', payload?: any) => void;
136
+
137
+ /**
138
+ * PRINT handler types.
139
+ */
140
+ export type PrintHandlerType = (data: Uint32Array, start: number, end: number) => void;
141
+ export type PrintFallbackHandlerType = PrintHandlerType;
142
+
143
+
144
+ /**
145
+ * EscapeSequenceParser interface.
146
+ */
147
+ export interface IEscapeSequenceParser extends IDisposable {
148
+ /**
149
+ * Preceding grapheme-join-state.
150
+ * Used for joining grapheme clusters across calls to `print`.
151
+ * Also used by REP to check if repeating a character is allowed.
152
+ * It gets reset by the parser for any valid sequence besides text.
153
+ */
154
+ precedingJoinState: number; // More specifically: UnicodeJoinProperties
155
+
156
+ /**
157
+ * Reset the parser to its initial state (handlers are kept).
158
+ */
159
+ reset(): void;
160
+
161
+ /**
162
+ * Parse UTF32 codepoints in `data` up to `length`.
163
+ * @param data The data to parse.
164
+ */
165
+ parse(data: Uint32Array, length: number, promiseResult?: boolean): void | Promise<boolean>;
166
+
167
+ /**
168
+ * Get string from numercial function identifier `ident`.
169
+ * Useful in fallback handlers which expose the low level
170
+ * numcerical function identifier for debugging purposes.
171
+ * Note: A full back translation to `IFunctionIdentifier`
172
+ * is not implemented.
173
+ */
174
+ identToString(ident: number): string;
175
+
176
+ setPrintHandler(handler: PrintHandlerType): void;
177
+ clearPrintHandler(): void;
178
+
179
+ registerEscHandler(id: IFunctionIdentifier, handler: EscHandlerType): IDisposable;
180
+ clearEscHandler(id: IFunctionIdentifier): void;
181
+ setEscHandlerFallback(handler: EscFallbackHandlerType): void;
182
+
183
+ setExecuteHandler(flag: string, handler: ExecuteHandlerType): void;
184
+ clearExecuteHandler(flag: string): void;
185
+ setExecuteHandlerFallback(handler: ExecuteFallbackHandlerType): void;
186
+
187
+ registerCsiHandler(id: IFunctionIdentifier, handler: CsiHandlerType): IDisposable;
188
+ clearCsiHandler(id: IFunctionIdentifier): void;
189
+ setCsiHandlerFallback(callback: CsiFallbackHandlerType): void;
190
+
191
+ registerDcsHandler(id: IFunctionIdentifier, handler: IDcsHandler): IDisposable;
192
+ clearDcsHandler(id: IFunctionIdentifier): void;
193
+ setDcsHandlerFallback(handler: DcsFallbackHandlerType): void;
194
+
195
+ registerOscHandler(ident: number, handler: IOscHandler): IDisposable;
196
+ clearOscHandler(ident: number): void;
197
+ setOscHandlerFallback(handler: OscFallbackHandlerType): void;
198
+
199
+ setErrorHandler(handler: (state: IParsingState) => IParsingState): void;
200
+ clearErrorHandler(): void;
201
+ }
202
+
203
+ /**
204
+ * Subparser interfaces.
205
+ * The subparsers are instantiated in `EscapeSequenceParser` and
206
+ * called during `EscapeSequenceParser.parse`.
207
+ */
208
+ export interface ISubParser<T, U> extends IDisposable {
209
+ reset(): void;
210
+ registerHandler(ident: number, handler: T): IDisposable;
211
+ clearHandler(ident: number): void;
212
+ setHandlerFallback(handler: U): void;
213
+ put(data: Uint32Array, start: number, end: number): void;
214
+ }
215
+
216
+ export interface IOscParser extends ISubParser<IOscHandler, OscFallbackHandlerType> {
217
+ start(): void;
218
+ end(success: boolean, promiseResult?: boolean): void | Promise<boolean>;
219
+ }
220
+
221
+ export interface IDcsParser extends ISubParser<IDcsHandler, DcsFallbackHandlerType> {
222
+ hook(ident: number, params: IParams): void;
223
+ unhook(success: boolean, promiseResult?: boolean): void | Promise<boolean>;
224
+ }
225
+
226
+ /**
227
+ * Interface to denote a specific ESC, CSI or DCS handler slot.
228
+ * The values are used to create an integer respresentation during handler
229
+ * regristation before passed to the subparsers as `ident`.
230
+ * The integer translation is made to allow a faster handler access
231
+ * in `EscapeSequenceParser.parse`.
232
+ */
233
+ export interface IFunctionIdentifier {
234
+ prefix?: string;
235
+ intermediates?: string;
236
+ final: string;
237
+ }
238
+
239
+ export interface IHandlerCollection<T> {
240
+ [key: string]: T[];
241
+ }
242
+
243
+ /**
244
+ * Types for async parser support.
245
+ */
246
+
247
+ // type of saved stack state in parser
248
+ export const enum ParserStackType {
249
+ NONE = 0,
250
+ FAIL,
251
+ RESET,
252
+ CSI,
253
+ ESC,
254
+ OSC,
255
+ DCS
256
+ }
257
+
258
+ // aggregate of resumable handler lists
259
+ export type ResumableHandlersType = CsiHandlerType[] | EscHandlerType[];
260
+
261
+ // saved stack state of the parser
262
+ export interface IParserStackState {
263
+ state: ParserStackType;
264
+ handlers: ResumableHandlersType;
265
+ handlerPos: number;
266
+ transition: number;
267
+ chunkPos: number;
268
+ }
269
+
270
+ // saved stack state of subparser (OSC and DCS)
271
+ export interface ISubParserStackState {
272
+ paused: boolean;
273
+ loopPosition: number;
274
+ fallThrough: boolean;
275
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Copyright (c) 2019 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ */
5
+
6
+ import { ITerminalAddon, IDisposable, Terminal } from '@xterm/xterm';
7
+
8
+ export interface ILoadedAddon {
9
+ instance: ITerminalAddon;
10
+ dispose: () => void;
11
+ isDisposed: boolean;
12
+ }
13
+
14
+ export class AddonManager implements IDisposable {
15
+ protected _addons: ILoadedAddon[] = [];
16
+
17
+ public dispose(): void {
18
+ for (let i = this._addons.length - 1; i >= 0; i--) {
19
+ this._addons[i].instance.dispose();
20
+ }
21
+ }
22
+
23
+ public loadAddon(terminal: Terminal, instance: ITerminalAddon): void {
24
+ const loadedAddon: ILoadedAddon = {
25
+ instance,
26
+ dispose: instance.dispose,
27
+ isDisposed: false
28
+ };
29
+ this._addons.push(loadedAddon);
30
+ instance.dispose = () => this._wrappedAddonDispose(loadedAddon);
31
+ instance.activate(terminal as any);
32
+ }
33
+
34
+ private _wrappedAddonDispose(loadedAddon: ILoadedAddon): void {
35
+ if (loadedAddon.isDisposed) {
36
+ // Do nothing if already disposed
37
+ return;
38
+ }
39
+ let index = -1;
40
+ for (let i = 0; i < this._addons.length; i++) {
41
+ if (this._addons[i] === loadedAddon) {
42
+ index = i;
43
+ break;
44
+ }
45
+ }
46
+ if (index === -1) {
47
+ throw new Error('Could not dispose an addon that has not been loaded');
48
+ }
49
+ loadedAddon.isDisposed = true;
50
+ loadedAddon.dispose.apply(loadedAddon.instance);
51
+ this._addons.splice(index, 1);
52
+ }
53
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Copyright (c) 2021 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ */
5
+
6
+ import { IBuffer as IBufferApi, IBufferLine as IBufferLineApi, IBufferCell as IBufferCellApi } from '@xterm/xterm';
7
+ import { IBuffer } from 'common/buffer/Types';
8
+ import { BufferLineApiView } from 'common/public/BufferLineApiView';
9
+ import { CellData } from 'common/buffer/CellData';
10
+
11
+ export class BufferApiView implements IBufferApi {
12
+ constructor(
13
+ private _buffer: IBuffer,
14
+ public readonly type: 'normal' | 'alternate'
15
+ ) { }
16
+
17
+ public init(buffer: IBuffer): BufferApiView {
18
+ this._buffer = buffer;
19
+ return this;
20
+ }
21
+
22
+ public get cursorY(): number { return this._buffer.y; }
23
+ public get cursorX(): number { return this._buffer.x; }
24
+ public get viewportY(): number { return this._buffer.ydisp; }
25
+ public get baseY(): number { return this._buffer.ybase; }
26
+ public get length(): number { return this._buffer.lines.length; }
27
+ public getLine(y: number): IBufferLineApi | undefined {
28
+ const line = this._buffer.lines.get(y);
29
+ if (!line) {
30
+ return undefined;
31
+ }
32
+ return new BufferLineApiView(line);
33
+ }
34
+ public getNullCell(): IBufferCellApi { return new CellData(); }
35
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Copyright (c) 2021 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ */
5
+
6
+ import { CellData } from 'common/buffer/CellData';
7
+ import { IBufferLine, ICellData } from 'common/Types';
8
+ import { IBufferCell as IBufferCellApi, IBufferLine as IBufferLineApi } from '@xterm/xterm';
9
+
10
+ export class BufferLineApiView implements IBufferLineApi {
11
+ constructor(private _line: IBufferLine) { }
12
+
13
+ public get isWrapped(): boolean { return this._line.isWrapped; }
14
+ public get length(): number { return this._line.length; }
15
+ public getCell(x: number, cell?: IBufferCellApi): IBufferCellApi | undefined {
16
+ if (x < 0 || x >= this._line.length) {
17
+ return undefined;
18
+ }
19
+
20
+ if (cell) {
21
+ this._line.loadCell(x, cell as ICellData);
22
+ return cell;
23
+ }
24
+ return this._line.loadCell(x, new CellData());
25
+ }
26
+ public translateToString(trimRight?: boolean, startColumn?: number, endColumn?: number): string {
27
+ return this._line.translateToString(trimRight, startColumn, endColumn);
28
+ }
29
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Copyright (c) 2021 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ */
5
+
6
+ import { IBuffer as IBufferApi, IBufferNamespace as IBufferNamespaceApi } from '@xterm/xterm';
7
+ import { BufferApiView } from 'common/public/BufferApiView';
8
+ import { EventEmitter } from 'common/EventEmitter';
9
+ import { ICoreTerminal } from 'common/Types';
10
+ import { Disposable } from 'common/Lifecycle';
11
+
12
+ export class BufferNamespaceApi extends Disposable implements IBufferNamespaceApi {
13
+ private _normal: BufferApiView;
14
+ private _alternate: BufferApiView;
15
+
16
+ private readonly _onBufferChange = this.register(new EventEmitter<IBufferApi>());
17
+ public readonly onBufferChange = this._onBufferChange.event;
18
+
19
+ constructor(private _core: ICoreTerminal) {
20
+ super();
21
+ this._normal = new BufferApiView(this._core.buffers.normal, 'normal');
22
+ this._alternate = new BufferApiView(this._core.buffers.alt, 'alternate');
23
+ this._core.buffers.onBufferActivate(() => this._onBufferChange.fire(this.active));
24
+ }
25
+ public get active(): IBufferApi {
26
+ if (this._core.buffers.active === this._core.buffers.normal) { return this.normal; }
27
+ if (this._core.buffers.active === this._core.buffers.alt) { return this.alternate; }
28
+ throw new Error('Active buffer is neither normal nor alternate');
29
+ }
30
+ public get normal(): IBufferApi {
31
+ return this._normal.init(this._core.buffers.normal);
32
+ }
33
+ public get alternate(): IBufferApi {
34
+ return this._alternate.init(this._core.buffers.alt);
35
+ }
36
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Copyright (c) 2021 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ */
5
+
6
+ import { IParams } from 'common/parser/Types';
7
+ import { IDisposable, IFunctionIdentifier, IParser } from '@xterm/xterm';
8
+ import { ICoreTerminal } from 'common/Types';
9
+
10
+ export class ParserApi implements IParser {
11
+ constructor(private _core: ICoreTerminal) { }
12
+
13
+ public registerCsiHandler(id: IFunctionIdentifier, callback: (params: (number | number[])[]) => boolean | Promise<boolean>): IDisposable {
14
+ return this._core.registerCsiHandler(id, (params: IParams) => callback(params.toArray()));
15
+ }
16
+ public addCsiHandler(id: IFunctionIdentifier, callback: (params: (number | number[])[]) => boolean | Promise<boolean>): IDisposable {
17
+ return this.registerCsiHandler(id, callback);
18
+ }
19
+ public registerDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: (number | number[])[]) => boolean | Promise<boolean>): IDisposable {
20
+ return this._core.registerDcsHandler(id, (data: string, params: IParams) => callback(data, params.toArray()));
21
+ }
22
+ public addDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: (number | number[])[]) => boolean | Promise<boolean>): IDisposable {
23
+ return this.registerDcsHandler(id, callback);
24
+ }
25
+ public registerEscHandler(id: IFunctionIdentifier, handler: () => boolean | Promise<boolean>): IDisposable {
26
+ return this._core.registerEscHandler(id, handler);
27
+ }
28
+ public addEscHandler(id: IFunctionIdentifier, handler: () => boolean | Promise<boolean>): IDisposable {
29
+ return this.registerEscHandler(id, handler);
30
+ }
31
+ public registerOscHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable {
32
+ return this._core.registerOscHandler(ident, callback);
33
+ }
34
+ public addOscHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable {
35
+ return this.registerOscHandler(ident, callback);
36
+ }
37
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Copyright (c) 2021 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ */
5
+
6
+ import { ICoreTerminal } from 'common/Types';
7
+ import { IUnicodeHandling, IUnicodeVersionProvider } from '@xterm/xterm';
8
+
9
+ export class UnicodeApi implements IUnicodeHandling {
10
+ constructor(private _core: ICoreTerminal) { }
11
+
12
+ public register(provider: IUnicodeVersionProvider): void {
13
+ this._core.unicodeService.register(provider);
14
+ }
15
+
16
+ public get versions(): string[] {
17
+ return this._core.unicodeService.versions;
18
+ }
19
+
20
+ public get activeVersion(): string {
21
+ return this._core.unicodeService.activeVersion;
22
+ }
23
+
24
+ public set activeVersion(version: string) {
25
+ this._core.unicodeService.activeVersion = version;
26
+ }
27
+ }
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Copyright (c) 2019 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ */
5
+
6
+ import { EventEmitter } from 'common/EventEmitter';
7
+ import { Disposable } from 'common/Lifecycle';
8
+ import { IAttributeData, IBufferLine, ScrollSource } from 'common/Types';
9
+ import { BufferSet } from 'common/buffer/BufferSet';
10
+ import { IBuffer, IBufferSet } from 'common/buffer/Types';
11
+ import { IBufferService, IOptionsService } from 'common/services/Services';
12
+
13
+ export const MINIMUM_COLS = 2; // Less than 2 can mess with wide chars
14
+ export const MINIMUM_ROWS = 1;
15
+
16
+ export class BufferService extends Disposable implements IBufferService {
17
+ public serviceBrand: any;
18
+
19
+ public cols: number;
20
+ public rows: number;
21
+ public buffers: IBufferSet;
22
+ /** Whether the user is scrolling (locks the scroll position) */
23
+ public isUserScrolling: boolean = false;
24
+
25
+ private readonly _onResize = this.register(new EventEmitter<{ cols: number, rows: number }>());
26
+ public readonly onResize = this._onResize.event;
27
+ private readonly _onScroll = this.register(new EventEmitter<number>());
28
+ public readonly onScroll = this._onScroll.event;
29
+
30
+ public get buffer(): IBuffer { return this.buffers.active; }
31
+
32
+ /** An IBufferline to clone/copy from for new blank lines */
33
+ private _cachedBlankLine: IBufferLine | undefined;
34
+
35
+ constructor(@IOptionsService optionsService: IOptionsService) {
36
+ super();
37
+ this.cols = Math.max(optionsService.rawOptions.cols || 0, MINIMUM_COLS);
38
+ this.rows = Math.max(optionsService.rawOptions.rows || 0, MINIMUM_ROWS);
39
+ this.buffers = this.register(new BufferSet(optionsService, this));
40
+ }
41
+
42
+ public resize(cols: number, rows: number): void {
43
+ this.cols = cols;
44
+ this.rows = rows;
45
+ this.buffers.resize(cols, rows);
46
+ // TODO: This doesn't fire when scrollback changes - add a resize event to BufferSet and forward
47
+ // event
48
+ this._onResize.fire({ cols, rows });
49
+ }
50
+
51
+ public reset(): void {
52
+ this.buffers.reset();
53
+ this.isUserScrolling = false;
54
+ }
55
+
56
+ /**
57
+ * Scroll the terminal down 1 row, creating a blank line.
58
+ * @param eraseAttr The attribute data to use the for blank line.
59
+ * @param isWrapped Whether the new line is wrapped from the previous line.
60
+ */
61
+ public scroll(eraseAttr: IAttributeData, isWrapped: boolean = false): void {
62
+ const buffer = this.buffer;
63
+
64
+ let newLine: IBufferLine | undefined;
65
+ newLine = this._cachedBlankLine;
66
+ if (!newLine || newLine.length !== this.cols || newLine.getFg(0) !== eraseAttr.fg || newLine.getBg(0) !== eraseAttr.bg) {
67
+ newLine = buffer.getBlankLine(eraseAttr, isWrapped);
68
+ this._cachedBlankLine = newLine;
69
+ }
70
+ newLine.isWrapped = isWrapped;
71
+
72
+ const topRow = buffer.ybase + buffer.scrollTop;
73
+ const bottomRow = buffer.ybase + buffer.scrollBottom;
74
+
75
+ if (buffer.scrollTop === 0) {
76
+ // Determine whether the buffer is going to be trimmed after insertion.
77
+ const willBufferBeTrimmed = buffer.lines.isFull;
78
+
79
+ // Insert the line using the fastest method
80
+ if (bottomRow === buffer.lines.length - 1) {
81
+ if (willBufferBeTrimmed) {
82
+ buffer.lines.recycle().copyFrom(newLine);
83
+ } else {
84
+ buffer.lines.push(newLine.clone());
85
+ }
86
+ } else {
87
+ buffer.lines.splice(bottomRow + 1, 0, newLine.clone());
88
+ }
89
+
90
+ // Only adjust ybase and ydisp when the buffer is not trimmed
91
+ if (!willBufferBeTrimmed) {
92
+ buffer.ybase++;
93
+ // Only scroll the ydisp with ybase if the user has not scrolled up
94
+ if (!this.isUserScrolling) {
95
+ buffer.ydisp++;
96
+ }
97
+ } else {
98
+ // When the buffer is full and the user has scrolled up, keep the text
99
+ // stable unless ydisp is right at the top
100
+ if (this.isUserScrolling) {
101
+ buffer.ydisp = Math.max(buffer.ydisp - 1, 0);
102
+ }
103
+ }
104
+ } else {
105
+ // scrollTop is non-zero which means no line will be going to the
106
+ // scrollback, instead we can just shift them in-place.
107
+ const scrollRegionHeight = bottomRow - topRow + 1 /* as it's zero-based */;
108
+ buffer.lines.shiftElements(topRow + 1, scrollRegionHeight - 1, -1);
109
+ buffer.lines.set(bottomRow, newLine.clone());
110
+ }
111
+
112
+ // Move the viewport to the bottom of the buffer unless the user is
113
+ // scrolling.
114
+ if (!this.isUserScrolling) {
115
+ buffer.ydisp = buffer.ybase;
116
+ }
117
+
118
+ this._onScroll.fire(buffer.ydisp);
119
+ }
120
+
121
+ /**
122
+ * Scroll the display of the terminal
123
+ * @param disp The number of lines to scroll down (negative scroll up).
124
+ * @param suppressScrollEvent Don't emit the scroll event as scrollLines. This is used
125
+ * to avoid unwanted events being handled by the viewport when the event was triggered from the
126
+ * viewport originally.
127
+ */
128
+ public scrollLines(disp: number, suppressScrollEvent?: boolean, source?: ScrollSource): void {
129
+ const buffer = this.buffer;
130
+ if (disp < 0) {
131
+ if (buffer.ydisp === 0) {
132
+ return;
133
+ }
134
+ this.isUserScrolling = true;
135
+ } else if (disp + buffer.ydisp >= buffer.ybase) {
136
+ this.isUserScrolling = false;
137
+ }
138
+
139
+ const oldYdisp = buffer.ydisp;
140
+ buffer.ydisp = Math.max(Math.min(buffer.ydisp + disp, buffer.ybase), 0);
141
+
142
+ // No change occurred, don't trigger scroll/refresh
143
+ if (oldYdisp === buffer.ydisp) {
144
+ return;
145
+ }
146
+
147
+ if (!suppressScrollEvent) {
148
+ this._onScroll.fire(buffer.ydisp);
149
+ }
150
+ }
151
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Copyright (c) 2019 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ */
5
+
6
+ import { ICharsetService } from 'common/services/Services';
7
+ import { ICharset } from 'common/Types';
8
+
9
+ export class CharsetService implements ICharsetService {
10
+ public serviceBrand: any;
11
+
12
+ public charset: ICharset | undefined;
13
+ public glevel: number = 0;
14
+
15
+ private _charsets: (ICharset | undefined)[] = [];
16
+
17
+ public reset(): void {
18
+ this.charset = undefined;
19
+ this._charsets = [];
20
+ this.glevel = 0;
21
+ }
22
+
23
+ public setgLevel(g: number): void {
24
+ this.glevel = g;
25
+ this.charset = this._charsets[g];
26
+ }
27
+
28
+ public setgCharset(g: number, charset: ICharset | undefined): void {
29
+ this._charsets[g] = charset;
30
+ if (this.glevel === g) {
31
+ this.charset = charset;
32
+ }
33
+ }
34
+ }