提交 331da82a 编写于 作者: D Daniel Imms

Enable shell selector outside Windows

Fixes #75718
上级 b3bba0c9
...@@ -42,7 +42,7 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape ...@@ -42,7 +42,7 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
this._toDispose.push(_terminalService.onActiveInstanceChanged(instance => this._onActiveTerminalChanged(instance ? instance.id : null))); this._toDispose.push(_terminalService.onActiveInstanceChanged(instance => this._onActiveTerminalChanged(instance ? instance.id : null)));
this._toDispose.push(_terminalService.onInstanceTitleChanged(instance => this._onTitleChanged(instance.id, instance.title))); this._toDispose.push(_terminalService.onInstanceTitleChanged(instance => this._onTitleChanged(instance.id, instance.title)));
this._toDispose.push(_terminalService.configHelper.onWorkspacePermissionsChanged(isAllowed => this._onWorkspacePermissionsChanged(isAllowed))); this._toDispose.push(_terminalService.configHelper.onWorkspacePermissionsChanged(isAllowed => this._onWorkspacePermissionsChanged(isAllowed)));
this._toDispose.push(_terminalService.onRequestWindowsShells(r => this._onRequestDetectWindowsShell(r))); this._toDispose.push(_terminalService.onRequestAvailableShells(r => this._onRequestAvailableShells(r)));
// Set initial ext host state // Set initial ext host state
this._terminalService.terminalInstances.forEach(t => { this._terminalService.terminalInstances.forEach(t => {
...@@ -277,7 +277,7 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape ...@@ -277,7 +277,7 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
this._terminalProcesses[terminalId].emitLatency(sum / COUNT); this._terminalProcesses[terminalId].emitLatency(sum / COUNT);
} }
private _onRequestDetectWindowsShell(resolve: (shells: IShellDefinition[]) => void): void { private _onRequestAvailableShells(resolve: (shells: IShellDefinition[]) => void): void {
this._proxy.$requestWindowsShells().then(shells => resolve(shells)); this._proxy.$requestAvailableShells().then(shells => resolve(shells));
} }
} }
...@@ -1128,7 +1128,7 @@ export interface ExtHostTerminalServiceShape { ...@@ -1128,7 +1128,7 @@ export interface ExtHostTerminalServiceShape {
$acceptProcessRequestCwd(id: number): void; $acceptProcessRequestCwd(id: number): void;
$acceptProcessRequestLatency(id: number): number; $acceptProcessRequestLatency(id: number): number;
$acceptWorkspacePermissionsChanged(isAllowed: boolean): void; $acceptWorkspacePermissionsChanged(isAllowed: boolean): void;
$requestWindowsShells(): Promise<IShellDefinitionDto[]>; $requestAvailableShells(): Promise<IShellDefinitionDto[]>;
} }
export interface ExtHostSCMShape { export interface ExtHostSCMShape {
......
...@@ -20,7 +20,7 @@ import { ExtHostWorkspace } from 'vs/workbench/api/common/extHostWorkspace'; ...@@ -20,7 +20,7 @@ import { ExtHostWorkspace } from 'vs/workbench/api/common/extHostWorkspace';
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { ExtHostVariableResolverService } from 'vs/workbench/api/node/extHostDebugService'; import { ExtHostVariableResolverService } from 'vs/workbench/api/node/extHostDebugService';
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors'; import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
import { getDefaultShell, detectWindowsShells } from 'vs/workbench/contrib/terminal/node/terminal'; import { getDefaultShell, detectAvailableShells } from 'vs/workbench/contrib/terminal/node/terminal';
const RENDERER_NO_PROCESS_ID = -1; const RENDERER_NO_PROCESS_ID = -1;
...@@ -575,11 +575,8 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape { ...@@ -575,11 +575,8 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape {
return id; return id;
} }
public $requestWindowsShells(): Promise<IShellDefinitionDto[]> { public $requestAvailableShells(): Promise<IShellDefinitionDto[]> {
if (!platform.isWindows) { return detectAvailableShells();
throw new Error('Can only detect Windows shells on Windows');
}
return detectWindowsShells();
} }
private _onProcessExit(id: number, exitCode: number): void { private _onProcessExit(id: number, exitCode: number): void {
......
...@@ -370,10 +370,7 @@ actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ClearTerminalAct ...@@ -370,10 +370,7 @@ actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ClearTerminalAct
primary: 0, primary: 0,
mac: { primary: KeyMod.CtrlCmd | KeyCode.KEY_K } mac: { primary: KeyMod.CtrlCmd | KeyCode.KEY_K }
}, KEYBINDING_CONTEXT_TERMINAL_FOCUS, KeybindingWeight.WorkbenchContrib + 1), 'Terminal: Clear', category); }, KEYBINDING_CONTEXT_TERMINAL_FOCUS, KeybindingWeight.WorkbenchContrib + 1), 'Terminal: Clear', category);
// TODO: This should be the remote OS
// if (platform.isWindows) {
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(SelectDefaultShellWindowsTerminalAction, SelectDefaultShellWindowsTerminalAction.ID, SelectDefaultShellWindowsTerminalAction.LABEL), 'Terminal: Select Default Shell', category); actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(SelectDefaultShellWindowsTerminalAction, SelectDefaultShellWindowsTerminalAction.ID, SelectDefaultShellWindowsTerminalAction.LABEL), 'Terminal: Select Default Shell', category);
// }
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(AllowWorkspaceShellTerminalCommand, AllowWorkspaceShellTerminalCommand.ID, AllowWorkspaceShellTerminalCommand.LABEL), 'Terminal: Allow Workspace Shell Configuration', category); actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(AllowWorkspaceShellTerminalCommand, AllowWorkspaceShellTerminalCommand.ID, AllowWorkspaceShellTerminalCommand.LABEL), 'Terminal: Allow Workspace Shell Configuration', category);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(DisallowWorkspaceShellTerminalCommand, DisallowWorkspaceShellTerminalCommand.ID, DisallowWorkspaceShellTerminalCommand.LABEL), 'Terminal: Disallow Workspace Shell Configuration', category); actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(DisallowWorkspaceShellTerminalCommand, DisallowWorkspaceShellTerminalCommand.ID, DisallowWorkspaceShellTerminalCommand.LABEL), 'Terminal: Disallow Workspace Shell Configuration', category);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(RenameTerminalAction, RenameTerminalAction.ID, RenameTerminalAction.LABEL), 'Terminal: Rename', category); actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(RenameTerminalAction, RenameTerminalAction.ID, RenameTerminalAction.LABEL), 'Terminal: Rename', category);
......
...@@ -35,7 +35,6 @@ import { Schemas } from 'vs/base/common/network'; ...@@ -35,7 +35,6 @@ import { Schemas } from 'vs/base/common/network';
import { URI } from 'vs/base/common/uri'; import { URI } from 'vs/base/common/uri';
import { isWindows } from 'vs/base/common/platform'; import { isWindows } from 'vs/base/common/platform';
import { withNullAsUndefined } from 'vs/base/common/types'; import { withNullAsUndefined } from 'vs/base/common/types';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
export const TERMINAL_PICKER_PREFIX = 'term '; export const TERMINAL_PICKER_PREFIX = 'term ';
...@@ -743,8 +742,7 @@ export class SwitchTerminalActionViewItem extends SelectActionViewItem { ...@@ -743,8 +742,7 @@ export class SwitchTerminalActionViewItem extends SelectActionViewItem {
action: IAction, action: IAction,
@ITerminalService private readonly terminalService: ITerminalService, @ITerminalService private readonly terminalService: ITerminalService,
@IThemeService themeService: IThemeService, @IThemeService themeService: IThemeService,
@IContextViewService contextViewService: IContextViewService, @IContextViewService contextViewService: IContextViewService
@IWorkbenchEnvironmentService private workbenchEnvironmentService: IWorkbenchEnvironmentService
) { ) {
super(null, action, terminalService.getTabLabels().map(label => <ISelectOptionItem>{ text: label }), terminalService.activeTabIndex, contextViewService, { ariaLabel: nls.localize('terminals', 'Open Terminals.') }); super(null, action, terminalService.getTabLabels().map(label => <ISelectOptionItem>{ text: label }), terminalService.activeTabIndex, contextViewService, { ariaLabel: nls.localize('terminals', 'Open Terminals.') });
...@@ -756,11 +754,8 @@ export class SwitchTerminalActionViewItem extends SelectActionViewItem { ...@@ -756,11 +754,8 @@ export class SwitchTerminalActionViewItem extends SelectActionViewItem {
private _updateItems(): void { private _updateItems(): void {
const items = this.terminalService.getTabLabels().map(label => <ISelectOptionItem>{ text: label }); const items = this.terminalService.getTabLabels().map(label => <ISelectOptionItem>{ text: label });
let enableSelectDefaultShell = this.workbenchEnvironmentService.configuration.remoteAuthority ? false : isWindows; items.push({ text: SwitchTerminalActionViewItem.SEPARATOR });
if (enableSelectDefaultShell) { items.push({ text: SelectDefaultShellWindowsTerminalAction.LABEL });
items.push({ text: SwitchTerminalActionViewItem.SEPARATOR });
items.push({ text: SelectDefaultShellWindowsTerminalAction.LABEL });
}
this.setOptions(items, this.terminalService.activeTabIndex); this.setOptions(items, this.terminalService.activeTabIndex);
} }
} }
......
...@@ -222,7 +222,7 @@ export interface ITerminalService { ...@@ -222,7 +222,7 @@ export interface ITerminalService {
onInstancesChanged: Event<void>; onInstancesChanged: Event<void>;
onInstanceTitleChanged: Event<ITerminalInstance>; onInstanceTitleChanged: Event<ITerminalInstance>;
onActiveInstanceChanged: Event<ITerminalInstance | undefined>; onActiveInstanceChanged: Event<ITerminalInstance | undefined>;
onRequestWindowsShells: Event<(shells: IShellDefinition[]) => void>; onRequestAvailableShells: Event<(shells: IShellDefinition[]) => void>;
/** /**
* Creates a terminal. * Creates a terminal.
......
...@@ -65,8 +65,8 @@ export abstract class TerminalService implements ITerminalService { ...@@ -65,8 +65,8 @@ export abstract class TerminalService implements ITerminalService {
public get onActiveInstanceChanged(): Event<ITerminalInstance | undefined> { return this._onActiveInstanceChanged.event; } public get onActiveInstanceChanged(): Event<ITerminalInstance | undefined> { return this._onActiveInstanceChanged.event; }
protected readonly _onTabDisposed = new Emitter<ITerminalTab>(); protected readonly _onTabDisposed = new Emitter<ITerminalTab>();
public get onTabDisposed(): Event<ITerminalTab> { return this._onTabDisposed.event; } public get onTabDisposed(): Event<ITerminalTab> { return this._onTabDisposed.event; }
protected readonly _onRequestWindowsShells = new Emitter<(shells: IShellDefinition[]) => void>(); protected readonly _onRequestAvailableShells = new Emitter<(shells: IShellDefinition[]) => void>();
public get onRequestWindowsShells(): Event<(shells: IShellDefinition[]) => void> { return this._onRequestWindowsShells.event; } public get onRequestAvailableShells(): Event<(shells: IShellDefinition[]) => void> { return this._onRequestAvailableShells.event; }
public abstract get configHelper(): ITerminalConfigHelper; public abstract get configHelper(): ITerminalConfigHelper;
...@@ -553,6 +553,6 @@ export abstract class TerminalService implements ITerminalService { ...@@ -553,6 +553,6 @@ export abstract class TerminalService implements ITerminalService {
} }
private _detectWindowsShells(): Promise<IShellDefinition[]> { private _detectWindowsShells(): Promise<IShellDefinition[]> {
return new Promise(r => this._onRequestWindowsShells.fire(r)); return new Promise(r => this._onRequestAvailableShells.fire(r));
} }
} }
...@@ -9,7 +9,7 @@ import * as processes from 'vs/base/node/processes'; ...@@ -9,7 +9,7 @@ import * as processes from 'vs/base/node/processes';
import { readFile, fileExists, stat } from 'vs/base/node/pfs'; import { readFile, fileExists, stat } from 'vs/base/node/pfs';
import { LinuxDistro, IShellDefinition } from 'vs/workbench/contrib/terminal/common/terminal'; import { LinuxDistro, IShellDefinition } from 'vs/workbench/contrib/terminal/common/terminal';
import { coalesce } from 'vs/base/common/arrays'; import { coalesce } from 'vs/base/common/arrays';
import { normalize } from 'vs/base/common/path'; import { normalize, basename } from 'vs/base/common/path';
export function getDefaultShell(p: platform.Platform): string { export function getDefaultShell(p: platform.Platform): string {
if (p === platform.Platform.Windows) { if (p === platform.Platform.Windows) {
...@@ -85,7 +85,11 @@ export function getWindowsBuildNumber(): number { ...@@ -85,7 +85,11 @@ export function getWindowsBuildNumber(): number {
return buildNumber; return buildNumber;
} }
export async function detectWindowsShells(): Promise<IShellDefinition[]> { export function detectAvailableShells(): Promise<IShellDefinition[]> {
return platform.isWindows ? detectAvailableWindowsShells() : detectAvailableUnixShells();
}
async function detectAvailableWindowsShells(): Promise<IShellDefinition[]> {
// Determine the correct System32 path. We want to point to Sysnative // Determine the correct System32 path. We want to point to Sysnative
// when the 32-bit version of VS Code is running on a 64-bit machine. // when the 32-bit version of VS Code is running on a 64-bit machine.
// The reason for this is because PowerShell's important PSReadline // The reason for this is because PowerShell's important PSReadline
...@@ -118,6 +122,16 @@ export async function detectWindowsShells(): Promise<IShellDefinition[]> { ...@@ -118,6 +122,16 @@ export async function detectWindowsShells(): Promise<IShellDefinition[]> {
return Promise.all(promises).then(coalesce); return Promise.all(promises).then(coalesce);
} }
async function detectAvailableUnixShells(): Promise<IShellDefinition[]> {
const contents = await readFile('/etc/shells', 'utf8');
const shells = contents.split('\n').filter(e => e.trim().indexOf('#') !== 0 && e.trim().length > 0);
return shells.map(e => {
return {
label: basename(e),
path: e
};
});
}
function validateShellPaths(label: string, potentialPaths: string[]): Promise<IShellDefinition | undefined> { function validateShellPaths(label: string, potentialPaths: string[]): Promise<IShellDefinition | undefined> {
if (potentialPaths.length === 0) { if (potentialPaths.length === 0) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册