-
Notifications
You must be signed in to change notification settings - Fork 30.7k
/
Copy pathterminal.ts
1131 lines (990 loc) · 39.3 KB
/
terminal.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Event } from '../../../base/common/event.js';
import { IProcessEnvironment, OperatingSystem } from '../../../base/common/platform.js';
import { URI, UriComponents } from '../../../base/common/uri.js';
import { createDecorator } from '../../instantiation/common/instantiation.js';
import { IPtyHostProcessReplayEvent, ISerializedCommandDetectionCapability, ITerminalCapabilityStore } from './capabilities/capabilities.js';
import { IGetTerminalLayoutInfoArgs, IProcessDetails, ISetTerminalLayoutInfoArgs } from './terminalProcess.js';
import { ThemeIcon } from '../../../base/common/themables.js';
import { ISerializableEnvironmentVariableCollections } from './environmentVariable.js';
import { RawContextKey } from '../../contextkey/common/contextkey.js';
import { IWorkspaceFolder } from '../../workspace/common/workspace.js';
import { Registry } from '../../registry/common/platform.js';
import type * as performance from '../../../base/common/performance.js';
import { ILogService } from '../../log/common/log.js';
export const terminalTabFocusModeContextKey = new RawContextKey<boolean>('terminalTabFocusMode', false, true);
export const enum TerminalSettingPrefix {
AutomationProfile = 'terminal.integrated.automationProfile.',
DefaultProfile = 'terminal.integrated.defaultProfile.',
Profiles = 'terminal.integrated.profiles.'
}
export const enum TerminalSettingId {
SendKeybindingsToShell = 'terminal.integrated.sendKeybindingsToShell',
AutomationProfileLinux = 'terminal.integrated.automationProfile.linux',
AutomationProfileMacOs = 'terminal.integrated.automationProfile.osx',
AutomationProfileWindows = 'terminal.integrated.automationProfile.windows',
ProfilesWindows = 'terminal.integrated.profiles.windows',
ProfilesMacOs = 'terminal.integrated.profiles.osx',
ProfilesLinux = 'terminal.integrated.profiles.linux',
DefaultProfileLinux = 'terminal.integrated.defaultProfile.linux',
DefaultProfileMacOs = 'terminal.integrated.defaultProfile.osx',
DefaultProfileWindows = 'terminal.integrated.defaultProfile.windows',
UseWslProfiles = 'terminal.integrated.useWslProfiles',
TabsDefaultColor = 'terminal.integrated.tabs.defaultColor',
TabsDefaultIcon = 'terminal.integrated.tabs.defaultIcon',
TabsEnabled = 'terminal.integrated.tabs.enabled',
TabsEnableAnimation = 'terminal.integrated.tabs.enableAnimation',
TabsHideCondition = 'terminal.integrated.tabs.hideCondition',
TabsShowActiveTerminal = 'terminal.integrated.tabs.showActiveTerminal',
TabsShowActions = 'terminal.integrated.tabs.showActions',
TabsLocation = 'terminal.integrated.tabs.location',
TabsFocusMode = 'terminal.integrated.tabs.focusMode',
MacOptionIsMeta = 'terminal.integrated.macOptionIsMeta',
MacOptionClickForcesSelection = 'terminal.integrated.macOptionClickForcesSelection',
AltClickMovesCursor = 'terminal.integrated.altClickMovesCursor',
CopyOnSelection = 'terminal.integrated.copyOnSelection',
EnableMultiLinePasteWarning = 'terminal.integrated.enableMultiLinePasteWarning',
DrawBoldTextInBrightColors = 'terminal.integrated.drawBoldTextInBrightColors',
FontFamily = 'terminal.integrated.fontFamily',
FontSize = 'terminal.integrated.fontSize',
LetterSpacing = 'terminal.integrated.letterSpacing',
LineHeight = 'terminal.integrated.lineHeight',
MinimumContrastRatio = 'terminal.integrated.minimumContrastRatio',
TabStopWidth = 'terminal.integrated.tabStopWidth',
FastScrollSensitivity = 'terminal.integrated.fastScrollSensitivity',
MouseWheelScrollSensitivity = 'terminal.integrated.mouseWheelScrollSensitivity',
BellDuration = 'terminal.integrated.bellDuration',
FontWeight = 'terminal.integrated.fontWeight',
FontWeightBold = 'terminal.integrated.fontWeightBold',
CursorBlinking = 'terminal.integrated.cursorBlinking',
CursorStyle = 'terminal.integrated.cursorStyle',
CursorStyleInactive = 'terminal.integrated.cursorStyleInactive',
CursorWidth = 'terminal.integrated.cursorWidth',
Scrollback = 'terminal.integrated.scrollback',
DetectLocale = 'terminal.integrated.detectLocale',
DefaultLocation = 'terminal.integrated.defaultLocation',
GpuAcceleration = 'terminal.integrated.gpuAcceleration',
TerminalTitleSeparator = 'terminal.integrated.tabs.separator',
TerminalTitle = 'terminal.integrated.tabs.title',
TerminalDescription = 'terminal.integrated.tabs.description',
RightClickBehavior = 'terminal.integrated.rightClickBehavior',
MiddleClickBehavior = 'terminal.integrated.middleClickBehavior',
Cwd = 'terminal.integrated.cwd',
ConfirmOnExit = 'terminal.integrated.confirmOnExit',
ConfirmOnKill = 'terminal.integrated.confirmOnKill',
EnableBell = 'terminal.integrated.enableBell',
EnableVisualBell = 'terminal.integrated.enableVisualBell',
CommandsToSkipShell = 'terminal.integrated.commandsToSkipShell',
AllowChords = 'terminal.integrated.allowChords',
AllowMnemonics = 'terminal.integrated.allowMnemonics',
TabFocusMode = 'terminal.integrated.tabFocusMode',
EnvMacOs = 'terminal.integrated.env.osx',
EnvLinux = 'terminal.integrated.env.linux',
EnvWindows = 'terminal.integrated.env.windows',
EnvironmentChangesIndicator = 'terminal.integrated.environmentChangesIndicator',
EnvironmentChangesRelaunch = 'terminal.integrated.environmentChangesRelaunch',
ExperimentalWindowsUseConptyDll = 'terminal.integrated.experimental.windowsUseConptyDll',
ShowExitAlert = 'terminal.integrated.showExitAlert',
SplitCwd = 'terminal.integrated.splitCwd',
WindowsEnableConpty = 'terminal.integrated.windowsEnableConpty',
WordSeparators = 'terminal.integrated.wordSeparators',
EnableFileLinks = 'terminal.integrated.enableFileLinks',
AllowedLinkSchemes = 'terminal.integrated.allowedLinkSchemes',
UnicodeVersion = 'terminal.integrated.unicodeVersion',
EnablePersistentSessions = 'terminal.integrated.enablePersistentSessions',
PersistentSessionReviveProcess = 'terminal.integrated.persistentSessionReviveProcess',
HideOnStartup = 'terminal.integrated.hideOnStartup',
CustomGlyphs = 'terminal.integrated.customGlyphs',
RescaleOverlappingGlyphs = 'terminal.integrated.rescaleOverlappingGlyphs',
PersistentSessionScrollback = 'terminal.integrated.persistentSessionScrollback',
InheritEnv = 'terminal.integrated.inheritEnv',
ShowLinkHover = 'terminal.integrated.showLinkHover',
IgnoreProcessNames = 'terminal.integrated.ignoreProcessNames',
ShellIntegrationEnabled = 'terminal.integrated.shellIntegration.enabled',
ShellIntegrationShowWelcome = 'terminal.integrated.shellIntegration.showWelcome',
ShellIntegrationDecorationsEnabled = 'terminal.integrated.shellIntegration.decorationsEnabled',
EnableImages = 'terminal.integrated.enableImages',
SmoothScrolling = 'terminal.integrated.smoothScrolling',
IgnoreBracketedPasteMode = 'terminal.integrated.ignoreBracketedPasteMode',
FocusAfterRun = 'terminal.integrated.focusAfterRun',
// Debug settings that are hidden from user
/** Simulated latency applied to all calls made to the pty host */
DeveloperPtyHostLatency = 'terminal.integrated.developer.ptyHost.latency',
/** Simulated startup delay of the pty host process */
DeveloperPtyHostStartupDelay = 'terminal.integrated.developer.ptyHost.startupDelay',
/** Shows the textarea element */
DevMode = 'terminal.integrated.developer.devMode'
}
export const enum PosixShellType {
Bash = 'bash',
Fish = 'fish',
Sh = 'sh',
Csh = 'csh',
Ksh = 'ksh',
Zsh = 'zsh',
}
export const enum WindowsShellType {
CommandPrompt = 'cmd',
Wsl = 'wsl',
GitBash = 'gitbash',
}
export const enum GeneralShellType {
PowerShell = 'pwsh',
Python = 'python',
Julia = 'julia',
NuShell = 'nu'
}
export type TerminalShellType = PosixShellType | WindowsShellType | GeneralShellType;
export interface IRawTerminalInstanceLayoutInfo<T> {
relativeSize: number;
terminal: T;
}
export type ITerminalInstanceLayoutInfoById = IRawTerminalInstanceLayoutInfo<number>;
export type ITerminalInstanceLayoutInfo = IRawTerminalInstanceLayoutInfo<IPtyHostAttachTarget>;
export interface IRawTerminalTabLayoutInfo<T> {
isActive: boolean;
activePersistentProcessId: number | undefined;
terminals: IRawTerminalInstanceLayoutInfo<T>[];
}
export type ITerminalTabLayoutInfoById = IRawTerminalTabLayoutInfo<number>;
export interface IRawTerminalsLayoutInfo<T> {
tabs: IRawTerminalTabLayoutInfo<T>[];
}
export interface IPtyHostAttachTarget {
id: number;
pid: number;
title: string;
titleSource: TitleEventSource;
cwd: string;
workspaceId: string;
workspaceName: string;
isOrphan: boolean;
icon: TerminalIcon | undefined;
fixedDimensions: IFixedTerminalDimensions | undefined;
environmentVariableCollections: ISerializableEnvironmentVariableCollections | undefined;
reconnectionProperties?: IReconnectionProperties;
waitOnExit?: WaitOnExitValue;
hideFromUser?: boolean;
isFeatureTerminal?: boolean;
type?: TerminalType;
hasChildProcesses: boolean;
shellIntegrationNonce: string;
}
export interface IReconnectionProperties {
ownerId: string;
data?: unknown;
}
export type TerminalType = 'Task' | 'Local' | undefined;
export enum TitleEventSource {
/** From the API or the rename command that overrides any other type */
Api,
/** From the process name property*/
Process,
/** From the VT sequence */
Sequence,
/** Config changed */
Config
}
export type ITerminalsLayoutInfo = IRawTerminalsLayoutInfo<IPtyHostAttachTarget | null>;
export type ITerminalsLayoutInfoById = IRawTerminalsLayoutInfo<number>;
export enum TerminalIpcChannels {
/**
* Communicates between the renderer process and shared process.
*/
LocalPty = 'localPty',
/**
* Communicates between the shared process and the pty host process.
*/
PtyHost = 'ptyHost',
/**
* Communicates between the renderer process and the pty host process.
*/
PtyHostWindow = 'ptyHostWindow',
/**
* Deals with logging from the pty host process.
*/
Logger = 'logger',
/**
* Enables the detection of unresponsive pty hosts.
*/
Heartbeat = 'heartbeat'
}
export const enum ProcessPropertyType {
Cwd = 'cwd',
InitialCwd = 'initialCwd',
FixedDimensions = 'fixedDimensions',
Title = 'title',
ShellType = 'shellType',
HasChildProcesses = 'hasChildProcesses',
ResolvedShellLaunchConfig = 'resolvedShellLaunchConfig',
OverrideDimensions = 'overrideDimensions',
FailedShellIntegrationActivation = 'failedShellIntegrationActivation',
UsedShellIntegrationInjection = 'usedShellIntegrationInjection'
}
export interface IProcessProperty<T extends ProcessPropertyType> {
type: T;
value: IProcessPropertyMap[T];
}
export interface IProcessPropertyMap {
[ProcessPropertyType.Cwd]: string;
[ProcessPropertyType.InitialCwd]: string;
[ProcessPropertyType.FixedDimensions]: IFixedTerminalDimensions;
[ProcessPropertyType.Title]: string;
[ProcessPropertyType.ShellType]: TerminalShellType | undefined;
[ProcessPropertyType.HasChildProcesses]: boolean;
[ProcessPropertyType.ResolvedShellLaunchConfig]: IShellLaunchConfig;
[ProcessPropertyType.OverrideDimensions]: ITerminalDimensionsOverride | undefined;
[ProcessPropertyType.FailedShellIntegrationActivation]: boolean | undefined;
[ProcessPropertyType.UsedShellIntegrationInjection]: boolean | undefined;
}
export interface IFixedTerminalDimensions {
/**
* The fixed columns of the terminal.
*/
cols?: number;
/**
* The fixed rows of the terminal.
*/
rows?: number;
}
/**
* A service that communicates with a pty host.
*/
export interface IPtyService {
readonly _serviceBrand: undefined;
readonly onProcessData: Event<{ id: number; event: IProcessDataEvent | string }>;
readonly onProcessReady: Event<{ id: number; event: IProcessReadyEvent }>;
readonly onProcessReplay: Event<{ id: number; event: IPtyHostProcessReplayEvent }>;
readonly onProcessOrphanQuestion: Event<{ id: number }>;
readonly onDidRequestDetach: Event<{ requestId: number; workspaceId: string; instanceId: number }>;
readonly onDidChangeProperty: Event<{ id: number; property: IProcessProperty<any> }>;
readonly onProcessExit: Event<{ id: number; event: number | undefined }>;
createProcess(
shellLaunchConfig: IShellLaunchConfig,
cwd: string,
cols: number,
rows: number,
unicodeVersion: '6' | '11',
env: IProcessEnvironment,
executableEnv: IProcessEnvironment,
options: ITerminalProcessOptions,
shouldPersist: boolean,
workspaceId: string,
workspaceName: string
): Promise<number>;
attachToProcess(id: number): Promise<void>;
detachFromProcess(id: number, forcePersist?: boolean): Promise<void>;
shutdownAll(): Promise<void>;
/**
* Lists all orphaned processes, ie. those without a connected frontend.
*/
listProcesses(): Promise<IProcessDetails[]>;
getPerformanceMarks(): Promise<performance.PerformanceMark[]>;
/**
* Measures and returns the latency of the current and all other processes to the pty host.
*/
getLatency(): Promise<IPtyHostLatencyMeasurement[]>;
start(id: number): Promise<ITerminalLaunchError | { injectedArgs: string[] } | undefined>;
shutdown(id: number, immediate: boolean): Promise<void>;
input(id: number, data: string): Promise<void>;
resize(id: number, cols: number, rows: number): Promise<void>;
clearBuffer(id: number): Promise<void>;
getInitialCwd(id: number): Promise<string>;
getCwd(id: number): Promise<string>;
acknowledgeDataEvent(id: number, charCount: number): Promise<void>;
setUnicodeVersion(id: number, version: '6' | '11'): Promise<void>;
processBinary(id: number, data: string): Promise<void>;
/** Confirm the process is _not_ an orphan. */
orphanQuestionReply(id: number): Promise<void>;
updateTitle(id: number, title: string, titleSource: TitleEventSource): Promise<void>;
updateIcon(id: number, userInitiated: boolean, icon: TerminalIcon, color?: string): Promise<void>;
getDefaultSystemShell(osOverride?: OperatingSystem): Promise<string>;
getEnvironment(): Promise<IProcessEnvironment>;
getWslPath(original: string, direction: 'unix-to-win' | 'win-to-unix'): Promise<string>;
getRevivedPtyNewId(workspaceId: string, id: number): Promise<number | undefined>;
setTerminalLayoutInfo(args: ISetTerminalLayoutInfoArgs): Promise<void>;
getTerminalLayoutInfo(args: IGetTerminalLayoutInfoArgs): Promise<ITerminalsLayoutInfo | undefined>;
reduceConnectionGraceTime(): Promise<void>;
requestDetachInstance(workspaceId: string, instanceId: number): Promise<IProcessDetails | undefined>;
acceptDetachInstanceReply(requestId: number, persistentProcessId?: number): Promise<void>;
freePortKillProcess(port: string): Promise<{ port: string; processId: string }>;
/**
* Serializes and returns terminal state.
* @param ids The persistent terminal IDs to serialize.
*/
serializeTerminalState(ids: number[]): Promise<string>;
/**
* Revives a workspaces terminal processes, these can then be reconnected to using the normal
* flow for restoring terminals after reloading.
*/
reviveTerminalProcesses(workspaceId: string, state: ISerializedTerminalState[], dateTimeFormatLocate: string): Promise<void>;
refreshProperty<T extends ProcessPropertyType>(id: number, property: T): Promise<IProcessPropertyMap[T]>;
updateProperty<T extends ProcessPropertyType>(id: number, property: T, value: IProcessPropertyMap[T]): Promise<void>;
// TODO: Make mandatory and remove impl from pty host service
refreshIgnoreProcessNames?(names: string[]): Promise<void>;
// #region Pty service contribution RPC calls
installAutoReply(match: string, reply: string): Promise<void>;
uninstallAllAutoReplies(): Promise<void>;
// #endregion
}
export const IPtyService = createDecorator<IPtyService>('ptyService');
export interface IPtyServiceContribution {
handleProcessReady(persistentProcessId: number, process: ITerminalChildProcess): void;
handleProcessDispose(persistentProcessId: number): void;
handleProcessInput(persistentProcessId: number, data: string): void;
handleProcessResize(persistentProcessId: number, cols: number, rows: number): void;
}
export interface IPtyHostController {
readonly onPtyHostExit: Event<number>;
readonly onPtyHostStart: Event<void>;
readonly onPtyHostUnresponsive: Event<void>;
readonly onPtyHostResponsive: Event<void>;
readonly onPtyHostRequestResolveVariables: Event<IRequestResolveVariablesEvent>;
restartPtyHost(): Promise<void>;
acceptPtyHostResolvedVariables(requestId: number, resolved: string[]): Promise<void>;
getProfiles(workspaceId: string, profiles: unknown, defaultProfile: unknown, includeDetectedProfiles?: boolean): Promise<ITerminalProfile[]>;
}
/**
* A service that communicates with a pty host controller (eg. main or server
* process) and is able to launch and forward requests to the pty host.
*/
export interface IPtyHostService extends IPtyService, IPtyHostController {
}
export interface IPtyHostLatencyMeasurement {
label: string;
latency: number;
}
/**
* Serialized terminal state matching the interface that can be used across versions, the version
* should be verified before using the state payload.
*/
export interface ICrossVersionSerializedTerminalState {
version: number;
state: unknown;
}
export interface ISerializedTerminalState {
id: number;
shellLaunchConfig: IShellLaunchConfig;
processDetails: IProcessDetails;
processLaunchConfig: IPersistentTerminalProcessLaunchConfig;
unicodeVersion: '6' | '11';
replayEvent: IPtyHostProcessReplayEvent;
timestamp: number;
}
export interface IPersistentTerminalProcessLaunchConfig {
env: IProcessEnvironment;
executableEnv: IProcessEnvironment;
options: ITerminalProcessOptions;
}
export interface IRequestResolveVariablesEvent {
requestId: number;
workspaceId: string;
originalText: string[];
}
export enum HeartbeatConstants {
/**
* The duration between heartbeats
*/
BeatInterval = 5000,
/**
* The duration of the first heartbeat while the pty host is starting up. This is much larger
* than the regular BeatInterval to accommodate slow machines, we still want to warn about the
* pty host's unresponsiveness eventually though.
*/
ConnectingBeatInterval = 20000,
/**
* Defines a multiplier for BeatInterval for how long to wait before starting the second wait
* timer.
*/
FirstWaitMultiplier = 1.2,
/**
* Defines a multiplier for BeatInterval for how long to wait before telling the user about
* non-responsiveness. The second timer is to avoid informing the user incorrectly when waking
* the computer up from sleep
*/
SecondWaitMultiplier = 1,
/**
* How long to wait before telling the user about non-responsiveness when they try to create a
* process. This short circuits the standard wait timeouts to tell the user sooner and only
* create process is handled to avoid additional perf overhead.
*/
CreateProcessTimeout = 5000
}
export interface IHeartbeatService {
readonly onBeat: Event<void>;
}
export interface IShellLaunchConfig {
/**
* The name of the terminal, if this is not set the name of the process will be used.
*/
name?: string;
/**
* A string to follow the name of the terminal with, indicating the type of terminal
*/
type?: 'Task' | 'Local';
/**
* The shell executable (bash, cmd, etc.).
*/
executable?: string;
/**
* The CLI arguments to use with executable, a string[] is in argv format and will be escaped,
* a string is in "CommandLine" pre-escaped format and will be used as is. The string option is
* only supported on Windows and will throw an exception if used on macOS or Linux.
*/
args?: string[] | string;
/**
* The current working directory of the terminal, this overrides the `terminal.integrated.cwd`
* settings key.
*/
cwd?: string | URI;
/**
* A custom environment for the terminal, if this is not set the environment will be inherited
* from the VS Code process.
*/
env?: ITerminalEnvironment;
/**
* Whether to ignore a custom cwd from the `terminal.integrated.cwd` settings key (e.g. if the
* shell is being launched by an extension).
*/
ignoreConfigurationCwd?: boolean;
/**
* The reconnection properties for this terminal
*/
reconnectionProperties?: IReconnectionProperties;
/** Whether to wait for a key press before closing the terminal. */
waitOnExit?: WaitOnExitValue;
/**
* A string including ANSI escape sequences that will be written to the terminal emulator
* _before_ the terminal process has launched, when a string is specified, a trailing \n is
* added at the end. This allows for example the terminal instance to display a styled message
* as the first line of the terminal. Use \x1b over \033 or \e for the escape control character.
*/
initialText?: string | { text: string; trailingNewLine: boolean };
/**
* Custom PTY/pseudoterminal process to use.
*/
customPtyImplementation?: (terminalId: number, cols: number, rows: number) => ITerminalChildProcess;
/**
* A UUID generated by the extension host process for terminals created on the extension host process.
*/
extHostTerminalId?: string;
/**
* This is a terminal that attaches to an already running terminal.
*/
attachPersistentProcess?: {
id: number;
findRevivedId?: boolean;
pid: number;
title: string;
titleSource: TitleEventSource;
cwd: string;
icon?: TerminalIcon;
color?: string;
hasChildProcesses?: boolean;
fixedDimensions?: IFixedTerminalDimensions;
environmentVariableCollections?: ISerializableEnvironmentVariableCollections;
reconnectionProperties?: IReconnectionProperties;
type?: TerminalType;
waitOnExit?: WaitOnExitValue;
hideFromUser?: boolean;
isFeatureTerminal?: boolean;
shellIntegrationNonce: string;
};
/**
* Whether the terminal process environment should be exactly as provided in
* `TerminalOptions.env`. When this is false (default), the environment will be based on the
* window's environment and also apply configured platform settings like
* `terminal.integrated.env.windows` on top. When this is true, the complete environment must be
* provided as nothing will be inherited from the process or any configuration.
*/
strictEnv?: boolean;
/**
* Whether the terminal process environment will inherit VS Code's "shell environment" that may
* get sourced from running a login shell depnding on how the application was launched.
* Consumers that rely on development tools being present in the $PATH should set this to true.
* This will overwrite the value of the inheritEnv setting.
*/
useShellEnvironment?: boolean;
/**
* When enabled the terminal will run the process as normal but not be surfaced to the user
* until `Terminal.show` is called. The typical usage for this is when you need to run
* something that may need interactivity but only want to tell the user about it when
* interaction is needed. Note that the terminals will still be exposed to all extensions
* as normal. The hidden terminals will not be restored when the workspace is next opened.
*/
hideFromUser?: boolean;
/**
* Whether this terminal is not a terminal that the user directly created and uses, but rather
* a terminal used to drive some VS Code feature.
*/
isFeatureTerminal?: boolean;
/**
* Whether this terminal was created by an extension.
*/
isExtensionOwnedTerminal?: boolean;
/**
* The icon for the terminal, used primarily in the terminal tab.
*/
icon?: TerminalIcon;
/**
* The color ID to use for this terminal. If not specified it will use the default fallback
*/
color?: string;
/**
* When a parent terminal is provided via API, the group needs
* to find the index in order to place the child
* directly to the right of its parent.
*/
parentTerminalId?: number;
/**
* The dimensions for the instance as set by the user
* or via Size to Content Width
*/
fixedDimensions?: IFixedTerminalDimensions;
/**
* Opt-out of the default terminal persistence on restart and reload
*/
isTransient?: boolean;
/**
* Attempt to force shell integration to be enabled by bypassing the {@link isFeatureTerminal}
* equals false requirement.
*/
forceShellIntegration?: boolean;
/**
* Create a terminal without shell integration even when it's enabled
*/
ignoreShellIntegration?: boolean;
}
export type WaitOnExitValue = boolean | string | ((exitCode: number) => string);
export interface ICreateContributedTerminalProfileOptions {
icon?: URI | string | { light: URI; dark: URI };
color?: string;
location?: TerminalLocation | { viewColumn: number; preserveState?: boolean } | { splitActiveTerminal: boolean };
cwd?: string | URI;
}
export enum TerminalLocation {
Panel = 1,
Editor = 2
}
export const enum TerminalLocationString {
TerminalView = 'view',
Editor = 'editor'
}
export type TerminalIcon = ThemeIcon | URI | { light: URI; dark: URI };
export interface IShellLaunchConfigDto {
name?: string;
executable?: string;
args?: string[] | string;
cwd?: string | UriComponents;
env?: ITerminalEnvironment;
useShellEnvironment?: boolean;
hideFromUser?: boolean;
reconnectionProperties?: IReconnectionProperties;
type?: 'Task' | 'Local';
isFeatureTerminal?: boolean;
}
/**
* A set of options for the terminal process. These differ from the shell launch config in that they
* are set internally to the terminal component, not from the outside.
*/
export interface ITerminalProcessOptions {
shellIntegration: {
enabled: boolean;
suggestEnabled: boolean;
nonce: string;
};
windowsEnableConpty: boolean;
windowsUseConptyDll: boolean;
environmentVariableCollections: ISerializableEnvironmentVariableCollections | undefined;
workspaceFolder: IWorkspaceFolder | undefined;
}
export interface ITerminalEnvironment {
[key: string]: string | null | undefined;
}
export interface ITerminalLaunchError {
message: string;
code?: number;
}
export interface IProcessReadyEvent {
pid: number;
cwd: string;
windowsPty: IProcessReadyWindowsPty | undefined;
}
export interface IProcessReadyWindowsPty {
/**
* What pty emulation backend is being used.
*/
backend: 'conpty' | 'winpty';
/**
* The Windows build version (eg. 19045)
*/
buildNumber: number;
}
/**
* An interface representing a raw terminal child process, this contains a subset of the
* child_process.ChildProcess node.js interface.
*/
export interface ITerminalChildProcess {
/**
* A unique identifier for the terminal process. Note that the uniqueness only applies to a
* given pty service connection, IDs will be duplicated for remote and local terminals for
* example. The ID will be 0 if it does not support reconnection.
*/
id: number;
/**
* Whether the process should be persisted across reloads.
*/
shouldPersist: boolean;
onProcessData: Event<IProcessDataEvent | string>;
onProcessReady: Event<IProcessReadyEvent>;
onProcessReplayComplete?: Event<void>;
onDidChangeProperty: Event<IProcessProperty<any>>;
onProcessExit: Event<number | undefined>;
onRestoreCommands?: Event<ISerializedCommandDetectionCapability>;
/**
* Starts the process.
*
* @returns undefined when the process was successfully started, otherwise an object containing
* information on what went wrong.
*/
start(): Promise<ITerminalLaunchError | { injectedArgs: string[] } | undefined>;
/**
* Detach the process from the UI and await reconnect.
* @param forcePersist Whether to force the process to persist if it supports persistence.
*/
detach?(forcePersist?: boolean): Promise<void>;
/**
* Frees the port and kills the process
*/
freePortKillProcess?(port: string): Promise<{ port: string; processId: string }>;
/**
* Shutdown the terminal process.
*
* @param immediate When true the process will be killed immediately, otherwise the process will
* be given some time to make sure no additional data comes through.
*/
shutdown(immediate: boolean): void;
input(data: string): void;
processBinary(data: string): Promise<void>;
resize(cols: number, rows: number): void;
clearBuffer(): void | Promise<void>;
/**
* Acknowledge a data event has been parsed by the terminal, this is used to implement flow
* control to ensure remote processes to not get too far ahead of the client and flood the
* connection.
* @param charCount The number of characters being acknowledged.
*/
acknowledgeDataEvent(charCount: number): void;
/**
* Sets the unicode version for the process, this drives the size of some characters in the
* xterm-headless instance.
*/
setUnicodeVersion(version: '6' | '11'): Promise<void>;
getInitialCwd(): Promise<string>;
getCwd(): Promise<string>;
refreshProperty<T extends ProcessPropertyType>(property: T): Promise<IProcessPropertyMap[T]>;
updateProperty<T extends ProcessPropertyType>(property: T, value: IProcessPropertyMap[T]): Promise<void>;
}
export interface IReconnectConstants {
graceTime: number;
shortGraceTime: number;
scrollback: number;
}
export const enum LocalReconnectConstants {
/**
* If there is no reconnection within this time-frame, consider the connection permanently closed...
*/
GraceTime = 60000, // 60 seconds
/**
* Maximal grace time between the first and the last reconnection...
*/
ShortGraceTime = 6000, // 6 seconds
}
export const enum FlowControlConstants {
/**
* The number of _unacknowledged_ chars to have been sent before the pty is paused in order for
* the client to catch up.
*/
HighWatermarkChars = 100000,
/**
* After flow control pauses the pty for the client the catch up, this is the number of
* _unacknowledged_ chars to have been caught up to on the client before resuming the pty again.
* This is used to attempt to prevent pauses in the flowing data; ideally while the pty is
* paused the number of unacknowledged chars would always be greater than 0 or the client will
* appear to stutter. In reality this balance is hard to accomplish though so heavy commands
* will likely pause as latency grows, not flooding the connection is the important thing as
* it's shared with other core functionality.
*/
LowWatermarkChars = 5000,
/**
* The number characters that are accumulated on the client side before sending an ack event.
* This must be less than or equal to LowWatermarkChars or the terminal max never unpause.
*/
CharCountAckSize = 5000
}
export interface IProcessDataEvent {
data: string;
trackCommit: boolean;
/**
* When trackCommit is set, this will be set to a promise that resolves when the data is parsed.
*/
writePromise?: Promise<void>;
}
export interface ITerminalDimensions {
/**
* The columns of the terminal.
*/
cols: number;
/**
* The rows of the terminal.
*/
rows: number;
}
export interface ITerminalProfile {
profileName: string;
path: string;
isDefault: boolean;
/**
* Whether the terminal profile contains a potentially unsafe {@link path}. For example, the path
* `C:\Cygwin` is the default install for Cygwin on Windows, but it could be created by any
* user in a multi-user environment. As such, we don't want to blindly present it as a profile
* without a warning.
*/
isUnsafePath?: boolean;
/**
* An additional unsafe path that must exist, for example a script that appears in {@link args}.
*/
requiresUnsafePath?: string;
isAutoDetected?: boolean;
/**
* Whether the profile path was found on the `$PATH` environment variable, if so it will be
* cleaner to display this profile in the UI using only `basename(path)`.
*/
isFromPath?: boolean;
args?: string | string[] | undefined;
env?: ITerminalEnvironment;
overrideName?: boolean;
color?: string;
icon?: ThemeIcon | URI | { light: URI; dark: URI };
}
export interface ITerminalDimensionsOverride extends Readonly<ITerminalDimensions> {
/**
* indicate that xterm must receive these exact dimensions, even if they overflow the ui!
*/
forceExactSize?: boolean;
}
export const enum ProfileSource {
GitBash = 'Git Bash',
Pwsh = 'PowerShell'
}
export interface IBaseUnresolvedTerminalProfile {
args?: string | string[] | undefined;
isAutoDetected?: boolean;
overrideName?: boolean;
icon?: string | ThemeIcon | URI | { light: URI; dark: URI };
color?: string;
env?: ITerminalEnvironment;
requiresPath?: string | ITerminalUnsafePath;
}
type OneOrN<T> = T | T[];
export interface ITerminalUnsafePath {
path: string;
isUnsafe: true;
}
export interface ITerminalExecutable extends IBaseUnresolvedTerminalProfile {
path: OneOrN<string | ITerminalUnsafePath>;
}
export interface ITerminalProfileSource extends IBaseUnresolvedTerminalProfile {
source: ProfileSource;
}
export interface ITerminalProfileContribution {
title: string;
id: string;
icon?: URI | { light: URI; dark: URI } | string;
color?: string;
}
export interface IExtensionTerminalProfile extends ITerminalProfileContribution {
extensionIdentifier: string;
}
export type ITerminalProfileObject = ITerminalExecutable | ITerminalProfileSource | IExtensionTerminalProfile | null;
export interface IShellIntegration {
readonly capabilities: ITerminalCapabilityStore;
readonly status: ShellIntegrationStatus;
readonly onDidChangeStatus: Event<ShellIntegrationStatus>;
deserialize(serialized: ISerializedCommandDetectionCapability): void;
}
export interface ITerminalContributions {
profiles?: ITerminalProfileContribution[];
}
export const enum ShellIntegrationStatus {
/** No shell integration sequences have been encountered. */
Off,
/** Final term shell integration sequences have been encountered. */
FinalTerm,
/** VS Code shell integration sequences have been encountered. Supercedes FinalTerm. */
VSCode
}
export enum TerminalExitReason {
Unknown = 0,
Shutdown = 1,
Process = 2,
User = 3,
Extension = 4,
}
export interface ITerminalOutputMatch {
regexMatch: RegExpMatchArray;
outputLines: string[];
}
/**
* A matcher that runs on a sub-section of a terminal command's output
*/
export interface ITerminalOutputMatcher {
/**
* A string or regex to match against the unwrapped line. If this is a regex with the multiline
* flag, it will scan an amount of lines equal to `\n` instances in the regex + 1.
*/
lineMatcher: string | RegExp;
/**
* Which side of the output to anchor the {@link offset} and {@link length} against.
*/
anchor: 'top' | 'bottom';
/**
* The number of rows above or below the {@link anchor} to start matching against.
*/
offset: number;
/**
* The number of rows to match against, this should be as small as possible for performance
* reasons. This is capped at 40.
*/
length: number;
/**
* If multiple matches are expected - this will result in {@link outputLines} being returned
* when there's a {@link regexMatch} from {@link offset} to {@link length}
*/
multipleMatches?: boolean;
}
export interface ITerminalCommandSelector {
id: string;
commandLineMatcher: string | RegExp;
outputMatcher?: ITerminalOutputMatcher;
exitStatus: boolean;
commandExitResult: 'success' | 'error';
kind?: 'fix' | 'explain';
}
export interface ITerminalBackend extends ITerminalBackendPtyServiceContributions {
readonly remoteAuthority: string | undefined;
readonly isResponsive: boolean;