xterm
[VSoRC/.git] / node_modules / xterm / src / common / services / Services.ts
1 /**
2  * Copyright (c) 2019 The xterm.js authors. All rights reserved.
3  * @license MIT
4  */
5
6 import { IEvent } from 'common/EventEmitter';
7 import { IBuffer, IBufferSet } from 'common/buffer/Types';
8 import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEncoding, ICoreMouseProtocol, CoreMouseEventType } from 'common/Types';
9 import { createDecorator } from 'common/services/ServiceRegistry';
10
11 export const IBufferService = createDecorator<IBufferService>('BufferService');
12 export interface IBufferService {
13   serviceBrand: any;
14
15   readonly cols: number;
16   readonly rows: number;
17   readonly buffer: IBuffer;
18   readonly buffers: IBufferSet;
19
20   // TODO: Move resize event here
21
22   resize(cols: number, rows: number): void;
23   reset(): void;
24 }
25
26 export const ICoreMouseService = createDecorator<ICoreMouseService>('CoreMouseService');
27 export interface ICoreMouseService {
28   activeProtocol: string;
29   activeEncoding: string;
30   addProtocol(name: string, protocol: ICoreMouseProtocol): void;
31   addEncoding(name: string, encoding: CoreMouseEncoding): void;
32   reset(): void;
33
34   /**
35    * Triggers a mouse event to be sent.
36    *
37    * Returns true if the event passed all protocol restrictions and a report
38    * was sent, otherwise false. The return value may be used to decide whether
39    * the default event action in the bowser component should be omitted.
40    *
41    * Note: The method will change values of the given event object
42    * to fullfill protocol and encoding restrictions.
43    */
44   triggerMouseEvent(event: ICoreMouseEvent): boolean;
45
46   /**
47    * Event to announce changes in mouse tracking.
48    */
49   onProtocolChange: IEvent<CoreMouseEventType>;
50
51   /**
52    * Human readable version of mouse events.
53    */
54   explainEvents(events: CoreMouseEventType): {[event: string]: boolean};
55 }
56
57 export const ICoreService = createDecorator<ICoreService>('CoreService');
58 export interface ICoreService {
59   serviceBrand: any;
60
61   readonly decPrivateModes: IDecPrivateModes;
62
63   readonly onData: IEvent<string>;
64   readonly onUserInput: IEvent<void>;
65
66   reset(): void;
67
68   /**
69    * Triggers the onData event in the public API.
70    * @param data The data that is being emitted.
71    * @param wasFromUser Whether the data originated from the user (as opposed to
72    * resulting from parsing incoming data). When true this will also:
73    * - Scroll to the bottom of the buffer.s
74    * - Fire the `onUserInput` event (so selection can be cleared).
75     */
76   triggerDataEvent(data: string, wasUserInput?: boolean): void;
77 }
78
79 export const IDirtyRowService = createDecorator<IDirtyRowService>('DirtyRowService');
80 export interface IDirtyRowService {
81   serviceBrand: any;
82
83   readonly start: number;
84   readonly end: number;
85
86   clearRange(): void;
87   markDirty(y: number): void;
88   markRangeDirty(y1: number, y2: number): void;
89   markAllDirty(): void;
90 }
91
92 export interface IServiceIdentifier<T> {
93   (...args: any[]): void;
94   type: T;
95 }
96
97 export interface IConstructorSignature0<T> {
98   new(...services: { serviceBrand: any; }[]): T;
99 }
100
101 export interface IConstructorSignature1<A1, T> {
102   new(first: A1, ...services: { serviceBrand: any; }[]): T;
103 }
104
105 export interface IConstructorSignature2<A1, A2, T> {
106   new(first: A1, second: A2, ...services: { serviceBrand: any; }[]): T;
107 }
108
109 export interface IConstructorSignature3<A1, A2, A3, T> {
110   new(first: A1, second: A2, third: A3, ...services: { serviceBrand: any; }[]): T;
111 }
112
113 export interface IConstructorSignature4<A1, A2, A3, A4, T> {
114   new(first: A1, second: A2, third: A3, fourth: A4, ...services: { serviceBrand: any; }[]): T;
115 }
116
117 export interface IConstructorSignature5<A1, A2, A3, A4, A5, T> {
118   new(first: A1, second: A2, third: A3, fourth: A4, fifth: A5, ...services: { serviceBrand: any; }[]): T;
119 }
120
121 export interface IConstructorSignature6<A1, A2, A3, A4, A5, A6, T> {
122   new(first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6, ...services: { serviceBrand: any; }[]): T;
123 }
124
125 export interface IConstructorSignature7<A1, A2, A3, A4, A5, A6, A7, T> {
126   new(first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6, seventh: A7, ...services: { serviceBrand: any; }[]): T;
127 }
128
129 export interface IConstructorSignature8<A1, A2, A3, A4, A5, A6, A7, A8, T> {
130   new(first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6, seventh: A7, eigth: A8, ...services: { serviceBrand: any; }[]): T;
131 }
132
133 export const IInstantiationService = createDecorator<IInstantiationService>('InstantiationService');
134 export interface IInstantiationService {
135   setService<T>(id: IServiceIdentifier<T>, instance: T): void;
136
137   createInstance<T>(ctor: IConstructorSignature0<T>): T;
138   createInstance<A1, T>(ctor: IConstructorSignature1<A1, T>, first: A1): T;
139   createInstance<A1, A2, T>(ctor: IConstructorSignature2<A1, A2, T>, first: A1, second: A2): T;
140   createInstance<A1, A2, A3, T>(ctor: IConstructorSignature3<A1, A2, A3, T>, first: A1, second: A2, third: A3): T;
141   createInstance<A1, A2, A3, A4, T>(ctor: IConstructorSignature4<A1, A2, A3, A4, T>, first: A1, second: A2, third: A3, fourth: A4): T;
142   createInstance<A1, A2, A3, A4, A5, T>(ctor: IConstructorSignature5<A1, A2, A3, A4, A5, T>, first: A1, second: A2, third: A3, fourth: A4, fifth: A5): T;
143   createInstance<A1, A2, A3, A4, A5, A6, T>(ctor: IConstructorSignature6<A1, A2, A3, A4, A5, A6, T>, first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6): T;
144   createInstance<A1, A2, A3, A4, A5, A6, A7, T>(ctor: IConstructorSignature7<A1, A2, A3, A4, A5, A6, A7, T>, first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6, seventh: A7): T;
145   createInstance<A1, A2, A3, A4, A5, A6, A7, A8, T>(ctor: IConstructorSignature8<A1, A2, A3, A4, A5, A6, A7, A8, T>, first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6, seventh: A7, eigth: A8): T;
146 }
147
148 export const ILogService = createDecorator<ILogService>('LogService');
149 export interface ILogService {
150   serviceBrand: any;
151
152   debug(message: any, ...optionalParams: any[]): void;
153   info(message: any, ...optionalParams: any[]): void;
154   warn(message: any, ...optionalParams: any[]): void;
155   error(message: any, ...optionalParams: any[]): void;
156 }
157
158 export const IOptionsService = createDecorator<IOptionsService>('OptionsService');
159 export interface IOptionsService {
160   serviceBrand: any;
161
162   readonly options: ITerminalOptions;
163
164   readonly onOptionChange: IEvent<string>;
165
166   setOption<T>(key: string, value: T): void;
167   getOption<T>(key: string): T | undefined;
168 }
169
170 export type FontWeight = 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
171 export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'off';
172 export type RendererType = 'dom' | 'canvas';
173
174 export interface IPartialTerminalOptions {
175   allowTransparency?: boolean;
176   bellSound?: string;
177   bellStyle?: 'none' /*| 'visual'*/ | 'sound' /*| 'both'*/;
178   cols?: number;
179   cursorBlink?: boolean;
180   cursorStyle?: 'block' | 'underline' | 'bar';
181   disableStdin?: boolean;
182   drawBoldTextInBrightColors?: boolean;
183   fastScrollModifier?: 'alt' | 'ctrl' | 'shift';
184   fastScrollSensitivity?: number;
185   fontSize?: number;
186   fontFamily?: string;
187   fontWeight?: FontWeight;
188   fontWeightBold?: FontWeight;
189   letterSpacing?: number;
190   lineHeight?: number;
191   logLevel?: LogLevel;
192   macOptionIsMeta?: boolean;
193   macOptionClickForcesSelection?: boolean;
194   rendererType?: RendererType;
195   rightClickSelectsWord?: boolean;
196   rows?: number;
197   screenReaderMode?: boolean;
198   scrollback?: number;
199   scrollSensitivity?: number;
200   tabStopWidth?: number;
201   theme?: ITheme;
202   windowsMode?: boolean;
203   wordSeparator?: string;
204 }
205
206 export interface ITerminalOptions {
207   allowTransparency: boolean;
208   bellSound: string;
209   bellStyle: 'none' /*| 'visual'*/ | 'sound' /*| 'both'*/;
210   cols: number;
211   cursorBlink: boolean;
212   cursorStyle: 'block' | 'underline' | 'bar';
213   disableStdin: boolean;
214   drawBoldTextInBrightColors: boolean;
215   fastScrollModifier: 'alt' | 'ctrl' | 'shift' | undefined;
216   fastScrollSensitivity: number;
217   fontSize: number;
218   fontFamily: string;
219   fontWeight: FontWeight;
220   fontWeightBold: FontWeight;
221   letterSpacing: number;
222   lineHeight: number;
223   logLevel: LogLevel;
224   macOptionIsMeta: boolean;
225   macOptionClickForcesSelection: boolean;
226   rendererType: RendererType;
227   rightClickSelectsWord: boolean;
228   rows: number;
229   screenReaderMode: boolean;
230   scrollback: number;
231   scrollSensitivity: number;
232   tabStopWidth: number;
233   theme: ITheme;
234   windowsMode: boolean;
235   wordSeparator: string;
236
237   [key: string]: any;
238   cancelEvents: boolean;
239   convertEol: boolean;
240   screenKeys: boolean;
241   termName: string;
242   useFlowControl: boolean;
243 }
244
245 export interface ITheme {
246   foreground?: string;
247   background?: string;
248   cursor?: string;
249   cursorAccent?: string;
250   selection?: string;
251   black?: string;
252   red?: string;
253   green?: string;
254   yellow?: string;
255   blue?: string;
256   magenta?: string;
257   cyan?: string;
258   white?: string;
259   brightBlack?: string;
260   brightRed?: string;
261   brightGreen?: string;
262   brightYellow?: string;
263   brightBlue?: string;
264   brightMagenta?: string;
265   brightCyan?: string;
266   brightWhite?: string;
267 }