55
66import 'vs/css!./media/developer' ;
77import { VSBuffer } from 'vs/base/common/buffer' ;
8- import { Disposable , MutableDisposable } from 'vs/base/common/lifecycle' ;
8+ import { Disposable , IDisposable , MutableDisposable , combinedDisposable , dispose } from 'vs/base/common/lifecycle' ;
99import { URI } from 'vs/base/common/uri' ;
1010import { localize } from 'vs/nls' ;
1111import { Categories } from 'vs/platform/action/common/actionCommonCategories' ;
@@ -23,7 +23,7 @@ import { TerminalWidgetManager } from 'vs/workbench/contrib/terminal/browser/wid
2323import { ITerminalProcessManager , TerminalCommandId } from 'vs/workbench/contrib/terminal/common/terminal' ;
2424import { TerminalContextKeys } from 'vs/workbench/contrib/terminal/common/terminalContextKey' ;
2525import type { Terminal } from '@xterm/xterm' ;
26- import { TerminalCapability } from 'vs/platform/terminal/common/capabilities/capabilities' ;
26+ import { ITerminalCommand , TerminalCapability } from 'vs/platform/terminal/common/capabilities/capabilities' ;
2727import { getWindow } from 'vs/base/browser/dom' ;
2828
2929registerTerminalAction ( {
@@ -156,48 +156,74 @@ class DevModeContribution extends Disposable implements ITerminalContribution {
156156 const commandDetection = this . _instance . capabilities . get ( TerminalCapability . CommandDetection ) ;
157157 if ( devMode ) {
158158 if ( commandDetection ) {
159- this . _activeDevModeDisposables . value = commandDetection . onCommandFinished ( command => {
160- const colorClass = `color-${ this . _currentColor } ` ;
161- if ( command . promptStartMarker ) {
162- const d = this . _instance . xterm ! . raw ?. registerDecoration ( {
163- marker : command . promptStartMarker
164- } ) ;
165- d ?. onRender ( e => {
166- e . textContent = 'A' ;
167- e . classList . add ( 'xterm-sequence-decoration' , 'top' , 'left' , colorClass ) ;
168- } ) ;
169- }
170- if ( command . marker ) {
171- const d = this . _instance . xterm ! . raw ?. registerDecoration ( {
172- marker : command . marker ,
173- x : command . startX
174- } ) ;
175- d ?. onRender ( e => {
176- e . textContent = 'B' ;
177- e . classList . add ( 'xterm-sequence-decoration' , 'top' , 'right' , colorClass ) ;
178- } ) ;
179- }
180- if ( command . executedMarker ) {
181- const d = this . _instance . xterm ! . raw ?. registerDecoration ( {
182- marker : command . executedMarker ,
183- x : command . executedX
184- } ) ;
185- d ?. onRender ( e => {
186- e . textContent = 'C' ;
187- e . classList . add ( 'xterm-sequence-decoration' , 'bottom' , 'left' , colorClass ) ;
188- } ) ;
189- }
190- if ( command . endMarker ) {
191- const d = this . _instance . xterm ! . raw ?. registerDecoration ( {
192- marker : command . endMarker
193- } ) ;
194- d ?. onRender ( e => {
195- e . textContent = 'D' ;
196- e . classList . add ( 'xterm-sequence-decoration' , 'bottom' , 'right' , colorClass ) ;
197- } ) ;
198- }
199- this . _currentColor = ( this . _currentColor + 1 ) % 2 ;
200- } ) ;
159+ const commandDecorations = new Map < ITerminalCommand , IDisposable [ ] > ( ) ;
160+ this . _activeDevModeDisposables . value = combinedDisposable (
161+ commandDetection . onCommandFinished ( command => {
162+ const colorClass = `color-${ this . _currentColor } ` ;
163+ const decorations : IDisposable [ ] = [ ] ;
164+ commandDecorations . set ( command , decorations ) ;
165+ if ( command . promptStartMarker ) {
166+ const d = this . _instance . xterm ! . raw ?. registerDecoration ( {
167+ marker : command . promptStartMarker
168+ } ) ;
169+ if ( d ) {
170+ decorations . push ( d ) ;
171+ d . onRender ( e => {
172+ e . textContent = 'A' ;
173+ e . classList . add ( 'xterm-sequence-decoration' , 'top' , 'left' , colorClass ) ;
174+ } ) ;
175+ }
176+ }
177+ if ( command . marker ) {
178+ const d = this . _instance . xterm ! . raw ?. registerDecoration ( {
179+ marker : command . marker ,
180+ x : command . startX
181+ } ) ;
182+ if ( d ) {
183+ decorations . push ( d ) ;
184+ d . onRender ( e => {
185+ e . textContent = 'B' ;
186+ e . classList . add ( 'xterm-sequence-decoration' , 'top' , 'right' , colorClass ) ;
187+ } ) ;
188+ }
189+ }
190+ if ( command . executedMarker ) {
191+ const d = this . _instance . xterm ! . raw ?. registerDecoration ( {
192+ marker : command . executedMarker ,
193+ x : command . executedX
194+ } ) ;
195+ if ( d ) {
196+ decorations . push ( d ) ;
197+ d . onRender ( e => {
198+ e . textContent = 'C' ;
199+ e . classList . add ( 'xterm-sequence-decoration' , 'bottom' , 'left' , colorClass ) ;
200+ } ) ;
201+ }
202+ }
203+ if ( command . endMarker ) {
204+ const d = this . _instance . xterm ! . raw ?. registerDecoration ( {
205+ marker : command . endMarker
206+ } ) ;
207+ if ( d ) {
208+ decorations . push ( d ) ;
209+ d . onRender ( e => {
210+ e . textContent = 'D' ;
211+ e . classList . add ( 'xterm-sequence-decoration' , 'bottom' , 'right' , colorClass ) ;
212+ } ) ;
213+ }
214+ }
215+ this . _currentColor = ( this . _currentColor + 1 ) % 2 ;
216+ } ) ,
217+ commandDetection . onCommandInvalidated ( commands => {
218+ for ( const c of commands ) {
219+ const decorations = commandDecorations . get ( c ) ;
220+ if ( decorations ) {
221+ dispose ( decorations ) ;
222+ }
223+ commandDecorations . delete ( c ) ;
224+ }
225+ } )
226+ ) ;
201227 } else {
202228 this . _activeDevModeDisposables . value = this . _instance . capabilities . onDidAddCapabilityType ( e => {
203229 if ( e === TerminalCapability . CommandDetection ) {
0 commit comments