Debian Codegraph @

node/@xterm/xterm/src/common/Types.ts

raw
1 /**
2 * Copyright (c) 2018 The xterm.js authors. All rights reserved.
3 * @license MIT
4 */
5
6 import { IDeleteEvent, IInsertEvent } from 'common/CircularList';
7 import { Attributes, UnderlineStyle } from 'common/buffer/Constants'; // eslint-disable-line no-unused-vars
8 import { IBufferSet } from 'common/buffer/Types';
9 import { IParams } from 'common/parser/Types';
10 import { ICoreMouseService, ICoreService, IOptionsService, IUnicodeService } from 'common/services/Services';
11 import { IFunctionIdentifier, ITerminalOptions as IPublicTerminalOptions } from '@xterm/xterm';
12 import type { Emitter, Event } from 'vs/base/common/event';
13
14 export interface ICoreTerminal {
15 coreMouseService: ICoreMouseService;
16 coreService: ICoreService;
17 optionsService: IOptionsService;
18 unicodeService: IUnicodeService;
19 buffers: IBufferSet;
20 options: Required<ITerminalOptions>;
21 registerCsiHandler(id: IFunctionIdentifier, callback: (params: IParams) => boolean | Promise<boolean>): IDisposable;
22 registerDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: IParams) => boolean | Promise<boolean>): IDisposable;
23 registerEscHandler(id: IFunctionIdentifier, callback: () => boolean | Promise<boolean>): IDisposable;
24 registerOscHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable;
25 }
26
27 export interface IDisposable {
28 dispose(): void;
29 }
30
31 // TODO: The options that are not in the public API should be reviewed
32 export interface ITerminalOptions extends IPublicTerminalOptions {
33 [key: string]: any;
34 cancelEvents?: boolean;
35 convertEol?: boolean;
36 termName?: string;
37 }
38
39 export type CursorStyle = 'block' | 'underline' | 'bar';
40
41 export type CursorInactiveStyle = 'outline' | 'block' | 'bar' | 'underline' | 'none';
42
43 export type XtermListener = (...args: any[]) => void;
44
45 /**
46 * A keyboard event interface which does not depend on the DOM, KeyboardEvent implicitly extends
47 * this event.
48 */
49 export interface IKeyboardEvent {
50 altKey: boolean;
51 ctrlKey: boolean;
52 shiftKey: boolean;
53 metaKey: boolean;
54 /** @deprecated See KeyboardEvent.keyCode */
55 keyCode: number;
56 key: string;
57 type: string;
58 code: string;
59 }
60
61 export interface IScrollEvent {
62 position: number;
63 }
64
65 export interface ICircularList<T> {
66 length: number;
67 maxLength: number;
68 isFull: boolean;
69
70 onDeleteEmitter: Emitter<IDeleteEvent>;
71 onDelete: Event<IDeleteEvent>;
72 onInsertEmitter: Emitter<IInsertEvent>;
73 onInsert: Event<IInsertEvent>;
74 onTrimEmitter: Emitter<number>;
75 onTrim: Event<number>;
76
77 get(index: number): T | undefined;
78 set(index: number, value: T): void;
79 push(value: T): void;
80 recycle(): T;
81 pop(): T | undefined;
82 splice(start: number, deleteCount: number, ...items: T[]): void;
83 trimStart(count: number): void;
84 shiftElements(start: number, count: number, offset: number): void;
85 }
86
87 export const enum KeyboardResultType {
88 SEND_KEY,
89 SELECT_ALL,
90 PAGE_UP,
91 PAGE_DOWN
92 }
93
94 export interface IKeyboardResult {
95 type: KeyboardResultType;
96 cancel: boolean;
97 key: string | undefined;
98 }
99
100 export interface ICharset {
101 [key: string]: string | undefined;
102 }
103
104 export type CharData = [number, string, number, number];
105
106 export interface IColor {
107 readonly css: string;
108 readonly rgba: number; // 32-bit int with rgba in each byte
109 }
110 export type IColorRGB = [number, number, number];
111
112 export interface IExtendedAttrs {
113 ext: number;
114 underlineStyle: UnderlineStyle;
115 underlineColor: number;
116 underlineVariantOffset: number;
117 urlId: number;
118 clone(): IExtendedAttrs;
119 isEmpty(): boolean;
120 }
121
122 /**
123 * Tracks the current hyperlink. Since these are treated as extended attirbutes, these get passed on
124 * to the linkifier when anything is printed. Doing it this way ensures that even when the cursor
125 * moves around unexpectedly the link is tracked, as opposed to using a start position and
126 * finalizing it at the end.
127 */
128 export interface IOscLinkData {
129 id?: string;
130 uri: string;
131 }
132
133 /**
134 * An object that represents all attributes of a cell.
135 */
136 export interface IAttributeData {
137 /**
138 * "fg" is a 32-bit unsigned integer that stores the foreground color of the cell in the 24 least
139 * significant bits and additional flags in the remaining 8 bits.
140 */
141 fg: number;
142 /**
143 * "bg" is a 32-bit unsigned integer that stores the background color of the cell in the 24 least
144 * significant bits and additional flags in the remaining 8 bits.
145 */
146 bg: number;
147 /**
148 * "extended", aka "ext", stores extended attributes beyond those available in fg and bg. This
149 * data is optional on a cell and encodes less common data.
150 */
151 extended: IExtendedAttrs;
152
153 clone(): IAttributeData;
154
155 // flags
156 isInverse(): number;
157 isBold(): number;
158 isUnderline(): number;
159 isBlink(): number;
160 isInvisible(): number;
161 isItalic(): number;
162 isDim(): number;
163 isStrikethrough(): number;
164 isProtected(): number;
165 isOverline(): number;
166
167 /**
168 * The color mode of the foreground color which determines how to decode {@link getFgColor},
169 * possible values include {@link Attributes.CM_DEFAULT}, {@link Attributes.CM_P16},
170 * {@link Attributes.CM_P256} and {@link Attributes.CM_RGB}.
171 */
172 getFgColorMode(): number;
173 /**
174 * The color mode of the background color which determines how to decode {@link getBgColor},
175 * possible values include {@link Attributes.CM_DEFAULT}, {@link Attributes.CM_P16},
176 * {@link Attributes.CM_P256} and {@link Attributes.CM_RGB}.
177 */
178 getBgColorMode(): number;
179 isFgRGB(): boolean;
180 isBgRGB(): boolean;
181 isFgPalette(): boolean;
182 isBgPalette(): boolean;
183 isFgDefault(): boolean;
184 isBgDefault(): boolean;
185 isAttributeDefault(): boolean;
186
187 /**
188 * Gets an integer representation of the foreground color, how to decode the color depends on the
189 * color mode {@link getFgColorMode}.
190 */
191 getFgColor(): number;
192 /**
193 * Gets an integer representation of the background color, how to decode the color depends on the
194 * color mode {@link getBgColorMode}.
195 */
196 getBgColor(): number;
197
198 // extended attrs
199 hasExtendedAttrs(): number;
200 updateExtended(): void;
201 getUnderlineColor(): number;
202 getUnderlineColorMode(): number;
203 isUnderlineColorRGB(): boolean;
204 isUnderlineColorPalette(): boolean;
205 isUnderlineColorDefault(): boolean;
206 getUnderlineStyle(): number;
207 getUnderlineVariantOffset(): number;
208 }
209
210 /** Cell data */
211 export interface ICellData extends IAttributeData {
212 content: number;
213 combinedData: string;
214 isCombined(): number;
215 getWidth(): number;
216 getChars(): string;
217 getCode(): number;
218 setFromCharData(value: CharData): void;
219 getAsCharData(): CharData;
220 }
221
222 /**
223 * Interface for a line in the terminal buffer.
224 */
225 export interface IBufferLine {
226 length: number;
227 isWrapped: boolean;
228 get(index: number): CharData;
229 set(index: number, value: CharData): void;
230 loadCell(index: number, cell: ICellData): ICellData;
231 setCell(index: number, cell: ICellData): void;
232 setCellFromCodepoint(index: number, codePoint: number, width: number, attrs: IAttributeData): void;
233 addCodepointToCell(index: number, codePoint: number, width: number): void;
234 insertCells(pos: number, n: number, ch: ICellData): void;
235 deleteCells(pos: number, n: number, fill: ICellData): void;
236 replaceCells(start: number, end: number, fill: ICellData, respectProtect?: boolean): void;
237 resize(cols: number, fill: ICellData): boolean;
238 cleanupMemory(): number;
239 fill(fillCellData: ICellData, respectProtect?: boolean): void;
240 copyFrom(line: IBufferLine): void;
241 clone(): IBufferLine;
242 getTrimmedLength(): number;
243 getNoBgTrimmedLength(): number;
244 translateToString(trimRight?: boolean, startCol?: number, endCol?: number, outColumns?: number[]): string;
245
246 /* direct access to cell attrs */
247 getWidth(index: number): number;
248 hasWidth(index: number): number;
249 getFg(index: number): number;
250 getBg(index: number): number;
251 hasContent(index: number): number;
252 getCodePoint(index: number): number;
253 isCombined(index: number): number;
254 getString(index: number): string;
255 }
256
257 export interface IMarker extends IDisposable {
258 readonly id: number;
259 readonly isDisposed: boolean;
260 readonly line: number;
261 onDispose: Event<void>;
262 }
263 export interface IModes {
264 insertMode: boolean;
265 }
266
267 export interface IDecPrivateModes {
268 applicationCursorKeys: boolean;
269 applicationKeypad: boolean;
270 bracketedPasteMode: boolean;
271 cursorBlink: boolean | undefined;
272 cursorStyle: CursorStyle | undefined;
273 origin: boolean;
274 reverseWraparound: boolean;
275 sendFocus: boolean;
276 synchronizedOutput: boolean;
277 wraparound: boolean; // defaults: xterm - true, vt100 - false
278 }
279
280 export interface IRowRange {
281 start: number;
282 end: number;
283 }
284
285 /**
286 * Interface for mouse events in the core.
287 */
288 export const enum CoreMouseButton {
289 LEFT = 0,
290 MIDDLE = 1,
291 RIGHT = 2,
292 NONE = 3,
293 WHEEL = 4,
294 // additional buttons 1..8
295 // untested!
296 AUX1 = 8,
297 AUX2 = 9,
298 AUX3 = 10,
299 AUX4 = 11,
300 AUX5 = 12,
301 AUX6 = 13,
302 AUX7 = 14,
303 AUX8 = 15
304 }
305
306 export const enum CoreMouseAction {
307 UP = 0, // buttons, wheel
308 DOWN = 1, // buttons, wheel
309 LEFT = 2, // wheel only
310 RIGHT = 3, // wheel only
311 MOVE = 32 // buttons only
312 }
313
314 export interface ICoreMouseEvent {
315 /** column (zero based). */
316 col: number;
317 /** row (zero based). */
318 row: number;
319 /** xy pixel positions. */
320 x: number;
321 y: number;
322 /**
323 * Button the action occured. Due to restrictions of the tracking protocols
324 * it is not possible to report multiple buttons at once.
325 * Wheel is treated as a button.
326 * There are invalid combinations of buttons and actions possible
327 * (like move + wheel), those are silently ignored by the CoreMouseService.
328 */
329 button: CoreMouseButton;
330 action: CoreMouseAction;
331 /**
332 * Modifier states.
333 * Protocols will add/ignore those based on specific restrictions.
334 */
335 ctrl?: boolean;
336 alt?: boolean;
337 shift?: boolean;
338 }
339
340 /**
341 * CoreMouseEventType
342 * To be reported to the browser component which events a mouse
343 * protocol wants to be catched and forwarded as an ICoreMouseEvent
344 * to CoreMouseService.
345 */
346 export const enum CoreMouseEventType {
347 NONE = 0,
348 /** any mousedown event */
349 DOWN = 1,
350 /** any mouseup event */
351 UP = 2,
352 /** any mousemove event while a button is held */
353 DRAG = 4,
354 /** any mousemove event without a button */
355 MOVE = 8,
356 /** any wheel event */
357 WHEEL = 16
358 }
359
360 /**
361 * Mouse protocol interface.
362 * A mouse protocol can be registered and activated at the CoreMouseService.
363 * `events` should contain a list of needed events as a hint for the browser component
364 * to install/remove the appropriate event handlers.
365 * `restrict` applies further protocol specific restrictions like not allowed
366 * modifiers or filtering invalid event types.
367 */
368 export interface ICoreMouseProtocol {
369 events: CoreMouseEventType;
370 restrict: (e: ICoreMouseEvent) => boolean;
371 }
372
373 /**
374 * CoreMouseEncoding
375 * The tracking encoding can be registered and activated at the CoreMouseService.
376 * If a ICoreMouseEvent passes all procotol restrictions it will be encoded
377 * with the active encoding and sent out.
378 * Note: Returning an empty string will supress sending a mouse report,
379 * which can be used to skip creating falsey reports in limited encodings
380 * (DEFAULT only supports up to 223 1-based as coord value).
381 */
382 export type CoreMouseEncoding = (event: ICoreMouseEvent) => string;
383
384 /**
385 * windowOptions
386 */
387 export interface IWindowOptions {
388 restoreWin?: boolean;
389 minimizeWin?: boolean;
390 setWinPosition?: boolean;
391 setWinSizePixels?: boolean;
392 raiseWin?: boolean;
393 lowerWin?: boolean;
394 refreshWin?: boolean;
395 setWinSizeChars?: boolean;
396 maximizeWin?: boolean;
397 fullscreenWin?: boolean;
398 getWinState?: boolean;
399 getWinPosition?: boolean;
400 getWinSizePixels?: boolean;
401 getScreenSizePixels?: boolean;
402 getCellSizePixels?: boolean;
403 getWinSizeChars?: boolean;
404 getScreenSizeChars?: boolean;
405 getIconTitle?: boolean;
406 getWinTitle?: boolean;
407 pushTitle?: boolean;
408 popTitle?: boolean;
409 setWinLines?: boolean;
410 }
411
412 // color events from common, used for OSC 4/10/11/12 and 104/110/111/112
413 export const enum ColorRequestType {
414 REPORT = 0,
415 SET = 1,
416 RESTORE = 2
417 }
418
419 // IntRange from https://stackoverflow.com/a/39495173
420 type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N
421 ? Acc[number]
422 : Enumerate<N, [...Acc, Acc['length']]>;
423 type IntRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
424
425 export type ColorIndex = IntRange<0, 256>; // number from 0 to 255
426 export type AllColorIndex = ColorIndex | SpecialColorIndex;
427 export const enum SpecialColorIndex {
428 FOREGROUND = 256,
429 BACKGROUND = 257,
430 CURSOR = 258
431 }
432 export interface IColorReportRequest {
433 type: ColorRequestType.REPORT;
434 index: AllColorIndex;
435 }
436 export interface IColorSetRequest {
437 type: ColorRequestType.SET;
438 index: AllColorIndex;
439 color: IColorRGB;
440 }
441 export interface IColorRestoreRequest {
442 type: ColorRequestType.RESTORE;
443 index?: AllColorIndex;
444 }
445 export type IColorEvent = (IColorReportRequest | IColorSetRequest | IColorRestoreRequest)[];
446
447
448 /**
449 * Calls the parser and handles actions generated by the parser.
450 */
451 export interface IInputHandler {
452 onTitleChange: Event<string>;
453
454 parse(data: string | Uint8Array, promiseResult?: boolean): void | Promise<boolean>;
455 print(data: Uint32Array, start: number, end: number): void;
456 registerCsiHandler(id: IFunctionIdentifier, callback: (params: IParams) => boolean | Promise<boolean>): IDisposable;
457 registerDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: IParams) => boolean | Promise<boolean>): IDisposable;
458 registerEscHandler(id: IFunctionIdentifier, callback: () => boolean | Promise<boolean>): IDisposable;
459 registerOscHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable;
460
461 /** C0 BEL */ bell(): boolean;
462 /** C0 LF */ lineFeed(): boolean;
463 /** C0 CR */ carriageReturn(): boolean;
464 /** C0 BS */ backspace(): boolean;
465 /** C0 HT */ tab(): boolean;
466 /** C0 SO */ shiftOut(): boolean;
467 /** C0 SI */ shiftIn(): boolean;
468
469 /** CSI @ */ insertChars(params: IParams): boolean;
470 /** CSI SP @ */ scrollLeft(params: IParams): boolean;
471 /** CSI A */ cursorUp(params: IParams): boolean;
472 /** CSI SP A */ scrollRight(params: IParams): boolean;
473 /** CSI B */ cursorDown(params: IParams): boolean;
474 /** CSI C */ cursorForward(params: IParams): boolean;
475 /** CSI D */ cursorBackward(params: IParams): boolean;
476 /** CSI E */ cursorNextLine(params: IParams): boolean;
477 /** CSI F */ cursorPrecedingLine(params: IParams): boolean;
478 /** CSI G */ cursorCharAbsolute(params: IParams): boolean;
479 /** CSI H */ cursorPosition(params: IParams): boolean;
480 /** CSI I */ cursorForwardTab(params: IParams): boolean;
481 /** CSI J */ eraseInDisplay(params: IParams): boolean;
482 /** CSI K */ eraseInLine(params: IParams): boolean;
483 /** CSI L */ insertLines(params: IParams): boolean;
484 /** CSI M */ deleteLines(params: IParams): boolean;
485 /** CSI P */ deleteChars(params: IParams): boolean;
486 /** CSI S */ scrollUp(params: IParams): boolean;
487 /** CSI T */ scrollDown(params: IParams, collect?: string): boolean;
488 /** CSI X */ eraseChars(params: IParams): boolean;
489 /** CSI Z */ cursorBackwardTab(params: IParams): boolean;
490 /** CSI ` */ charPosAbsolute(params: IParams): boolean;
491 /** CSI a */ hPositionRelative(params: IParams): boolean;
492 /** CSI b */ repeatPrecedingCharacter(params: IParams): boolean;
493 /** CSI c */ sendDeviceAttributesPrimary(params: IParams): boolean;
494 /** CSI > c */ sendDeviceAttributesSecondary(params: IParams): boolean;
495 /** CSI d */ linePosAbsolute(params: IParams): boolean;
496 /** CSI e */ vPositionRelative(params: IParams): boolean;
497 /** CSI f */ hVPosition(params: IParams): boolean;
498 /** CSI g */ tabClear(params: IParams): boolean;
499 /** CSI h */ setMode(params: IParams, collect?: string): boolean;
500 /** CSI l */ resetMode(params: IParams, collect?: string): boolean;
501 /** CSI m */ charAttributes(params: IParams): boolean;
502 /** CSI n */ deviceStatus(params: IParams, collect?: string): boolean;
503 /** CSI p */ softReset(params: IParams, collect?: string): boolean;
504 /** CSI q */ setCursorStyle(params: IParams, collect?: string): boolean;
505 /** CSI r */ setScrollRegion(params: IParams, collect?: string): boolean;
506 /** CSI s */ saveCursor(params: IParams): boolean;
507 /** CSI u */ restoreCursor(params: IParams): boolean;
508 /** CSI ' } */ insertColumns(params: IParams): boolean;
509 /** CSI ' ~ */ deleteColumns(params: IParams): boolean;
510
511 /** OSC 0
512 OSC 2 */ setTitle(data: string): boolean;
513 /** OSC 4 */ setOrReportIndexedColor(data: string): boolean;
514 /** OSC 10 */ setOrReportFgColor(data: string): boolean;
515 /** OSC 11 */ setOrReportBgColor(data: string): boolean;
516 /** OSC 12 */ setOrReportCursorColor(data: string): boolean;
517 /** OSC 104 */ restoreIndexedColor(data: string): boolean;
518 /** OSC 110 */ restoreFgColor(data: string): boolean;
519 /** OSC 111 */ restoreBgColor(data: string): boolean;
520 /** OSC 112 */ restoreCursorColor(data: string): boolean;
521
522 /** ESC E */ nextLine(): boolean;
523 /** ESC = */ keypadApplicationMode(): boolean;
524 /** ESC > */ keypadNumericMode(): boolean;
525 /** ESC % G
526 ESC % @ */ selectDefaultCharset(): boolean;
527 /** ESC ( C
528 ESC ) C
529 ESC * C
530 ESC + C
531 ESC - C
532 ESC . C
533 ESC / C */ selectCharset(collectAndFlag: string): boolean;
534 /** ESC D */ index(): boolean;
535 /** ESC H */ tabSet(): boolean;
536 /** ESC M */ reverseIndex(): boolean;
537 /** ESC c */ fullReset(): boolean;
538 /** ESC n
539 ESC o
540 ESC |
541 ESC }
542 ESC ~ */ setgLevel(level: number): boolean;
543 /** ESC # 8 */ screenAlignmentPattern(): boolean;
544 }
545
546 export interface IParseStack {
547 paused: boolean;
548 cursorStartX: number;
549 cursorStartY: number;
550 decodedLength: number;
551 position: number;
552 }