Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: external terminal not registering Ctrl+C with .NET Core #201020

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/vs/platform/externalTerminal/node/externalTerminalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import * as cp from 'child_process';
import { memoize } from 'vs/base/common/decorators';
import { FileAccess } from 'vs/base/common/network';
import * as path from 'vs/base/common/path';
import * as env from 'vs/base/common/platform';
Expand Down Expand Up @@ -66,14 +67,15 @@ export class WindowsExternalTerminalService extends ExternalTerminalService impl

return new Promise<void>((c, e) => {
const env = getSanitizedEnvironment(process);
const child = spawner.spawn(command, cmdArgs, { cwd, env });
const child = spawner.spawn(command, cmdArgs, { cwd, env, detached: true });
child.on('error', e);
child.on('exit', () => c());
});
}

public runInTerminal(title: string, dir: string, args: string[], envVars: ITerminalEnvironment, settings: IExternalTerminalSettings): Promise<number | undefined> {
public async runInTerminal(title: string, dir: string, args: string[], envVars: ITerminalEnvironment, settings: IExternalTerminalSettings): Promise<number | undefined> {
const exec = 'windowsExec' in settings && settings.windowsExec ? settings.windowsExec : WindowsExternalTerminalService.getDefaultTerminalWindows();
const wt = await WindowsExternalTerminalService.getWtExePath();

return new Promise<number | undefined>((resolve, reject) => {

Expand Down Expand Up @@ -101,6 +103,11 @@ export class WindowsExternalTerminalService extends ExternalTerminalService impl
// inside it
spawnExec = exec;
cmdArgs = ['-d', '.', WindowsExternalTerminalService.CMD, '/c', command];
} else if (wt) {
// prefer to use the window terminal to spawn if it's available instead
// of start, since that allows ctrl+c handling (#81322)
spawnExec = wt;
cmdArgs = ['-d', dir, exec, '/c', command];
} else {
spawnExec = WindowsExternalTerminalService.CMD;
cmdArgs = ['/c', 'start', title, '/wait', exec, '/c', command];
Expand All @@ -123,6 +130,16 @@ export class WindowsExternalTerminalService extends ExternalTerminalService impl
}
return WindowsExternalTerminalService._DEFAULT_TERMINAL_WINDOWS;
}

@memoize
private static async getWtExePath() {
try {
const wtPath = await processes.win32.findExecutable('wt');
return await pfs.Promises.exists(wtPath) ? wtPath : undefined;
} catch {
return undefined;
}
}
}

export class MacExternalTerminalService extends ExternalTerminalService implements IExternalTerminalService {
Expand Down