@@ -9,15 +9,20 @@ import { Schemas } from 'vs/base/common/network';
99import { withNullAsUndefined } from 'vs/base/common/types' ;
1010import { localize } from 'vs/nls' ;
1111import { ILogService } from 'vs/platform/log/common/log' ;
12- import { INotificationHandle , INotificationService , IPromptChoice , Severity } from 'vs/platform/notification/common/notification' ;
1312import { ICrossVersionSerializedTerminalState , IPtyHostController , ISerializedTerminalState } from 'vs/platform/terminal/common/terminal' ;
13+ import { themeColorFromId } from 'vs/platform/theme/common/themeService' ;
1414import { 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' ;
1517import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver' ;
1618import { IHistoryService } from 'vs/workbench/services/history/common/history' ;
19+ import { IStatusbarEntry , IStatusbarEntryAccessor , IStatusbarService , StatusbarAlignment } from 'vs/workbench/services/statusbar/browser/statusbar' ;
1720
1821export abstract class BaseTerminalBackend extends Disposable {
1922 private _isPtyHostUnresponsive : boolean = false ;
2023
24+ get isResponsive ( ) : boolean { return ! this . _isPtyHostUnresponsive ; }
25+
2126 protected readonly _onPtyHostRestart = this . _register ( new Emitter < void > ( ) ) ;
2227 readonly onPtyHostRestart = this . _onPtyHostRestart . event ;
2328 protected readonly _onPtyHostUnresponsive = this . _register ( new Emitter < void > ( ) ) ;
@@ -26,55 +31,63 @@ export abstract class BaseTerminalBackend extends Disposable {
2631 readonly onPtyHostResponsive = this . _onPtyHostResponsive . event ;
2732
2833 constructor (
29- eventSource : IPtyHostController ,
34+ private readonly _ptyHostController : IPtyHostController ,
3035 protected readonly _logService : ILogService ,
31- notificationService : INotificationService ,
3236 historyService : IHistoryService ,
3337 configurationResolverService : IConfigurationResolverService ,
38+ statusBarService : IStatusbarService ,
3439 protected readonly _workspaceContextService : IWorkspaceContextService
3540 ) {
3641 super ( ) ;
3742
43+ let unresponsiveStatusBarEntry : IStatusbarEntry ;
44+ let statusBarAccessor : IStatusbarEntryAccessor ;
45+
3846 // Attach pty host listeners
39- if ( eventSource . onPtyHostExit ) {
40- this . _register ( eventSource . onPtyHostExit ( ( ) => {
47+ if ( this . _ptyHostController . onPtyHostExit ) {
48+ this . _register ( this . _ptyHostController . onPtyHostExit ( ( ) => {
4149 this . _logService . error ( `The terminal's pty host process exited, the connection to all terminal processes was lost` ) ;
4250 } ) ) ;
4351 }
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 ( ( ) => {
4754 this . _onPtyHostRestart . fire ( ) ;
48- unresponsiveNotification ?. close ( ) ;
49- unresponsiveNotification = undefined ;
55+ statusBarAccessor ?. dispose ( ) ;
5056 this . _isPtyHostUnresponsive = false ;
5157 } ) ) ;
5258 }
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 ) ;
6074 this . _isPtyHostUnresponsive = true ;
6175 this . _onPtyHostUnresponsive . fire ( ) ;
6276 } ) ) ;
6377 }
64- if ( eventSource . onPtyHostResponsive ) {
65- this . _register ( eventSource . onPtyHostResponsive ( ( ) => {
78+ if ( this . _ptyHostController . onPtyHostResponsive ) {
79+ this . _register ( this . _ptyHostController . onPtyHostResponsive ( ( ) => {
6680 if ( ! this . _isPtyHostUnresponsive ) {
6781 return ;
6882 }
6983 this . _logService . info ( 'The pty host became responsive again' ) ;
70- unresponsiveNotification ?. close ( ) ;
71- unresponsiveNotification = undefined ;
84+ statusBarAccessor ?. dispose ( ) ;
7285 this . _isPtyHostUnresponsive = false ;
7386 this . _onPtyHostResponsive . fire ( ) ;
7487 } ) ) ;
7588 }
76- if ( eventSource . onPtyHostRequestResolveVariables ) {
77- this . _register ( eventSource . onPtyHostRequestResolveVariables ( async e => {
89+ if ( this . _ptyHostController . onPtyHostRequestResolveVariables ) {
90+ this . _register ( this . _ptyHostController . onPtyHostRequestResolveVariables ( async e => {
7891 // Only answer requests for this workspace
7992 if ( e . workspaceId !== this . _workspaceContextService . getWorkspace ( ) . id ) {
8093 return ;
@@ -85,11 +98,15 @@ export abstract class BaseTerminalBackend extends Disposable {
8598 return configurationResolverService . resolveAsync ( lastActiveWorkspaceRoot , t ) ;
8699 } ) ;
87100 const result = await Promise . all ( resolveCalls ) ;
88- eventSource . acceptPtyHostResolvedVariables ?.( e . requestId , result ) ;
101+ this . _ptyHostController . acceptPtyHostResolvedVariables ?.( e . requestId , result ) ;
89102 } ) ) ;
90103 }
91104 }
92105
106+ restartPtyHost ( ) : void {
107+ this . _ptyHostController . restartPtyHost ?.( ) ;
108+ }
109+
93110 protected _deserializeTerminalState ( serializedState : string | undefined ) : ISerializedTerminalState [ ] | undefined {
94111 if ( serializedState === undefined ) {
95112 return undefined ;
0 commit comments