Skip to content

Commit f5ad8cd

Browse files
committed
Inline implementations
1 parent 08cf925 commit f5ad8cd

File tree

1 file changed

+92
-99
lines changed

1 file changed

+92
-99
lines changed

src/vs/workbench/contrib/terminalContrib/sendCommands/browser/terminal.sendCommands.contribution.ts

Lines changed: 92 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -7,114 +7,17 @@ import { Schemas } from '../../../../../base/common/network.js';
77
import { isWindows } from '../../../../../base/common/platform.js';
88
import { isObject, isString } from '../../../../../base/common/types.js';
99
import { localize, localize2 } from '../../../../../nls.js';
10-
import type { ServicesAccessor } from '../../../../../platform/instantiation/common/instantiation.js';
1110
import { IQuickInputService, type QuickPickItem } from '../../../../../platform/quickinput/common/quickInput.js';
1211
import { IWorkspaceContextService } from '../../../../../platform/workspace/common/workspace.js';
1312
import { IConfigurationResolverService } from '../../../../services/configurationResolver/common/configurationResolver.js';
1413
import { IHistoryService } from '../../../../services/history/common/history.js';
15-
import { ITerminalService } from '../../../terminal/browser/terminal.js';
1614
import { registerTerminalAction } from '../../../terminal/browser/terminalActions.js';
1715
import { TerminalSendCommandsCommandId } from '../common/terminal.sendCommands.js';
1816

1917
function toOptionalString(obj: unknown): string | undefined {
2018
return isString(obj) ? obj : undefined;
2119
}
2220

23-
export const terminalSendSequenceCommand = async (accessor: ServicesAccessor, args: unknown) => {
24-
const quickInputService = accessor.get(IQuickInputService);
25-
const configurationResolverService = accessor.get(IConfigurationResolverService);
26-
const workspaceContextService = accessor.get(IWorkspaceContextService);
27-
const historyService = accessor.get(IHistoryService);
28-
const terminalService = accessor.get(ITerminalService);
29-
30-
const instance = terminalService.activeInstance;
31-
if (instance) {
32-
let text = isObject(args) && 'text' in args ? toOptionalString(args.text) : undefined;
33-
34-
// If no text provided, prompt user for input and process special characters
35-
if (!text) {
36-
text = await quickInputService.input({
37-
value: '',
38-
placeHolder: 'Enter sequence to send (supports \\n, \\r, \\xAB)',
39-
prompt: localize('workbench.action.terminal.sendSequence.prompt', "Enter sequence to send to the terminal"),
40-
});
41-
if (!text) {
42-
return;
43-
}
44-
// Process escape sequences
45-
let processedText = text
46-
.replace(/\\n/g, '\n')
47-
.replace(/\\r/g, '\r');
48-
49-
// Process hex escape sequences (\xNN)
50-
while (true) {
51-
const match = processedText.match(/\\x([0-9a-fA-F]{2})/);
52-
if (match === null || match.index === undefined || match.length < 2) {
53-
break;
54-
}
55-
processedText = processedText.slice(0, match.index) + String.fromCharCode(parseInt(match[1], 16)) + processedText.slice(match.index + 4);
56-
}
57-
58-
text = processedText;
59-
}
60-
61-
const activeWorkspaceRootUri = historyService.getLastActiveWorkspaceRoot(instance.isRemote ? Schemas.vscodeRemote : Schemas.file);
62-
const lastActiveWorkspaceRoot = activeWorkspaceRootUri ? workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri) ?? undefined : undefined;
63-
const resolvedText = await configurationResolverService.resolveAsync(lastActiveWorkspaceRoot, text);
64-
instance.sendText(resolvedText, false);
65-
}
66-
};
67-
68-
export const terminalSendSignalCommand = async (accessor: ServicesAccessor, args: unknown) => {
69-
const quickInputService = accessor.get(IQuickInputService);
70-
const instance = accessor.get(ITerminalService).activeInstance;
71-
if (!instance) {
72-
return;
73-
}
74-
75-
let signal = isObject(args) && 'signal' in args ? toOptionalString(args.signal) : undefined;
76-
77-
if (!signal) {
78-
const signalOptions: QuickPickItem[] = [
79-
{ label: 'SIGINT', description: localize('SIGINT', 'Interrupt process (Ctrl+C)') },
80-
{ label: 'SIGTERM', description: localize('SIGTERM', 'Terminate process gracefully') },
81-
{ label: 'SIGKILL', description: localize('SIGKILL', 'Force kill process') },
82-
{ label: 'SIGSTOP', description: localize('SIGSTOP', 'Stop process') },
83-
{ label: 'SIGCONT', description: localize('SIGCONT', 'Continue process') },
84-
{ label: 'SIGHUP', description: localize('SIGHUP', 'Hangup') },
85-
{ label: 'SIGQUIT', description: localize('SIGQUIT', 'Quit process') },
86-
{ label: 'SIGUSR1', description: localize('SIGUSR1', 'User-defined signal 1') },
87-
{ label: 'SIGUSR2', description: localize('SIGUSR2', 'User-defined signal 2') },
88-
{ type: 'separator' },
89-
{ label: localize('manualSignal', 'Manually enter signal') }
90-
];
91-
92-
const selected = await quickInputService.pick(signalOptions, {
93-
placeHolder: localize('selectSignal', 'Select signal to send to terminal process')
94-
});
95-
96-
if (!selected) {
97-
return;
98-
}
99-
100-
if (selected.label === localize('manualSignal', 'Manually enter signal')) {
101-
const inputSignal = await quickInputService.input({
102-
prompt: localize('enterSignal', 'Enter signal name (e.g., SIGTERM, SIGKILL)'),
103-
});
104-
105-
if (!inputSignal) {
106-
return;
107-
}
108-
109-
signal = inputSignal;
110-
} else {
111-
signal = selected.label;
112-
}
113-
}
114-
115-
await instance.sendSignal(signal);
116-
};
117-
11821
const sendSequenceString = localize2('sendSequence', "Send Sequence");
11922
registerTerminalAction({
12023
id: TerminalSendCommandsCommandId.SendSequence,
@@ -136,7 +39,49 @@ registerTerminalAction({
13639
}
13740
}]
13841
},
139-
run: (c, accessor, args) => terminalSendSequenceCommand(accessor, args)
42+
run: async (c, accessor, args) => {
43+
const quickInputService = accessor.get(IQuickInputService);
44+
const configurationResolverService = accessor.get(IConfigurationResolverService);
45+
const workspaceContextService = accessor.get(IWorkspaceContextService);
46+
const historyService = accessor.get(IHistoryService);
47+
48+
const instance = c.service.activeInstance;
49+
if (instance) {
50+
let text = isObject(args) && 'text' in args ? toOptionalString(args.text) : undefined;
51+
52+
// If no text provided, prompt user for input and process special characters
53+
if (!text) {
54+
text = await quickInputService.input({
55+
value: '',
56+
placeHolder: 'Enter sequence to send (supports \\n, \\r, \\xAB)',
57+
prompt: localize('workbench.action.terminal.sendSequence.prompt', "Enter sequence to send to the terminal"),
58+
});
59+
if (!text) {
60+
return;
61+
}
62+
// Process escape sequences
63+
let processedText = text
64+
.replace(/\\n/g, '\n')
65+
.replace(/\\r/g, '\r');
66+
67+
// Process hex escape sequences (\xNN)
68+
while (true) {
69+
const match = processedText.match(/\\x([0-9a-fA-F]{2})/);
70+
if (match === null || match.index === undefined || match.length < 2) {
71+
break;
72+
}
73+
processedText = processedText.slice(0, match.index) + String.fromCharCode(parseInt(match[1], 16)) + processedText.slice(match.index + 4);
74+
}
75+
76+
text = processedText;
77+
}
78+
79+
const activeWorkspaceRootUri = historyService.getLastActiveWorkspaceRoot(instance.isRemote ? Schemas.vscodeRemote : Schemas.file);
80+
const lastActiveWorkspaceRoot = activeWorkspaceRootUri ? workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri) ?? undefined : undefined;
81+
const resolvedText = await configurationResolverService.resolveAsync(lastActiveWorkspaceRoot, text);
82+
instance.sendText(resolvedText, false);
83+
}
84+
}
14085
});
14186

