Skip to content

Commit 7546740

Browse files
committed
Add picker to sendSequence command
Fixes microsoft#250669
1 parent 95c9166 commit 7546740

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

src/vs/workbench/contrib/terminal/browser/terminalActions.ts

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,43 @@ export async function getCwdForSplit(
121121
}
122122

123123
export const terminalSendSequenceCommand = async (accessor: ServicesAccessor, args: unknown) => {
124-
const instance = accessor.get(ITerminalService).activeInstance;
124+
const quickInputService = accessor.get(IQuickInputService);
125+
const configurationResolverService = accessor.get(IConfigurationResolverService);
126+
const workspaceContextService = accessor.get(IWorkspaceContextService);
127+
const historyService = accessor.get(IHistoryService);
128+
const terminalService = accessor.get(ITerminalService);
129+
130+
const instance = terminalService.activeInstance;
125131
if (instance) {
126-
const text = isObject(args) && 'text' in args ? toOptionalString(args.text) : undefined;
132+
let text = isObject(args) && 'text' in args ? toOptionalString(args.text) : undefined;
133+
134+
// If no text provided, prompt user for input and process special characters
127135
if (!text) {
128-
return;
136+
text = await quickInputService.input({
137+
value: '',
138+
placeHolder: 'Enter sequence to send (supports \\n, \\r, \\x{AB})',
139+
prompt: localize('workbench.action.terminal.sendSequence.prompt', "Enter sequence to send to the terminal"),
140+
});
141+
if (!text) {
142+
return;
143+
}
144+
// Process escape sequences
145+
let processedText = text
146+
.replace(/\\n/g, '\n')
147+
.replace(/\\r/g, '\r');
148+
149+
// Process hex escape sequences (\xNN)
150+
while (true) {
151+
const match = processedText.match(/\\x([0-9a-fA-F]{2})/);
152+
if (match === null || match.index === undefined || match.length < 2) {
153+
break;
154+
}
155+
processedText = processedText.slice(0, match.index) + String.fromCharCode(parseInt(match[1], 16)) + processedText.slice(match.index + 4);
156+
}
157+
158+
text = processedText;
129159
}
130-
const configurationResolverService = accessor.get(IConfigurationResolverService);
131-
const workspaceContextService = accessor.get(IWorkspaceContextService);
132-
const historyService = accessor.get(IHistoryService);
160+
133161
const activeWorkspaceRootUri = historyService.getLastActiveWorkspaceRoot(instance.isRemote ? Schemas.vscodeRemote : Schemas.file);
134162
const lastActiveWorkspaceRoot = activeWorkspaceRootUri ? workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri) ?? undefined : undefined;
135163
const resolvedText = await configurationResolverService.resolveAsync(lastActiveWorkspaceRoot, text);
@@ -1007,7 +1035,7 @@ export function registerTerminalActions() {
10071035
registerTerminalAction({
10081036
id: TerminalCommandId.SendSequence,
10091037
title: terminalStrings.sendSequence,
1010-
f1: false,
1038+
f1: true,
10111039
metadata: {
10121040
description: terminalStrings.sendSequence.value,
10131041
args: [{

src/vs/workbench/contrib/terminal/common/terminalStrings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const terminalStrings = {
3636
rename: localize2('workbench.action.terminal.rename', "Rename..."),
3737
toggleSizeToContentWidth: localize2('workbench.action.terminal.sizeToContentWidthInstance', "Toggle Size to Content Width"),
3838
focusHover: localize2('workbench.action.terminal.focusHover', "Focus Hover"),
39-
sendSequence: localize2('workbench.action.terminal.sendSequence', "Send Custom Sequence to Terminal"),
39+
sendSequence: localize2('workbench.action.terminal.sendSequence', "Send Sequence"),
4040
sendSignal: localize2('workbench.action.terminal.sendSignal', "Send Signal"),
4141
newWithCwd: localize2('workbench.action.terminal.newWithCwd', "Create New Terminal Starting in a Custom Working Directory"),
4242
renameWithArgs: localize2('workbench.action.terminal.renameWithArg', "Rename the Currently Active Terminal"),

0 commit comments

Comments
 (0)