xterm
[VSoRC/.git] / node_modules / xterm / src / Types.d.ts
1 /**
2  * Copyright (c) 2017 The xterm.js authors. All rights reserved.
3  * @license MIT
4  */
5
6 import { ITerminalOptions as IPublicTerminalOptions, IDisposable, IMarker, ISelectionPosition } from 'xterm';
7 import { ICharset, IAttributeData, CharData, CoreMouseEventType } from 'common/Types';
8 import { IEvent, IEventEmitter } from 'common/EventEmitter';
9 import { IColorSet, ILinkifier, ILinkMatcherOptions, IViewport } from 'browser/Types';
10 import { IOptionsService } from 'common/services/Services';
11 import { IBuffer, IBufferSet } from 'common/buffer/Types';
12 import { IParams, IFunctionIdentifier } from 'common/parser/Types';
13
14 export type CustomKeyEventHandler = (event: KeyboardEvent) => boolean;
15
16 export type LineData = CharData[];
17
18 /**
19  * This interface encapsulates everything needed from the Terminal by the
20  * InputHandler. This cleanly separates the large amount of methods needed by
21  * InputHandler cleanly from the ITerminal interface.
22  */
23 export interface IInputHandlingTerminal {
24   element: HTMLElement;
25   options: ITerminalOptions;
26   cols: number;
27   rows: number;
28   charset: ICharset;
29   gcharset: number;
30   glevel: number;
31   charsets: ICharset[];
32   applicationKeypad: boolean;
33   originMode: boolean;
34   insertMode: boolean;
35   wraparoundMode: boolean;
36   bracketedPasteMode: boolean;
37   curAttrData: IAttributeData;
38   savedCols: number;
39   mouseEvents: CoreMouseEventType;
40   sendFocus: boolean;
41   cursorHidden: boolean;
42
43   buffers: IBufferSet;
44   buffer: IBuffer;
45   viewport: IViewport;
46
47   onA11yCharEmitter: IEventEmitter<string>;
48   onA11yTabEmitter: IEventEmitter<number>;
49
50   bell(): void;
51   focus(): void;
52   scroll(isWrapped?: boolean): void;
53   setgLevel(g: number): void;
54   eraseAttrData(): IAttributeData;
55   is(term: string): boolean;
56   setgCharset(g: number, charset: ICharset): void;
57   resize(x: number, y: number): void;
58   reset(): void;
59   showCursor(): void;
60   refresh(start: number, end: number): void;
61   handleTitle(title: string): void;
62 }
63
64 export interface ICompositionHelper {
65   compositionstart(): void;
66   compositionupdate(ev: CompositionEvent): void;
67   compositionend(): void;
68   updateCompositionElements(dontRecurse?: boolean): void;
69   keydown(ev: KeyboardEvent): boolean;
70 }
71
72 /**
73  * Calls the parser and handles actions generated by the parser.
74  */
75 export interface IInputHandler {
76   parse(data: string | Uint8Array): void;
77   print(data: Uint32Array, start: number, end: number): void;
78
79   /** C0 BEL */ bell(): void;
80   /** C0 LF */ lineFeed(): void;
81   /** C0 CR */ carriageReturn(): void;
82   /** C0 BS */ backspace(): void;
83   /** C0 HT */ tab(): void;
84   /** C0 SO */ shiftOut(): void;
85   /** C0 SI */ shiftIn(): void;
86
87   /** CSI @ */ insertChars(params: IParams): void;
88   /** CSI SP @ */ scrollLeft(params: IParams): void;
89   /** CSI A */ cursorUp(params: IParams): void;
90   /** CSI SP A */ scrollRight(params: IParams): void;
91   /** CSI B */ cursorDown(params: IParams): void;
92   /** CSI C */ cursorForward(params: IParams): void;
93   /** CSI D */ cursorBackward(params: IParams): void;
94   /** CSI E */ cursorNextLine(params: IParams): void;
95   /** CSI F */ cursorPrecedingLine(params: IParams): void;
96   /** CSI G */ cursorCharAbsolute(params: IParams): void;
97   /** CSI H */ cursorPosition(params: IParams): void;
98   /** CSI I */ cursorForwardTab(params: IParams): void;
99   /** CSI J */ eraseInDisplay(params: IParams): void;
100   /** CSI K */ eraseInLine(params: IParams): void;
101   /** CSI L */ insertLines(params: IParams): void;
102   /** CSI M */ deleteLines(params: IParams): void;
103   /** CSI P */ deleteChars(params: IParams): void;
104   /** CSI S */ scrollUp(params: IParams): void;
105   /** CSI T */ scrollDown(params: IParams, collect?: string): void;
106   /** CSI X */ eraseChars(params: IParams): void;
107   /** CSI Z */ cursorBackwardTab(params: IParams): void;
108   /** CSI ` */ charPosAbsolute(params: IParams): void;
109   /** CSI a */ hPositionRelative(params: IParams): void;
110   /** CSI b */ repeatPrecedingCharacter(params: IParams): void;
111   /** CSI c */ sendDeviceAttributesPrimary(params: IParams): void;
112   /** CSI > c */ sendDeviceAttributesSecondary(params: IParams): void;
113   /** CSI d */ linePosAbsolute(params: IParams): void;
114   /** CSI e */ vPositionRelative(params: IParams): void;
115   /** CSI f */ hVPosition(params: IParams): void;
116   /** CSI g */ tabClear(params: IParams): void;
117   /** CSI h */ setMode(params: IParams, collect?: string): void;
118   /** CSI l */ resetMode(params: IParams, collect?: string): void;
119   /** CSI m */ charAttributes(params: IParams): void;
120   /** CSI n */ deviceStatus(params: IParams, collect?: string): void;
121   /** CSI p */ softReset(params: IParams, collect?: string): void;
122   /** CSI q */ setCursorStyle(params: IParams, collect?: string): void;
123   /** CSI r */ setScrollRegion(params: IParams, collect?: string): void;
124   /** CSI s */ saveCursor(params: IParams): void;
125   /** CSI u */ restoreCursor(params: IParams): void;
126   /** CSI ' } */ insertColumns(params: IParams): void;
127   /** CSI ' ~ */ deleteColumns(params: IParams): void;
128   /** OSC 0
129       OSC 2 */ setTitle(data: string): void;
130   /** ESC E */ nextLine(): void;
131   /** ESC = */ keypadApplicationMode(): void;
132   /** ESC > */ keypadNumericMode(): void;
133   /** ESC % G
134       ESC % @ */ selectDefaultCharset(): void;
135   /** ESC ( C
136       ESC ) C
137       ESC * C
138       ESC + C
139       ESC - C
140       ESC . C
141       ESC / C */ selectCharset(collectAndFlag: string): void;
142   /** ESC D */ index(): void;
143   /** ESC H */ tabSet(): void;
144   /** ESC M */ reverseIndex(): void;
145   /** ESC c */ reset(): void;
146   /** ESC n
147       ESC o
148       ESC |
149       ESC }
150       ESC ~ */ setgLevel(level: number): void;
151   /** ESC # 8 */ screenAlignmentPattern(): void;
152 }
153
154 export interface ITerminal extends IPublicTerminal, IElementAccessor, IBufferAccessor, ILinkifierAccessor {
155   screenElement: HTMLElement;
156   browser: IBrowser;
157   cursorHidden: boolean;
158   cursorState: number;
159   buffer: IBuffer;
160   buffers: IBufferSet;
161   isFocused: boolean;
162   viewport: IViewport;
163   bracketedPasteMode: boolean;
164   optionsService: IOptionsService;
165   // TODO: We should remove options once components adopt optionsService
166   options: ITerminalOptions;
167
168   onBlur: IEvent<void>;
169   onFocus: IEvent<void>;
170   onA11yChar: IEvent<string>;
171   onA11yTab: IEvent<number>;
172
173   scrollLines(disp: number, suppressScrollEvent?: boolean): void;
174   cancel(ev: Event, force?: boolean): boolean | void;
175   showCursor(): void;
176 }
177
178 // Portions of the public API that are required by the internal Terminal
179 export interface IPublicTerminal extends IDisposable {
180   textarea: HTMLTextAreaElement | undefined;
181   rows: number;
182   cols: number;
183   buffer: IBuffer;
184   markers: IMarker[];
185   onCursorMove: IEvent<void>;
186   onData: IEvent<string>;
187   onKey: IEvent<{ key: string, domEvent: KeyboardEvent }>;
188   onLineFeed: IEvent<void>;
189   onScroll: IEvent<number>;
190   onSelectionChange: IEvent<void>;
191   onRender: IEvent<{ start: number, end: number }>;
192   onResize: IEvent<{ cols: number, rows: number }>;
193   onTitleChange: IEvent<string>;
194   blur(): void;
195   focus(): void;
196   resize(columns: number, rows: number): void;
197   open(parent: HTMLElement): void;
198   attachCustomKeyEventHandler(customKeyEventHandler: (event: KeyboardEvent) => boolean): void;
199   addCsiHandler(id: IFunctionIdentifier, callback: (params: IParams) => boolean): IDisposable;
200   addDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: IParams) => boolean): IDisposable;
201   addEscHandler(id: IFunctionIdentifier, callback: () => boolean): IDisposable;
202   addOscHandler(ident: number, callback: (data: string) => boolean): IDisposable;
203   registerLinkMatcher(regex: RegExp, handler: (event: MouseEvent, uri: string) => void, options?: ILinkMatcherOptions): number;
204   deregisterLinkMatcher(matcherId: number): void;
205   registerCharacterJoiner(handler: (text: string) => [number, number][]): number;
206   deregisterCharacterJoiner(joinerId: number): void;
207   addMarker(cursorYOffset: number): IMarker;
208   hasSelection(): boolean;
209   getSelection(): string;
210   getSelectionPosition(): ISelectionPosition | undefined;
211   clearSelection(): void;
212   select(column: number, row: number, length: number): void;
213   selectAll(): void;
214   selectLines(start: number, end: number): void;
215   dispose(): void;
216   scrollLines(amount: number): void;
217   scrollPages(pageCount: number): void;
218   scrollToTop(): void;
219   scrollToBottom(): void;
220   scrollToLine(line: number): void;
221   clear(): void;
222   write(data: string | Uint8Array, callback?: () => void): void;
223   paste(data: string): void;
224   refresh(start: number, end: number): void;
225   reset(): void;
226 }
227
228 export interface IBufferAccessor {
229   buffer: IBuffer;
230 }
231
232 export interface IElementAccessor {
233   readonly element: HTMLElement | undefined;
234 }
235
236 export interface ILinkifierAccessor {
237   linkifier: ILinkifier;
238 }
239
240 // TODO: The options that are not in the public API should be reviewed
241 export interface ITerminalOptions extends IPublicTerminalOptions {
242   [key: string]: any;
243   cancelEvents?: boolean;
244   convertEol?: boolean;
245   handler?: (data: string) => void;
246   screenKeys?: boolean;
247   termName?: string;
248   useFlowControl?: boolean;
249 }
250
251 export interface IBrowser {
252   isNode: boolean;
253   userAgent: string;
254   platform: string;
255   isFirefox: boolean;
256   isMac: boolean;
257   isIpad: boolean;
258   isIphone: boolean;
259   isWindows: boolean;
260 }