-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathrunInTerminal.ts
More file actions
38 lines (35 loc) · 1.62 KB
/
runInTerminal.ts
File metadata and controls
38 lines (35 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { Terminal, TerminalShellExecution } from 'vscode';
import { PythonEnvironment, PythonTerminalExecutionOptions } from '../../api';
import { createDeferred } from '../../common/utils/deferred';
import { onDidEndTerminalShellExecution } from '../../common/window.apis';
import { identifyTerminalShell } from '../common/shellDetector';
import { getShellCommandAsString } from './shells/common/shellUtils';
export async function runInTerminal(
environment: PythonEnvironment,
terminal: Terminal,
options: PythonTerminalExecutionOptions,
): Promise<void> {
if (options.show) {
terminal.show();
}
let executable = environment.execInfo?.activatedRun?.executable ?? environment.execInfo?.run.executable ?? 'python';
const args = environment.execInfo?.activatedRun?.args ?? environment.execInfo?.run.args ?? [];
const allArgs = [...args, ...(options.args ?? [])];
const shellType = identifyTerminalShell(terminal);
if (terminal.shellIntegration) {
let execution: TerminalShellExecution | undefined;
const deferred = createDeferred<void>();
const disposable = onDidEndTerminalShellExecution((e) => {
if (e.execution === execution) {
disposable.dispose();
deferred.resolve();
}
});
executable = getShellCommandAsString(shellType, [{ executable }]);
execution = terminal.shellIntegration.executeCommand(executable, allArgs);
await deferred.promise;
} else {
const text = getShellCommandAsString(shellType, [{ executable, args: allArgs }]);
terminal.sendText(`${text}\n`);
}
}