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