@@ -16,15 +16,14 @@ import { IOpenerService } from 'vs/platform/opener/common/opener';
16
16
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput' ;
17
17
import { ITerminalLogService , TerminalSettingId } from 'vs/platform/terminal/common/terminal' ;
18
18
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace' ;
19
- import { IInternalXtermTerminal , ITerminalConfigurationService , ITerminalContribution , ITerminalInstance , IXtermTerminal } from 'vs/workbench/contrib/terminal/browser/terminal' ;
19
+ import { IInternalXtermTerminal , ITerminalContribution , ITerminalInstance , IXtermTerminal } from 'vs/workbench/contrib/terminal/browser/terminal' ;
20
20
import { registerTerminalAction } from 'vs/workbench/contrib/terminal/browser/terminalActions' ;
21
21
import { registerTerminalContribution } from 'vs/workbench/contrib/terminal/browser/terminalExtensions' ;
22
22
import { TerminalWidgetManager } from 'vs/workbench/contrib/terminal/browser/widgets/widgetManager' ;
23
23
import { ITerminalProcessManager , TerminalCommandId } from 'vs/workbench/contrib/terminal/common/terminal' ;
24
24
import { TerminalContextKeys } from 'vs/workbench/contrib/terminal/common/terminalContextKey' ;
25
25
import type { Terminal } from '@xterm/xterm' ;
26
- import { ITerminalCommand , TerminalCapability } from 'vs/platform/terminal/common/capabilities/capabilities' ;
27
- import { getWindow } from 'vs/base/browser/dom' ;
26
+ import { ITerminalCommand , TerminalCapability , type ICommandDetectionCapability } from 'vs/platform/terminal/common/capabilities/capabilities' ;
28
27
import { IStatusbarService , StatusbarAlignment , type IStatusbarEntry , type IStatusbarEntryAccessor } from 'vs/workbench/services/statusbar/browser/statusbar' ;
29
28
30
29
registerTerminalAction ( {
@@ -123,14 +122,13 @@ class DevModeContribution extends Disposable implements ITerminalContribution {
123
122
private _currentColor = 0 ;
124
123
125
124
private _statusbarEntry : IStatusbarEntry | undefined ;
126
- private _statusbarEntryAccessor : IStatusbarEntryAccessor | undefined ;
125
+ private readonly _statusbarEntryAccessor : MutableDisposable < IStatusbarEntryAccessor > = this . _register ( new MutableDisposable ( ) ) ;
127
126
128
127
constructor (
129
128
private readonly _instance : ITerminalInstance ,
130
129
processManager : ITerminalProcessManager ,
131
130
widgetManager : TerminalWidgetManager ,
132
131
@IConfigurationService private readonly _configurationService : IConfigurationService ,
133
- @ITerminalConfigurationService private readonly _terminalConfigurationService : ITerminalConfigurationService ,
134
132
@IStatusbarService private readonly _statusbarService : IStatusbarService ,
135
133
) {
136
134
super ( ) ;
@@ -139,19 +137,6 @@ class DevModeContribution extends Disposable implements ITerminalContribution {
139
137
this . _updateDevMode ( ) ;
140
138
}
141
139
} ) ) ;
142
-
143
- setTimeout ( ( ) => {
144
- const commandDetection = this . _instance . capabilities . get ( TerminalCapability . CommandDetection )
145
- if ( commandDetection ) {
146
- // TODO: Listen to capability add
147
- // TODO: Add util for when capability is available?
148
- commandDetection . promptInputModel . onDidChangeInput ( ( ) => {
149
- // TODO: Create a status bar item sync
150
- // TODO: Only show focused instance status bar item
151
- this . _updateDevMode ( ) ;
152
- } ) ;
153
- }
154
- } , 2000 ) ;
155
140
}
156
141
157
142
xtermReady ( xterm : IXtermTerminal & { raw : Terminal } ) : void {
@@ -163,38 +148,16 @@ class DevModeContribution extends Disposable implements ITerminalContribution {
163
148
const devMode : boolean = this . _isEnabled ( ) ;
164
149
this . _xterm ?. raw . element ?. classList . toggle ( 'dev-mode' , devMode ) ;
165
150
166
- const promptInputModel = this . _instance . capabilities . get ( TerminalCapability . CommandDetection ) ?. promptInputModel
167
- if ( promptInputModel ) {
168
- // Text area syncing
169
- const promptInput = promptInputModel . value . replaceAll ( '\n' , '\u23CE' ) ;
170
- this . _statusbarEntry = {
171
- name : localize ( 'terminalDevMode' , 'Terminal Dev Mode' ) ,
172
- text : `$(terminal) ${ promptInput . substring ( 0 , promptInputModel . cursorIndex ) } |${ promptInput . substring ( promptInputModel . cursorIndex ) } ` ,
173
- // 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."),
174
- ariaLabel : localize ( 'ptyHostStatus.ariaLabel' , 'test' ) ,
175
- // command: TerminalCommandId.RestartPtyHost,
176
- kind : 'warning'
177
- } ;
178
- if ( ! this . _statusbarEntryAccessor ) {
179
- console . log ( '1' ) ;
180
- this . _statusbarEntryAccessor = this . _statusbarService . addEntry ( this . _statusbarEntry , 'terminal.promptInput' , StatusbarAlignment . LEFT ) ;
181
- } else {
182
- console . log ( '2' ) ;
183
- this . _statusbarEntryAccessor . update ( this . _statusbarEntry ) ;
184
- }
185
- }
186
- if ( this . _xterm ?. raw . textarea ) {
187
- const font = this . _terminalConfigurationService . getFont ( getWindow ( this . _xterm . raw . textarea ) ) ;
188
- this . _xterm . raw . textarea . style . fontFamily = font . fontFamily ;
189
- this . _xterm . raw . textarea . style . fontSize = `${ font . fontSize } px` ;
190
- }
191
-
192
- // Sequence markers
193
151
const commandDetection = this . _instance . capabilities . get ( TerminalCapability . CommandDetection ) ;
194
152
if ( devMode ) {
195
153
if ( commandDetection ) {
196
154
const commandDecorations = new Map < ITerminalCommand , IDisposable [ ] > ( ) ;
197
155
this . _activeDevModeDisposables . value = combinedDisposable (
156
+ // Prompt input
157
+ this . _instance . onDidBlur ( ( ) => this . _updateDevMode ( ) ) ,
158
+ this . _instance . onDidFocus ( ( ) => this . _updateDevMode ( ) ) ,
159
+ commandDetection . promptInputModel . onDidChangeInput ( ( ) => this . _updateDevMode ( ) ) ,
160
+ // Sequence markers
198
161
commandDetection . onCommandFinished ( command => {
199
162
const colorClass = `color-${ this . _currentColor } ` ;
200
163
const decorations : IDisposable [ ] = [ ] ;
@@ -261,6 +224,8 @@ class DevModeContribution extends Disposable implements ITerminalContribution {
261
224
}
262
225
} )
263
226
) ;
227
+
228
+ this . _updatePromptInputStatusBar ( commandDetection ) ;
264
229
} else {
265
230
this . _activeDevModeDisposables . value = this . _instance . capabilities . onDidAddCapabilityType ( e => {
266
231
if ( e === TerminalCapability . CommandDetection ) {
@@ -276,6 +241,25 @@ class DevModeContribution extends Disposable implements ITerminalContribution {
276
241
private _isEnabled ( ) : boolean {
277
242
return this . _configurationService . getValue ( TerminalSettingId . DevMode ) || false ;
278
243
}
244
+
245
+ private _updatePromptInputStatusBar ( commandDetection : ICommandDetectionCapability ) {
246
+ const promptInputModel = commandDetection . promptInputModel ;
247
+ if ( promptInputModel ) {
248
+ const promptInput = promptInputModel . value . replaceAll ( '\n' , '\u23CE' ) ;
249
+ this . _statusbarEntry = {
250
+ name : localize ( 'terminalDevMode' , 'Terminal Dev Mode' ) ,
251
+ text : `$(terminal) ${ promptInput . substring ( 0 , promptInputModel . cursorIndex ) } |${ promptInput . substring ( promptInputModel . cursorIndex ) } ` ,
252
+ ariaLabel : localize ( 'terminalDevMode' , 'Terminal Dev Mode' ) ,
253
+ kind : 'warning'
254
+ } ;
255
+ if ( ! this . _statusbarEntryAccessor . value ) {
256
+ this . _statusbarEntryAccessor . value = this . _statusbarService . addEntry ( this . _statusbarEntry , `terminal.promptInput.${ this . _instance . instanceId } ` , StatusbarAlignment . LEFT ) ;
257
+ } else {
258
+ this . _statusbarEntryAccessor . value . update ( this . _statusbarEntry ) ;
259
+ }
260
+ this . _statusbarService . updateEntryVisibility ( `terminal.promptInput.${ this . _instance . instanceId } ` , this . _instance . hasFocus ) ;
261
+ }
262
+ }
279
263
}
280
264
281
265
registerTerminalContribution ( DevModeContribution . ID , DevModeContribution ) ;
0 commit comments