Skip to content

Commit

Permalink
Attach shell should take focus (microsoft#2421)
Browse files Browse the repository at this point in the history
  • Loading branch information
bwateratmsft authored and Dmarch28 committed Mar 4, 2021
1 parent eb8b3f6 commit 428e348
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/commands/containers/attachShellContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ export async function attachShellContainer(context: IActionContext, node?: Conta
shellCommand
);

await executeAsTask(context, terminalCommand, `Shell: ${node.containerName}`, { addDockerEnv: true, alwaysRunNew: true });
await executeAsTask(context, terminalCommand, `Shell: ${node.containerName}`, { addDockerEnv: true, alwaysRunNew: true, focus: true });
}
2 changes: 1 addition & 1 deletion src/commands/images/runAzureCliImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ export async function runAzureCliImage(context: IActionContext): Promise<void> {
vol += ` -v ${workspaceFolder.uri.fsPath}:/workspace`;
}

await executeAsTask(context, `docker run ${option} ${vol.trim()} -it --rm mcr.microsoft.com/azure-cli:latest`, 'Azure CLI', { addDockerEnv: true });
await executeAsTask(context, `docker run ${option} ${vol.trim()} -it --rm mcr.microsoft.com/azure-cli:latest`, 'Azure CLI', { addDockerEnv: true, focus: true });
}
}
17 changes: 16 additions & 1 deletion src/utils/executeAsTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ import * as vscode from 'vscode';
import { IActionContext } from 'vscode-azureextensionui';
import { addDockerSettingsToEnv } from './addDockerSettingsToEnv';

export async function executeAsTask(context: IActionContext, command: string, name: string, options: { addDockerEnv?: boolean, workspaceFolder?: vscode.WorkspaceFolder, cwd?: string, alwaysRunNew?: boolean, rejectOnError?: boolean }): Promise<void> {
interface ExecuteAsTaskOptions {
addDockerEnv?: boolean;
workspaceFolder?: vscode.WorkspaceFolder;
cwd?: string;
alwaysRunNew?: boolean;
rejectOnError?: boolean;
focus?: boolean;
}

export async function executeAsTask(context: IActionContext, command: string, name: string, options: ExecuteAsTaskOptions): Promise<void> {
let newEnv: NodeJS.ProcessEnv | undefined;
options = options ?? {};

Expand All @@ -34,6 +43,12 @@ export async function executeAsTask(context: IActionContext, command: string, na
task.definition.idRandomizer = Math.random();
}

if (options.focus) {
task.presentationOptions = {
focus: true,
};
}

const taskExecution = await vscode.tasks.executeTask(task);

const taskEndPromise = new Promise<void>((resolve, reject) => {
Expand Down

0 comments on commit 428e348

Please sign in to comment.