Skip to content

Commit 2853f77

Browse files
committed
Added setting for terminal launch arguments, show and focus terminal when running
1 parent c000a91 commit 2853f77

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,11 @@
681681
"type": "boolean",
682682
"default": false,
683683
"description": "When executing a file in the terminal, whether to use execute in the file's directory, instead of the current open folder."
684+
},
685+
"python.terminal.launchArgs": {
686+
"type": "array",
687+
"default": [],
688+
"description": "Python launch arguments to use when executing a file in the terminal."
684689
}
685690
}
686691
}

src/client/common/configSettings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export interface IAutoCompeteSettings {
6969
}
7070
export interface ITerminalSettings {
7171
executeInFileDir: boolean;
72+
launchArgs: string[];
7273
}
7374

7475
const systemVariables: SystemVariables = new SystemVariables();

src/client/providers/execInTerminalProvider.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@ function execInTerminal(fileUri?: vscode.Uri) {
4040
filePath = `"${filePath}"`;
4141
}
4242
const terminal = vscode.window.createTerminal(`Python`);
43-
if (pythonSettings.terminal.executeInFileDir) {
44-
let fileDirPath = path.dirname(filePath).substring(1);
43+
if (pythonSettings.terminal && pythonSettings.terminal.executeInFileDir) {
44+
const fileDirPath = path.dirname(filePath).substring(1);
4545
if (fileDirPath != vscode.workspace.rootPath) {
4646
terminal.sendText(`cd "${fileDirPath}"`);
4747
}
4848
}
49-
terminal.sendText(`${currentPythonPath} ${filePath}`);
49+
const launchArgs = settings.PythonSettings.getInstance().terminal.launchArgs;
50+
const launchArgsString = launchArgs.length > 0 ? " ".concat(launchArgs.join(" ")) : "";
51+
terminal.sendText(`${currentPythonPath} ${filePath}${launchArgsString}`);
52+
terminal.show();
5053
}
5154

5255
function execSelectionInTerminal() {
@@ -62,5 +65,8 @@ function execSelectionInTerminal() {
6265
}
6366
const code = vscode.window.activeTextEditor.document.getText(new vscode.Range(selection.start, selection.end));
6467
const terminal = vscode.window.createTerminal(`Python`);
65-
terminal.sendText(`${currentPythonPath} -c "${code}"`);
66-
}
68+
const launchArgs = settings.PythonSettings.getInstance().terminal.launchArgs;
69+
const launchArgsString = launchArgs.length > 0 ? " ".concat(launchArgs.join(" ")) : "";
70+
terminal.sendText(`${currentPythonPath} -c "${code}"${launchArgsString}`);
71+
terminal.show();
72+
}

0 commit comments

Comments
 (0)