@@ -9,15 +9,20 @@ import { Schemas } from 'vs/base/common/network';
9
9
import { withNullAsUndefined } from 'vs/base/common/types' ;
10
10
import { localize } from 'vs/nls' ;
11
11
import { ILogService } from 'vs/platform/log/common/log' ;
12
- import { INotificationHandle , INotificationService , IPromptChoice , Severity } from 'vs/platform/notification/common/notification' ;
13
12
import { ICrossVersionSerializedTerminalState , IPtyHostController , ISerializedTerminalState } from 'vs/platform/terminal/common/terminal' ;
13
+ import { themeColorFromId } from 'vs/platform/theme/common/themeService' ;
14
14
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace' ;
15
+ import { STATUS_BAR_WARNING_ITEM_BACKGROUND , STATUS_BAR_WARNING_ITEM_FOREGROUND } from 'vs/workbench/common/theme' ;
16
+ import { TerminalCommandId } from 'vs/workbench/contrib/terminal/common/terminal' ;
15
17
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver' ;
16
18
import { IHistoryService } from 'vs/workbench/services/history/common/history' ;
19
+ import { IStatusbarEntry , IStatusbarEntryAccessor , IStatusbarService , StatusbarAlignment } from 'vs/workbench/services/statusbar/browser/statusbar' ;
17
20
18
21
export abstract class BaseTerminalBackend extends Disposable {
19
22
private _isPtyHostUnresponsive : boolean = false ;
20
23
24
+ get isResponsive ( ) : boolean { return ! this . _isPtyHostUnresponsive ; }
25
+
21
26
protected readonly _onPtyHostRestart = this . _register ( new Emitter < void > ( ) ) ;
22
27
readonly onPtyHostRestart = this . _onPtyHostRestart . event ;
23
28
protected readonly _onPtyHostUnresponsive = this . _register ( new Emitter < void > ( ) ) ;
@@ -26,55 +31,63 @@ export abstract class BaseTerminalBackend extends Disposable {
26
31
readonly onPtyHostResponsive = this . _onPtyHostResponsive . event ;
27
32
28
33
constructor (
29
- eventSource : IPtyHostController ,
34
+ private readonly _ptyHostController : IPtyHostController ,
30
35
protected readonly _logService : ILogService ,
31
- notificationService : INotificationService ,
32
36
historyService : IHistoryService ,
33
37
configurationResolverService : IConfigurationResolverService ,
38
+ statusBarService : IStatusbarService ,
34
39
protected readonly _workspaceContextService : IWorkspaceContextService
35
40
) {
36
41
super ( ) ;
37
42
43
+ let unresponsiveStatusBarEntry : IStatusbarEntry ;
44
+ let statusBarAccessor : IStatusbarEntryAccessor ;
45
+
38
46
// Attach pty host listeners
39
- if ( eventSource . onPtyHostExit ) {
40
- this . _register ( eventSource . onPtyHostExit ( ( ) => {
47
+ if ( this . _ptyHostController . onPtyHostExit ) {
48
+ this . _register ( this . _ptyHostController . onPtyHostExit ( ( ) => {
41
49
this . _logService . error ( `The terminal's pty host process exited, the connection to all terminal processes was lost` ) ;
42
50
} ) ) ;
43
51
}
44
- let unresponsiveNotification : INotificationHandle | undefined ;
45
- if ( eventSource . onPtyHostStart ) {
46
- this . _register ( eventSource . onPtyHostStart ( ( ) => {
52
+ if ( this . _ptyHostController . onPtyHostStart ) {
53
+ this . _register ( this . _ptyHostController . onPtyHostStart ( ( ) => {
47
54
this . _onPtyHostRestart . fire ( ) ;
48
- unresponsiveNotification ?. close ( ) ;
49
- unresponsiveNotification = undefined ;
55
+ statusBarAccessor ?. dispose ( ) ;
50
56
this . _isPtyHostUnresponsive = false ;
51
57
} ) ) ;
52
58
}
53
- if ( eventSource . onPtyHostUnresponsive ) {
54
- this . _register ( eventSource . onPtyHostUnresponsive ( ( ) => {
55
- const choices : IPromptChoice [ ] = [ {
56
- label : localize ( 'restartPtyHost' , "Restart pty host" ) ,
57
- run : ( ) => eventSource . restartPtyHost ! ( )
58
- } ] ;
59
- unresponsiveNotification = notificationService . prompt ( Severity . Error , localize ( 'nonResponsivePtyHost' , "The connection to the terminal's pty host process is unresponsive, the terminals may stop working." ) , choices ) ;
59
+ if ( this . _ptyHostController . onPtyHostUnresponsive ) {
60
+ this . _register ( this . _ptyHostController . onPtyHostUnresponsive ( ( ) => {
61
+ statusBarAccessor ?. dispose ( ) ;
62
+ if ( ! unresponsiveStatusBarEntry ) {
63
+ unresponsiveStatusBarEntry = {
64
+ name : localize ( 'ptyHostStatus' , 'Pty Host Status' ) ,
65
+ text : `$(debug-disconnect) ${ localize ( 'ptyHostStatus.short' , 'Pty Host' ) } ` ,
66
+ tooltip : localize ( 'nonResponsivePtyHost' , "The connection to the terminal's pty host process is unresponsive, terminals may stop working. Click to manually restart the pty host." ) ,
67
+ ariaLabel : localize ( 'ptyHostStatus.ariaLabel' , 'Pty Host is unresponsive' ) ,
68
+ command : TerminalCommandId . RestartPtyHost ,
69
+ backgroundColor : themeColorFromId ( STATUS_BAR_WARNING_ITEM_BACKGROUND ) ,
70
+ color : themeColorFromId ( STATUS_BAR_WARNING_ITEM_FOREGROUND ) ,
71
+ } ;
72
+ }
73
+ statusBarAccessor = statusBarService . addEntry ( unresponsiveStatusBarEntry , 'ptyHostStatus' , StatusbarAlignment . LEFT ) ;
60
74
this . _isPtyHostUnresponsive = true ;
61
75
this . _onPtyHostUnresponsive . fire ( ) ;
62
76
} ) ) ;
63
77
}
64
- if ( eventSource . onPtyHostResponsive ) {
65
- this . _register ( eventSource . onPtyHostResponsive ( ( ) => {
78
+ if ( this . _ptyHostController . onPtyHostResponsive ) {
79
+ this . _register ( this . _ptyHostController . onPtyHostResponsive ( ( ) => {
66
80
if ( ! this . _isPtyHostUnresponsive ) {
67
81
return ;
68
82
}
69
83
this . _logService . info ( 'The pty host became responsive again' ) ;
70
- unresponsiveNotification ?. close ( ) ;
71
- unresponsiveNotification = undefined ;
84
+ statusBarAccessor ?. dispose ( ) ;
72
85
this . _isPtyHostUnresponsive = false ;
73
86
this . _onPtyHostResponsive . fire ( ) ;
74
87
} ) ) ;
75
88
}
76
- if ( eventSource . onPtyHostRequestResolveVariables ) {
77
- this . _register ( eventSource . onPtyHostRequestResolveVariables ( async e => {
89
+ if ( this . _ptyHostController . onPtyHostRequestResolveVariables ) {
90
+ this . _register ( this . _ptyHostController . onPtyHostRequestResolveVariables ( async e => {
78
91
// Only answer requests for this workspace
79
92
if ( e . workspaceId !== this . _workspaceContextService . getWorkspace ( ) . id ) {
80
93
return ;
@@ -85,11 +98,15 @@ export abstract class BaseTerminalBackend extends Disposable {
85
98
return configurationResolverService . resolveAsync ( lastActiveWorkspaceRoot , t ) ;
86
99
} ) ;
87
100
const result = await Promise . all ( resolveCalls ) ;
88
- eventSource . acceptPtyHostResolvedVariables ?.( e . requestId , result ) ;
101
+ this . _ptyHostController . acceptPtyHostResolvedVariables ?.( e . requestId , result ) ;
89
102
} ) ) ;
90
103
}
91
104
}
92
105
106
+ restartPtyHost ( ) : void {
107
+ this . _ptyHostController . restartPtyHost ?.( ) ;
108
+ }
109
+
93
110
protected _deserializeTerminalState ( serializedState : string | undefined ) : ISerializedTerminalState [ ] | undefined {
94
111
if ( serializedState === undefined ) {
95
112
return undefined ;
0 commit comments