@@ -121,20 +121,48 @@ export async function getCwdForSplit(
121
121
}
122
122
123
123
export const terminalSendSequenceCommand = async ( accessor : ServicesAccessor , args : unknown ) => {
124
- const instance = accessor . get ( ITerminalService ) . activeInstance ;
125
- if ( instance ) {
126
- const text = isObject ( args ) && 'text' in args ? toOptionalString ( args . text ) : undefined ;
124
+ const terminalService = accessor . get ( ITerminalService ) ;
125
+ const instance = terminalService . activeInstance || await terminalService . getActiveOrCreateInstance ( ) ;
126
+ if ( ! instance ) {
127
+ return ;
128
+ }
129
+
130
+ let text = isObject ( args ) && 'text' in args ? toOptionalString ( args . text ) : undefined ;
131
+
132
+ // If no text provided, prompt user for input
133
+ if ( ! text ) {
134
+ const quickInputService = accessor . get ( IQuickInputService ) ;
135
+ text = await quickInputService . input ( {
136
+ value : '' ,
137
+ placeHolder : 'Enter sequence to send (supports \\n, \\r, \\x escape sequences)' ,
138
+ prompt : localize ( 'workbench.action.terminal.sendSequence.prompt' , "Enter sequence to send to the terminal" ) ,
139
+ } ) ;
127
140
if ( ! text ) {
128
141
return ;
129
142
}
130
- const configurationResolverService = accessor . get ( IConfigurationResolverService ) ;
131
- const workspaceContextService = accessor . get ( IWorkspaceContextService ) ;
132
- const historyService = accessor . get ( IHistoryService ) ;
133
- const activeWorkspaceRootUri = historyService . getLastActiveWorkspaceRoot ( instance . isRemote ? Schemas . vscodeRemote : Schemas . file ) ;
134
- const lastActiveWorkspaceRoot = activeWorkspaceRootUri ? workspaceContextService . getWorkspaceFolder ( activeWorkspaceRootUri ) ?? undefined : undefined ;
135
- const resolvedText = await configurationResolverService . resolveAsync ( lastActiveWorkspaceRoot , text ) ;
136
- instance . sendText ( resolvedText , false ) ;
137
143
}
144
+
145
+ // Process escape sequences similar to WriteDataToTerminal
146
+ let processedText = text
147
+ . replace ( / \\ n / g, '\n' )
148
+ . replace ( / \\ r / g, '\r' ) ;
149
+
150
+ // Process hex escape sequences (\xNN)
151
+ while ( true ) {
152
+ const match = processedText . match ( / \\ x ( [ 0 - 9 a - f A - F ] { 2 } ) / ) ;
153
+ if ( match === null || match . index === undefined || match . length < 2 ) {
154
+ break ;
155
+ }
156
+ processedText = processedText . slice ( 0 , match . index ) + String . fromCharCode ( parseInt ( match [ 1 ] , 16 ) ) + processedText . slice ( match . index + 4 ) ;
157
+ }
158
+
159
+ const configurationResolverService = accessor . get ( IConfigurationResolverService ) ;
160
+ const workspaceContextService = accessor . get ( IWorkspaceContextService ) ;
161
+ const historyService = accessor . get ( IHistoryService ) ;
162
+ const activeWorkspaceRootUri = historyService . getLastActiveWorkspaceRoot ( instance . isRemote ? Schemas . vscodeRemote : Schemas . file ) ;
163
+ const lastActiveWorkspaceRoot = activeWorkspaceRootUri ? workspaceContextService . getWorkspaceFolder ( activeWorkspaceRootUri ) ?? undefined : undefined ;
164
+ const resolvedText = await configurationResolverService . resolveAsync ( lastActiveWorkspaceRoot , processedText ) ;
165
+ instance . sendText ( resolvedText , false ) ;
138
166
} ;
139
167
140
168
export class TerminalLaunchHelpAction extends Action {
@@ -957,14 +985,13 @@ export function registerTerminalActions() {
957
985
registerTerminalAction ( {
958
986
id : TerminalCommandId . SendSequence ,
959
987
title : terminalStrings . sendSequence ,
960
- f1 : false ,
988
+ f1 : true ,
961
989
metadata : {
962
990
description : terminalStrings . sendSequence . value ,
963
991
args : [ {
964
992
name : 'args' ,
965
993
schema : {
966
994
type : 'object' ,
967
- required : [ 'text' ] ,
968
995
properties : {
969
996
text : {
970
997
description : localize ( 'sendSequence' , "The sequence of text to send to the terminal" ) ,
0 commit comments