Skip to content

Commit a07177e

Browse files
committed
Add ev3devBrowser.interactiveTerminal.env setting
This adds a new setting for passing additional environment variables to programs run using the debugger's interactiveTerminal option. This is useful for things like PYTHONINSPECT where it only makes sense to set it when there is a terminal.
1 parent a6d1ef1 commit a07177e

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ This extension contributes the following settings:
9090
* `ev3devBrowser.env`: If you need to set environment variables for running
9191
remote programs, you can set them here. Each variable is defined as a
9292
key/value pair.
93+
* `ev3devBrowser.interactiveTerminal.env`: This is similar to `ev3devBrowser.env`
94+
but the environment variables are only applied when running a program in
95+
the interactive terminal.
9396
* `ev3devBrowser.download.include`: Use this to specify which files to
9497
included when downloading files to the remote device. Can use glob patterns.
9598
* `ev3devBrowser.download.exclude`: Use this to specify which files to

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@
5252
"description": "Addition environment variables to use on remote devices.",
5353
"uniqueItems": true
5454
},
55+
"ev3devBrowser.interactiveTerminal.env": {
56+
"scope": "window",
57+
"type": "object",
58+
"patternProperties": {
59+
"[A-Za-z0-9_]{1,}": {
60+
"type": "string"
61+
}
62+
},
63+
"additionalProperties": false,
64+
"default": {
65+
"PYTHONINSPECT": "TRUE",
66+
"MICROPYINSPECT": "TRUE"
67+
},
68+
"description": "Addition environment variables to use on remote devices only when using the interactive terminal that is started by the debugger.",
69+
"uniqueItems": true
70+
},
5571
"ev3devBrowser.download.include": {
5672
"scope": "resource",
5773
"type": "string",

src/device.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,10 @@ export class Device extends vscode.Disposable {
223223
* Executes a command on the remote device.
224224
* @param command The absolute path of the command.
225225
*/
226-
public exec(command: string, pty?: ssh2.PseudoTtyOptions): Promise<ssh2.ClientChannel> {
226+
public exec(command: string, env?: any, pty?: ssh2.PseudoTtyOptions): Promise<ssh2.ClientChannel> {
227227
return new Promise((resolve, reject) => {
228228
const options = {
229-
env: vscode.workspace.getConfiguration('ev3devBrowser').get('env'),
229+
env: env,
230230
pty: pty,
231231
};
232232
this.client.exec(command, options, (err, channel) => {

src/extension.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ async function handleCustomDebugEvent(event: vscode.DebugSessionCustomEvent): Pr
148148
if (args.interactiveTerminal) {
149149
const config = vscode.workspace.getConfiguration(`terminal.integrated.env.${getPlatform()}`);
150150
const termEnv = config.get<string>('TERM');
151-
const ch = await device.exec(command, { term: termEnv || process.env['TERM'] || 'xterm-256color' });
151+
const env = {
152+
...vscode.workspace.getConfiguration('ev3devBrowser').get<object>('env'),
153+
...vscode.workspace.getConfiguration('ev3devBrowser').get<object>('interactiveTerminal.env'),
154+
};
155+
const ch = await device.exec(command, env, { term: termEnv || process.env['TERM'] || 'xterm-256color' });
152156
const writeEmitter = new vscode.EventEmitter<string>();
153157
ch.stdout.on('data', (data: string | Buffer) => writeEmitter.fire(String(data)));
154158
ch.stderr.on('data', (data: string | Buffer) => writeEmitter.fire(String(data)));
@@ -212,7 +216,8 @@ async function handleCustomDebugEvent(event: vscode.DebugSessionCustomEvent): Pr
212216
output.show(true);
213217
output.clear();
214218
output.appendLine(`Starting: ${command}`);
215-
const channel = await device.exec(command);
219+
const env = vscode.workspace.getConfiguration('ev3devBrowser').get('env');
220+
const channel = await device.exec(command, env);
216221
channel.on('close', () => {
217222
if (debugRestarting) {
218223
activeDebugSessions.add(event.session.id);

0 commit comments

Comments
 (0)