@@ -19,8 +19,10 @@ import { Codicon } from 'vs/base/common/codicons';
19
19
20
20
export class TerminalSpeechToTextSession extends Disposable {
21
21
private _input : string = '' ;
22
+ private _ghostText : IDecoration | undefined ;
22
23
private _decoration : IDecoration | undefined ;
23
24
private _marker : IXtermMarker | undefined ;
25
+ private _ghostTextMarker : IXtermMarker | undefined ;
24
26
private static _instance : TerminalSpeechToTextSession | undefined = undefined ;
25
27
private _acceptTranscriptionScheduler : RunOnceScheduler | undefined ;
26
28
static getInstance ( instantiationService : IInstantiationService ) : TerminalSpeechToTextSession {
@@ -69,6 +71,7 @@ export class TerminalSpeechToTextSession extends Disposable {
69
71
break ;
70
72
case SpeechToTextStatus . Recognizing : {
71
73
this . _updateInput ( e ) ;
74
+ this . _renderGhostText ( e ) ;
72
75
if ( voiceTimeout > 0 ) {
73
76
this . _acceptTranscriptionScheduler ! . cancel ( ) ;
74
77
}
@@ -94,6 +97,9 @@ export class TerminalSpeechToTextSession extends Disposable {
94
97
this . _terminalService . activeInstance ?. sendText ( this . _input , false ) ;
95
98
}
96
99
this . _marker ?. dispose ( ) ;
100
+ this . _ghostTextMarker ?. dispose ( ) ;
101
+ this . _ghostText ?. dispose ( ) ;
102
+ this . _ghostText = undefined ;
97
103
this . _decoration ?. dispose ( ) ;
98
104
this . _decoration = undefined ;
99
105
this . _cancellationTokenSource ?. cancel ( ) ;
@@ -165,6 +171,33 @@ export class TerminalSpeechToTextSession extends Disposable {
165
171
private _setInactive ( ) : void {
166
172
this . _decoration ?. element ?. classList . remove ( 'recording' ) ;
167
173
}
174
+
175
+ private _renderGhostText ( e : ISpeechToTextEvent ) : void {
176
+ this . _ghostText ?. dispose ( ) ;
177
+ const text = e . text ;
178
+ if ( ! text ) {
179
+ return ;
180
+ }
181
+ const activeInstance = this . _terminalService . activeInstance ;
182
+ const xterm = activeInstance ?. xterm ?. raw ;
183
+ if ( ! xterm ) {
184
+ return ;
185
+ }
186
+ this . _ghostTextMarker = activeInstance . registerMarker ( ) ;
187
+ if ( ! this . _ghostTextMarker ) {
188
+ return ;
189
+ }
190
+ this . _ghostText = xterm . registerDecoration ( {
191
+ marker : this . _ghostTextMarker ,
192
+ layer : 'top' ,
193
+ x : xterm . buffer . active . cursorX + 1 ?? 0 ,
194
+ } ) ;
195
+ this . _ghostText ?. onRender ( ( e : HTMLElement ) => {
196
+ e . classList . add ( 'terminal-speech-progress-text' ) ;
197
+ e . textContent = text ;
198
+ e . style . width = 'fit-content' ;
199
+ } ) ;
200
+ }
168
201
}
169
202
170
203
0 commit comments