Debian Codegraph @

node/@xterm/xterm/src/common/services/Services.ts

raw
1 /**
2 * Copyright (c) 2019 The xterm.js authors. All rights reserved.
3 * @license MIT
4 */
5
6 import { IDecoration, IDecorationOptions, ILinkHandler, ILogger, IWindowsPty, type IOverviewRulerOptions } from '@xterm/xterm';
7 import { CoreMouseEncoding, CoreMouseEventType, CursorInactiveStyle, CursorStyle, IAttributeData, ICharset, IColor, ICoreMouseEvent, ICoreMouseProtocol, IDecPrivateModes, IDisposable, IModes, IOscLinkData, IWindowOptions } from 'common/Types';
8 import { IBuffer, IBufferSet } from 'common/buffer/Types';
9 import { createDecorator } from 'common/services/ServiceRegistry';
10 import type { Emitter, Event } from 'vs/base/common/event';
11
12 export const IBufferService = createDecorator<IBufferService>('BufferService');
13 export interface IBufferService {
14 serviceBrand: undefined;
15
16 readonly cols: number;
17 readonly rows: number;
18 readonly buffer: IBuffer;
19 readonly buffers: IBufferSet;
20 isUserScrolling: boolean;
21 onResize: Event<IBufferResizeEvent>;
22 onScroll: Event<number>;
23 scroll(eraseAttr: IAttributeData, isWrapped?: boolean): void;
24 scrollLines(disp: number, suppressScrollEvent?: boolean): void;
25 resize(cols: number, rows: number): void;
26 reset(): void;
27 }
28
29 export interface IBufferResizeEvent {
30 cols: number;
31 rows: number;
32 colsChanged: boolean;
33 rowsChanged: boolean;
34 }
35
36 export const ICoreMouseService = createDecorator<ICoreMouseService>('CoreMouseService');
37 export interface ICoreMouseService {
38 serviceBrand: undefined;
39
40 activeProtocol: string;
41 activeEncoding: string;
42 areMouseEventsActive: boolean;
43 addProtocol(name: string, protocol: ICoreMouseProtocol): void;
44 addEncoding(name: string, encoding: CoreMouseEncoding): void;
45 reset(): void;
46
47 /**
48 * Triggers a mouse event to be sent.
49 *
50 * Returns true if the event passed all protocol restrictions and a report
51 * was sent, otherwise false. The return value may be used to decide whether
52 * the default event action in the bowser component should be omitted.
53 *
54 * Note: The method will change values of the given event object
55 * to fullfill protocol and encoding restrictions.
56 */
57 triggerMouseEvent(event: ICoreMouseEvent): boolean;
58
59 /**
60 * Event to announce changes in mouse tracking.
61 */
62 onProtocolChange: Event<CoreMouseEventType>;
63
64 /**
65 * Human readable version of mouse events.
66 */
67 explainEvents(events: CoreMouseEventType): { [event: string]: boolean };
68
69 /**
70 * Process wheel event taking partial scroll into account.
71 */
72 consumeWheelEvent(ev: WheelEvent, cellHeight?: number, dpr?: number): number;
73 }
74
75 export const ICoreService = createDecorator<ICoreService>('CoreService');
76 export interface ICoreService {
77 serviceBrand: undefined;
78
79 /**
80 * Initially the cursor will not be visible until the first time the terminal
81 * is focused.
82 */
83 isCursorInitialized: boolean;
84 isCursorHidden: boolean;
85
86 readonly modes: IModes;
87 readonly decPrivateModes: IDecPrivateModes;
88
89 readonly onData: Event<string>;
90 readonly onUserInput: Event<void>;
91 readonly onBinary: Event<string>;
92 readonly onRequestScrollToBottom: Event<void>;
93
94 reset(): void;
95
96 /**
97 * Triggers the onData event in the public API.
98 * @param data The data that is being emitted.
99 * @param wasUserInput Whether the data originated from the user (as opposed to
100 * resulting from parsing incoming data). When true this will also:
101 * - Scroll to the bottom of the buffer if option scrollOnUserInput is true.
102 * - Fire the `onUserInput` event (so selection can be cleared).
103 */
104 triggerDataEvent(data: string, wasUserInput?: boolean): void;
105
106 /**
107 * Triggers the onBinary event in the public API.
108 * @param data The data that is being emitted.
109 */
110 triggerBinaryEvent(data: string): void;
111 }
112
113 export const ICharsetService = createDecorator<ICharsetService>('CharsetService');
114 export interface ICharsetService {
115 serviceBrand: undefined;
116
117 charset: ICharset | undefined;
118 readonly glevel: number;
119
120 reset(): void;
121
122 /**
123 * Set the G level of the terminal.
124 * @param g
125 */
126 setgLevel(g: number): void;
127
128 /**
129 * Set the charset for the given G level of the terminal.
130 * @param g
131 * @param charset
132 */
133 setgCharset(g: number, charset: ICharset | undefined): void;
134 }
135
136 export interface IServiceIdentifier<T> {
137 (...args: any[]): void;
138 type: T;
139 _id: string;
140 }
141
142 export interface IBrandedService {
143 serviceBrand: undefined;
144 }
145
146 type GetLeadingNonServiceArgs<TArgs extends any[]> = TArgs extends [] ? []
147 : TArgs extends [...infer TFirst, infer TLast] ? TLast extends IBrandedService ? GetLeadingNonServiceArgs<TFirst> : TArgs
148 : never;
149
150 export const IInstantiationService = createDecorator<IInstantiationService>('InstantiationService');
151 export interface IInstantiationService {
152 serviceBrand: undefined;
153
154 setService<T>(id: IServiceIdentifier<T>, instance: T): void;
155 getService<T>(id: IServiceIdentifier<T>): T | undefined;
156 createInstance<Ctor extends new (...args: any[]) => any, R extends InstanceType<Ctor>>(t: Ctor, ...args: GetLeadingNonServiceArgs<ConstructorParameters<Ctor>>): R;
157 }
158
159 export enum LogLevelEnum {
160 TRACE = 0,
161 DEBUG = 1,
162 INFO = 2,
163 WARN = 3,
164 ERROR = 4,
165 OFF = 5
166 }
167
168 export const ILogService = createDecorator<ILogService>('LogService');
169 export interface ILogService {
170 serviceBrand: undefined;
171
172 readonly logLevel: LogLevelEnum;
173
174 trace(message: any, ...optionalParams: any[]): void;
175 debug(message: any, ...optionalParams: any[]): void;
176 info(message: any, ...optionalParams: any[]): void;
177 warn(message: any, ...optionalParams: any[]): void;
178 error(message: any, ...optionalParams: any[]): void;
179 }
180
181 export const IOptionsService = createDecorator<IOptionsService>('OptionsService');
182 export interface IOptionsService {
183 serviceBrand: undefined;
184
185 /**
186 * Read only access to the raw options object, this is an internal-only fast path for accessing
187 * single options without any validation as we trust TypeScript to enforce correct usage
188 * internally.
189 */
190 readonly rawOptions: Required<ITerminalOptions>;
191
192 /**
193 * Options as exposed through the public API, this property uses getters and setters with
194 * validation which makes it safer but slower. {@link rawOptions} should be used for pretty much
195 * all internal usage for performance reasons.
196 */
197 readonly options: Required<ITerminalOptions>;
198
199 /**
200 * Adds an event listener for when any option changes.
201 */
202 readonly onOptionChange: Event<keyof ITerminalOptions>;
203
204 /**
205 * Adds an event listener for when a specific option changes, this is a convenience method that is
206 * preferred over {@link onOptionChange} when only a single option is being listened to.
207 */
208 // eslint-disable-next-line @typescript-eslint/naming-convention
209 onSpecificOptionChange<T extends keyof ITerminalOptions>(key: T, listener: (arg1: Required<ITerminalOptions>[T]) => any): IDisposable;
210
211 /**
212 * Adds an event listener for when a set of specific options change, this is a convenience method
213 * that is preferred over {@link onOptionChange} when multiple options are being listened to and
214 * handled the same way.
215 */
216 // eslint-disable-next-line @typescript-eslint/naming-convention
217 onMultipleOptionChange(keys: (keyof ITerminalOptions)[], listener: () => any): IDisposable;
218 }
219
220 export type FontWeight = 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' | number;
221 export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'off';
222
223 export interface ITerminalOptions {
224 allowProposedApi?: boolean;
225 allowTransparency?: boolean;
226 altClickMovesCursor?: boolean;
227 cols?: number;
228 convertEol?: boolean;
229 cursorBlink?: boolean;
230 cursorStyle?: CursorStyle;
231 cursorWidth?: number;
232 cursorInactiveStyle?: CursorInactiveStyle;
233 customGlyphs?: boolean;
234 disableStdin?: boolean;
235 documentOverride?: any | null;
236 drawBoldTextInBrightColors?: boolean;
237 /** @deprecated No longer supported */
238 fastScrollModifier?: 'none' | 'alt' | 'ctrl' | 'shift';
239 fastScrollSensitivity?: number;
240 fontSize?: number;
241 fontFamily?: string;
242 fontWeight?: FontWeight;
243 fontWeightBold?: FontWeight;
244 ignoreBracketedPasteMode?: boolean;
245 letterSpacing?: number;
246 lineHeight?: number;
247 linkHandler?: ILinkHandler | null;
248 logLevel?: LogLevel;
249 logger?: ILogger | null;
250 macOptionIsMeta?: boolean;
251 macOptionClickForcesSelection?: boolean;
252 minimumContrastRatio?: number;
253 reflowCursorLine?: boolean;
254 rescaleOverlappingGlyphs?: boolean;
255 rightClickSelectsWord?: boolean;
256 rows?: number;
257 screenReaderMode?: boolean;
258 scrollback?: number;
259 scrollOnUserInput?: boolean;
260 scrollSensitivity?: number;
261 smoothScrollDuration?: number;
262 tabStopWidth?: number;
263 theme?: ITheme;
264 windowsMode?: boolean;
265 windowsPty?: IWindowsPty;
266 windowOptions?: IWindowOptions;
267 wordSeparator?: string;
268 overviewRuler?: IOverviewRulerOptions;
269 scrollOnEraseInDisplay?: boolean;
270
271 [key: string]: any;
272 cancelEvents: boolean;
273 termName: string;
274 }
275
276 export interface ITheme {
277 foreground?: string;
278 background?: string;
279 cursor?: string;
280 cursorAccent?: string;
281 selectionForeground?: string;
282 selectionBackground?: string;
283 selectionInactiveBackground?: string;
284 scrollbarSliderBackground?: string;
285 scrollbarSliderHoverBackground?: string;
286 scrollbarSliderActiveBackground?: string;
287 overviewRulerBorder?: string;
288 black?: string;
289 red?: string;
290 green?: string;
291 yellow?: string;
292 blue?: string;
293 magenta?: string;
294 cyan?: string;
295 white?: string;
296 brightBlack?: string;
297 brightRed?: string;
298 brightGreen?: string;
299 brightYellow?: string;
300 brightBlue?: string;
301 brightMagenta?: string;
302 brightCyan?: string;
303 brightWhite?: string;
304 extendedAnsi?: string[];
305 }
306
307 export const IOscLinkService = createDecorator<IOscLinkService>('OscLinkService');
308 export interface IOscLinkService {
309 serviceBrand: undefined;
310 /**
311 * Registers a link to the service, returning the link ID. The link data is managed by this
312 * service and will be freed when this current cursor position is trimmed off the buffer.
313 */
314 registerLink(linkData: IOscLinkData): number;
315 /**
316 * Adds a line to a link if needed.
317 */
318 addLineToLink(linkId: number, y: number): void;
319 /** Get the link data associated with a link ID. */
320 getLinkData(linkId: number): IOscLinkData | undefined;
321 }
322
323 /*
324 * Width and Grapheme_Cluster_Break properties of a character as a bit mask.
325 *
326 * bit 0: shouldJoin - should combine with preceding character.
327 * bit 1..2: wcwidth - see UnicodeCharWidth.
328 * bit 3..31: class of character (currently only 4 bits are used).
329 * This is used to determined grapheme clustering - i.e. which codepoints
330 * are to be combined into a single compound character.
331 *
332 * Use the UnicodeService static function createPropertyValue to create a
333 * UnicodeCharProperties; use extractShouldJoin, extractWidth, and
334 * extractCharKind to extract the components.
335 */
336 export type UnicodeCharProperties = number;
337
338 /**
339 * Width in columns of a character.
340 * In a CJK context, "half-width" characters (such as Latin) are width 1,
341 * while "full-width" characters (such as Kanji) are 2 columns wide.
342 * Combining characters (such as accents) are width 0.
343 */
344 export type UnicodeCharWidth = 0 | 1 | 2;
345
346 export const IUnicodeService = createDecorator<IUnicodeService>('UnicodeService');
347 export interface IUnicodeService {
348 serviceBrand: undefined;
349 /** Register an Unicode version provider. */
350 register(provider: IUnicodeVersionProvider): void;
351 /** Registered Unicode versions. */
352 readonly versions: string[];
353 /** Currently active version. */
354 activeVersion: string;
355 /** Event triggered, when activate version changed. */
356 readonly onChange: Event<string>;
357
358 /**
359 * Unicode version dependent
360 */
361 wcwidth(codepoint: number): UnicodeCharWidth;
362 getStringCellWidth(s: string): number;
363 /**
364 * Return character width and type for grapheme clustering.
365 * If preceding != 0, it is the return code from the previous character;
366 * in that case the result specifies if the characters should be joined.
367 */
368 charProperties(codepoint: number, preceding: UnicodeCharProperties): UnicodeCharProperties;
369 }
370
371 export interface IUnicodeVersionProvider {
372 readonly version: string;
373 wcwidth(ucs: number): UnicodeCharWidth;
374 charProperties(codepoint: number, preceding: UnicodeCharProperties): UnicodeCharProperties;
375 }
376
377 export const IDecorationService = createDecorator<IDecorationService>('DecorationService');
378 export interface IDecorationService extends IDisposable {
379 serviceBrand: undefined;
380 readonly decorations: IterableIterator<IInternalDecoration>;
381 readonly onDecorationRegistered: Event<IInternalDecoration>;
382 readonly onDecorationRemoved: Event<IInternalDecoration>;
383 registerDecoration(decorationOptions: IDecorationOptions): IDecoration | undefined;
384 reset(): void;
385 /**
386 * Trigger a callback over the decoration at a cell (in no particular order). This uses a callback
387 * instead of an iterator as it's typically used in hot code paths.
388 */
389 forEachDecorationAtCell(x: number, line: number, layer: 'bottom' | 'top' | undefined, callback: (decoration: IInternalDecoration) => void): void;
390 }
391 export interface IInternalDecoration extends IDecoration {
392 readonly options: IDecorationOptions;
393 readonly backgroundColorRGB: IColor | undefined;
394 readonly foregroundColorRGB: IColor | undefined;
395 readonly onRenderEmitter: Emitter<HTMLElement>;
396 }