@@ -13,6 +13,7 @@ import { ThemeIcon } from 'vs/base/common/themables';
13
13
import { ISerializableEnvironmentVariableCollections } from 'vs/platform/terminal/common/environmentVariable' ;
14
14
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey' ;
15
15
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace' ;
16
+ import { Registry } from 'vs/platform/registry/common/platform' ;
16
17
import type * as performance from 'vs/base/common/performance' ;
17
18
18
19
export const terminalTabFocusContextKey = new RawContextKey < boolean > ( 'terminalTabFocusMode' , false , true ) ;
@@ -946,6 +947,108 @@ export interface ITerminalCommandSelector {
946
947
commandExitResult : 'success' | 'error' ;
947
948
}
948
949
950
+ export interface ITerminalBackend {
951
+ readonly remoteAuthority : string | undefined ;
952
+
953
+ readonly isResponsive : boolean ;
954
+ readonly whenConnected : Promise < void > ;
955
+ setConnected ( ) : void ;
956
+
957
+ /**
958
+ * Fired when the ptyHost process becomes non-responsive, this should disable stdin for all
959
+ * terminals using this pty host connection and mark them as disconnected.
960
+ */
961
+ onPtyHostUnresponsive : Event < void > ;
962
+ /**
963
+ * Fired when the ptyHost process becomes responsive after being non-responsive. Allowing
964
+ * previously disconnected terminals to reconnect.
965
+ */
966
+ onPtyHostResponsive : Event < void > ;
967
+ /**
968
+ * Fired when the ptyHost has been restarted, this is used as a signal for listening terminals
969
+ * that its pty has been lost and will remain disconnected.
970
+ */
971
+ onPtyHostRestart : Event < void > ;
972
+
973
+ onDidRequestDetach : Event < { requestId : number ; workspaceId : string ; instanceId : number } > ;
974
+
975
+ attachToProcess ( id : number ) : Promise < ITerminalChildProcess | undefined > ;
976
+ attachToRevivedProcess ( id : number ) : Promise < ITerminalChildProcess | undefined > ;
977
+ listProcesses ( ) : Promise < IProcessDetails [ ] > ;
978
+ getDefaultSystemShell ( osOverride ?: OperatingSystem ) : Promise < string > ;
979
+ getProfiles ( profiles : unknown , defaultProfile : unknown , includeDetectedProfiles ?: boolean ) : Promise < ITerminalProfile [ ] > ;
980
+ getWslPath ( original : string , direction : 'unix-to-win' | 'win-to-unix' ) : Promise < string > ;
981
+ getEnvironment ( ) : Promise < IProcessEnvironment > ;
982
+ getShellEnvironment ( ) : Promise < IProcessEnvironment | undefined > ;
983
+ setTerminalLayoutInfo ( layoutInfo ?: ITerminalsLayoutInfoById ) : Promise < void > ;
984
+ updateTitle ( id : number , title : string , titleSource : TitleEventSource ) : Promise < void > ;
985
+ updateIcon ( id : number , userInitiated : boolean , icon : TerminalIcon , color ?: string ) : Promise < void > ;
986
+ getTerminalLayoutInfo ( ) : Promise < ITerminalsLayoutInfo | undefined > ;
987
+ getPerformanceMarks ( ) : Promise < performance . PerformanceMark [ ] > ;
988
+ reduceConnectionGraceTime ( ) : Promise < void > ;
989
+ requestDetachInstance ( workspaceId : string , instanceId : number ) : Promise < IProcessDetails | undefined > ;
990
+ acceptDetachInstanceReply ( requestId : number , persistentProcessId ?: number ) : Promise < void > ;
991
+ persistTerminalState ( ) : Promise < void > ;
992
+
993
+ createProcess (
994
+ shellLaunchConfig : IShellLaunchConfig ,
995
+ cwd : string ,
996
+ cols : number ,
997
+ rows : number ,
998
+ unicodeVersion : '6' | '11' ,
999
+ env : IProcessEnvironment ,
1000
+ options : ITerminalProcessOptions ,
1001
+ shouldPersist : boolean
1002
+ ) : Promise < ITerminalChildProcess > ;
1003
+
1004
+ restartPtyHost ( ) : void ;
1005
+ }
1006
+
1007
+ export const TerminalExtensions = {
1008
+ Backend : 'workbench.contributions.terminal.processBackend'
1009
+ } ;
1010
+
1011
+ export interface ITerminalBackendRegistry {
1012
+ /**
1013
+ * Gets all backends in the registry.
1014
+ */
1015
+ backends : ReadonlyMap < string , ITerminalBackend > ;
1016
+
1017
+ /**
1018
+ * Registers a terminal backend for a remote authority.
1019
+ */
1020
+ registerTerminalBackend ( backend : ITerminalBackend ) : void ;
1021
+
1022
+ /**
1023
+ * Returns the registered terminal backend for a remote authority.
1024
+ */
1025
+ getTerminalBackend ( remoteAuthority ?: string ) : ITerminalBackend | undefined ;
1026
+ }
1027
+
1028
+ class TerminalBackendRegistry implements ITerminalBackendRegistry {
1029
+ private readonly _backends = new Map < string , ITerminalBackend > ( ) ;
1030
+
1031
+ get backends ( ) : ReadonlyMap < string , ITerminalBackend > { return this . _backends ; }
1032
+
1033
+ registerTerminalBackend ( backend : ITerminalBackend ) : void {
1034
+ const key = this . _sanitizeRemoteAuthority ( backend . remoteAuthority ) ;
1035
+ if ( this . _backends . has ( key ) ) {
1036
+ throw new Error ( `A terminal backend with remote authority '${ key } ' was already registered.` ) ;
1037
+ }
1038
+ this . _backends . set ( key , backend ) ;
1039
+ }
1040
+
1041
+ getTerminalBackend ( remoteAuthority : string | undefined ) : ITerminalBackend | undefined {
1042
+ return this . _backends . get ( this . _sanitizeRemoteAuthority ( remoteAuthority ) ) ;
1043
+ }
1044
+
1045
+ private _sanitizeRemoteAuthority ( remoteAuthority : string | undefined ) {
1046
+ // Normalize the key to lowercase as the authority is case-insensitive
1047
+ return remoteAuthority ?. toLowerCase ( ) ?? '' ;
1048
+ }
1049
+ }
1050
+ Registry . add ( TerminalExtensions . Backend , new TerminalBackendRegistry ( ) ) ;
1051
+
949
1052
export const ILocalPtyService = createDecorator < ILocalPtyService > ( 'localPtyService' ) ;
950
1053
951
1054
/**
0 commit comments