14287
const sendSignalString = localize2('sendSignal', "Send Signal");
@@ -160,5 +105,53 @@ registerTerminalAction({
160105
}
161106
}]
162107
},
163-
run: (c, accessor, args) => terminalSendSignalCommand(accessor, args)
108+
run: async (c, accessor, args) => {
109+
const quickInputService = accessor.get(IQuickInputService);
110+
const instance = c.service.activeInstance;
111+
if (!instance) {
112+
return;
113+
}
114+
115+
let signal = isObject(args) && 'signal' in args ? toOptionalString(args.signal) : undefined;
116+
117+
if (!signal) {
118+
const signalOptions: QuickPickItem[] = [
119+
{ label: 'SIGINT', description: localize('SIGINT', 'Interrupt process (Ctrl+C)') },
120+
{ label: 'SIGTERM', description: localize('SIGTERM', 'Terminate process gracefully') },
121+
{ label: 'SIGKILL', description: localize('SIGKILL', 'Force kill process') },
122+
{ label: 'SIGSTOP', description: localize('SIGSTOP', 'Stop process') },
123+
{ label: 'SIGCONT', description: localize('SIGCONT', 'Continue process') },
124+
{ label: 'SIGHUP', description: localize('SIGHUP', 'Hangup') },
125+
{ label: 'SIGQUIT', description: localize('SIGQUIT', 'Quit process') },
126+
{ label: 'SIGUSR1', description: localize('SIGUSR1', 'User-defined signal 1') },
127+
{ label: 'SIGUSR2', description: localize('SIGUSR2', 'User-defined signal 2') },
128+
{ type: 'separator' },
129+
{ label: localize('manualSignal', 'Manually enter signal') }
130+
];
131+
132+
const selected = await quickInputService.pick(signalOptions, {
133+
placeHolder: localize('selectSignal', 'Select signal to send to terminal process')
134+
});
135+
136+
if (!selected) {
137+
return;
138+
}
139+
140+
if (selected.label === localize('manualSignal', 'Manually enter signal')) {
141+
const inputSignal = await quickInputService.input({
142+
prompt: localize('enterSignal', 'Enter signal name (e.g., SIGTERM, SIGKILL)'),
143+
});
144+
145+
if (!inputSignal) {
146+
return;
147+
}
148+
149+
signal = inputSignal;
150+
} else {
151+
signal = selected.label;
152+
}
153+
}
154+
155+
await instance.sendSignal(signal);
156+
}
164157
});

0 commit comments

Comments
 (0)