提交 ebed7e9c 编写于 作者: D Daniel Imms

Change setLocaleVariables to detectLocale

The setting is now an enum instead of boolean and defaults to auto
which should provide better detection and not set in cases where it
shouldn't.

Fixes #80072
上级 7694f65a
......@@ -182,7 +182,7 @@ export class ExtHostTerminalService extends BaseExtHostTerminalService {
this._variableResolver,
isWorkspaceShellAllowed,
pkg.version,
terminalConfig.get<boolean>('setLocaleVariables', false),
terminalConfig.get<string>('detectLocale', 'auto'),
baseEnv
);
......
......@@ -194,10 +194,16 @@ configurationRegistry.registerConfiguration({
type: 'number',
default: 1000
},
'terminal.integrated.setLocaleVariables': {
markdownDescription: nls.localize('terminal.integrated.setLocaleVariables', "Controls whether locale variables are set at startup of the terminal."),
type: 'boolean',
default: true
'terminal.integrated.detectLocale': {
markdownDescription: nls.localize('terminal.integrated.detectLocale', "Controls whether to detect and set the `$LANG` environment variable."),
type: 'string',
enum: ['auto', 'off', 'on'],
enumDescriptions: [
nls.localize('terminal.integrated.detectLocale.auto', "Set the `$LANG` environment variable if the existing variable does not exist or it does not end in `'.UTF-8'`."),
nls.localize('terminal.integrated.detectLocale.off', "Do not set the `$LANG` environment variable."),
nls.localize('terminal.integrated.detectLocale.on', "Always set the `$LANG` environment variable.")
],
default: 'auto'
},
'terminal.integrated.rendererType': {
type: 'string',
......
......@@ -100,7 +100,7 @@ export interface ITerminalConfiguration {
fontSize: number;
letterSpacing: number;
lineHeight: number;
setLocaleVariables: boolean;
detectLocale: 'auto' | 'off' | 'on';
scrollback: number;
commandsToSkipShell: string[];
cwd: string;
......
......@@ -51,12 +51,12 @@ function _mergeEnvironmentValue(env: ITerminalEnvironment, key: string, value: s
}
}
export function addTerminalEnvironmentKeys(env: platform.IProcessEnvironment, version: string | undefined, locale: string | undefined, setLocaleVariables: boolean): void {
export function addTerminalEnvironmentKeys(env: platform.IProcessEnvironment, version: string | undefined, locale: string | undefined, detectLocale: 'auto' | 'off' | 'on'): void {
env['TERM_PROGRAM'] = 'vscode';
if (version) {
env['TERM_PROGRAM_VERSION'] = version;
}
if (setLocaleVariables) {
if (_shouldSetLangEnvVariable(env, detectLocale)) {
env['LANG'] = _getLangEnvVariable(locale);
}
env['COLORTERM'] = 'truecolor';
......@@ -88,6 +88,16 @@ function resolveConfigurationVariables(configurationResolverService: IConfigurat
return env;
}
function _shouldSetLangEnvVariable(env: platform.IProcessEnvironment, detectLocale: 'auto' | 'off' | 'on'): boolean {
if (detectLocale === 'on') {
return true;
}
if (detectLocale === 'auto') {
return !env['LANG'] || env['LANG'].search(/\.UTF\-8$/) === -1;
}
return false; // 'off'
}
function _getLangEnvVariable(locale?: string): string {
const parts = locale ? locale.split('-') : [];
const n = parts.length;
......@@ -334,7 +344,7 @@ export function createTerminalEnvironment(
configurationResolverService: IConfigurationResolverService | undefined,
isWorkspaceShellAllowed: boolean,
version: string | undefined,
setLocaleVariables: boolean,
detectLocale: 'auto' | 'off' | 'on',
baseEnv: platform.IProcessEnvironment
): platform.IProcessEnvironment {
// Create a terminal environment based on settings, launch config and permissions
......@@ -369,7 +379,7 @@ export function createTerminalEnvironment(
mergeEnvironments(env, shellLaunchConfig.env);
// Adding other env keys necessary to create the process
addTerminalEnvironmentKeys(env, version, platform.locale, setLocaleVariables);
addTerminalEnvironmentKeys(env, version, platform.locale, detectLocale);
}
return env;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册