Skip to content

Commit f4833ee

Browse files
authored
Merge pull request microsoft#106072 from IllusionMH/terminal-numeric-font-weight-101467
Add numeric values support for terminal.integrated.fontWeight
2 parents 758f355 + 6f82a39 commit f4833ee

3 files changed

Lines changed: 56 additions & 13 deletions

File tree

src/vs/workbench/contrib/terminal/browser/terminalConfigHelper.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as platform from 'vs/base/common/platform';
88
import { EDITOR_FONT_DEFAULTS, IEditorOptions } from 'vs/editor/common/config/editorOptions';
99
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1010
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
11-
import { ITerminalConfiguration, ITerminalFont, IS_WORKSPACE_SHELL_ALLOWED_STORAGE_KEY, TERMINAL_CONFIG_SECTION, DEFAULT_LETTER_SPACING, DEFAULT_LINE_HEIGHT, MINIMUM_LETTER_SPACING, LinuxDistro, IShellLaunchConfig } from 'vs/workbench/contrib/terminal/common/terminal';
11+
import { ITerminalConfiguration, ITerminalFont, IS_WORKSPACE_SHELL_ALLOWED_STORAGE_KEY, TERMINAL_CONFIG_SECTION, DEFAULT_LETTER_SPACING, DEFAULT_LINE_HEIGHT, MINIMUM_LETTER_SPACING, LinuxDistro, IShellLaunchConfig, MINIMUM_FONT_WEIGHT, MAXIMUM_FONT_WEIGHT, DEFAULT_FONT_WEIGHT, DEFAULT_BOLD_FONT_WEIGHT, FontWeight } from 'vs/workbench/contrib/terminal/common/terminal';
1212
import Severity from 'vs/base/common/severity';
1313
import { INotificationService, NeverShowAgainScope } from 'vs/platform/notification/common/notification';
1414
import { IBrowserTerminalConfigHelper } from 'vs/workbench/contrib/terminal/browser/terminal';
@@ -67,7 +67,11 @@ export class TerminalConfigHelper implements IBrowserTerminalConfigHelper {
6767
}
6868

6969
private _updateConfig(): void {
70-
this.config = this._configurationService.getValue<ITerminalConfiguration>(TERMINAL_CONFIG_SECTION);
70+
const configValues = this._configurationService.getValue<ITerminalConfiguration>(TERMINAL_CONFIG_SECTION);
71+
configValues.fontWeight = this._normalizeFontWeight(configValues.fontWeight, DEFAULT_FONT_WEIGHT);
72+
configValues.fontWeightBold = this._normalizeFontWeight(configValues.fontWeightBold, DEFAULT_BOLD_FONT_WEIGHT);
73+
74+
this.config = configValues;
7175
}
7276

7377
public configFontIsMonospace(): boolean {
@@ -157,7 +161,7 @@ export class TerminalConfigHelper implements IBrowserTerminalConfigHelper {
157161
const editorConfig = this._configurationService.getValue<IEditorOptions>('editor');
158162

159163
let fontFamily = this.config.fontFamily || editorConfig.fontFamily || EDITOR_FONT_DEFAULTS.fontFamily;
160-
let fontSize = this._toInteger(this.config.fontSize, MINIMUM_FONT_SIZE, MAXIMUM_FONT_SIZE, EDITOR_FONT_DEFAULTS.fontSize);
164+
let fontSize = this._clampInt(this.config.fontSize, MINIMUM_FONT_SIZE, MAXIMUM_FONT_SIZE, EDITOR_FONT_DEFAULTS.fontSize);
161165

162166
// Work around bad font on Fedora/Ubuntu
163167
if (!this.config.fontFamily) {
@@ -168,7 +172,7 @@ export class TerminalConfigHelper implements IBrowserTerminalConfigHelper {
168172
fontFamily = '\'Ubuntu Mono\', monospace';
169173

170174
// Ubuntu mono is somehow smaller, so set fontSize a bit larger to get the same perceived size.
171-
fontSize = this._toInteger(fontSize + 2, MINIMUM_FONT_SIZE, MAXIMUM_FONT_SIZE, EDITOR_FONT_DEFAULTS.fontSize);
175+
fontSize = this._clampInt(fontSize + 2, MINIMUM_FONT_SIZE, MAXIMUM_FONT_SIZE, EDITOR_FONT_DEFAULTS.fontSize);
172176
}
173177
}
174178

@@ -271,7 +275,7 @@ export class TerminalConfigHelper implements IBrowserTerminalConfigHelper {
271275
return !!isWorkspaceShellAllowed;
272276
}
273277

274-
private _toInteger(source: any, minimum: number, maximum: number, fallback: number): number {
278+
private _clampInt<T>(source: any, minimum: number, maximum: number, fallback: T): number | T {
275279
let r = parseInt(source, 10);
276280
if (isNaN(r)) {
277281
return fallback;
@@ -340,4 +344,11 @@ export class TerminalConfigHelper implements IBrowserTerminalConfigHelper {
340344
const extensions = await this._extensionManagementService.getInstalled(ExtensionType.User);
341345
return extensions.some(e => e.identifier.id === id);
342346
}
347+
348+
private _normalizeFontWeight(input: any, defaultWeight: FontWeight): FontWeight {
349+
if (input === 'normal' || input === 'bold') {
350+
return input;
351+
}
352+
return this._clampInt(input, MINIMUM_FONT_WEIGHT, MAXIMUM_FONT_WEIGHT, defaultWeight);
353+
}
343354
}

src/vs/workbench/contrib/terminal/common/terminal.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,13 @@ export const DEFAULT_LETTER_SPACING = 0;
7070
export const MINIMUM_LETTER_SPACING = -5;
7171
export const DEFAULT_LINE_HEIGHT = 1;
7272

73-
export type FontWeight = 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
73+
export const MINIMUM_FONT_WEIGHT = 1;
74+
export const MAXIMUM_FONT_WEIGHT = 1000;
75+
export const DEFAULT_FONT_WEIGHT = 'normal';
76+
export const DEFAULT_BOLD_FONT_WEIGHT = 'bold';
77+
export const SUGGESTIONS_FONT_WEIGHT = ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900'];
78+
79+
export type FontWeight = 'normal' | 'bold' | number;
7480

7581
export interface ITerminalConfiguration {
7682
shell: {

src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { IConfigurationNode } from 'vs/platform/configuration/common/configurationRegistry';
77
import { localize } from 'vs/nls';
88
import { EDITOR_FONT_DEFAULTS } from 'vs/editor/common/config/editorOptions';
9-
import { DEFAULT_LETTER_SPACING, DEFAULT_LINE_HEIGHT, TerminalCursorStyle, DEFAULT_COMMANDS_TO_SKIP_SHELL } from 'vs/workbench/contrib/terminal/common/terminal';
9+
import { DEFAULT_LETTER_SPACING, DEFAULT_LINE_HEIGHT, TerminalCursorStyle, DEFAULT_COMMANDS_TO_SKIP_SHELL, SUGGESTIONS_FONT_WEIGHT, MINIMUM_FONT_WEIGHT, MAXIMUM_FONT_WEIGHT } from 'vs/workbench/contrib/terminal/common/terminal';
1010
import { isMacintosh, isWindows, Platform } from 'vs/base/common/platform';
1111

1212
export const terminalConfiguration: IConfigurationNode = {
@@ -136,15 +136,41 @@ export const terminalConfiguration: IConfigurationNode = {
136136
default: 1
137137
},
138138
'terminal.integrated.fontWeight': {
139-
type: 'string',
140-
enum: ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900'],
141-
description: localize('terminal.integrated.fontWeight', "The font weight to use within the terminal for non-bold text."),
139+
'anyOf': [
140+
{
141+
type: 'number',
142+
minimum: MINIMUM_FONT_WEIGHT,
143+
maximum: MAXIMUM_FONT_WEIGHT,
144+
errorMessage: localize('terminal.integrated.fontWeightError', "Only \"normal\" and \"bold\" keywords or numbers between 1 and 1000 are allowed.")
145+
},
146+
{
147+
type: 'string',
148+
pattern: '^(normal|bold|1000|[1-9][0-9]{0,2})$'
149+
},
150+
{
151+
enum: SUGGESTIONS_FONT_WEIGHT,
152+
}
153+
],
154+
description: localize('terminal.integrated.fontWeight', "The font weight to use within the terminal for non-bold text. Accepts \"normal\" and \"bold\" keywords or numbers between 1 and 1000."),
142155
default: 'normal'
143156
},
144157
'terminal.integrated.fontWeightBold': {
145-
type: 'string',
146-
enum: ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900'],
147-
description: localize('terminal.integrated.fontWeightBold', "The font weight to use within the terminal for bold text."),
158+
'anyOf': [
159+
{
160+
type: 'number',
161+
minimum: MINIMUM_FONT_WEIGHT,
162+
maximum: MAXIMUM_FONT_WEIGHT,
163+
errorMessage: localize('terminal.integrated.fontWeightError', "Only \"normal\" and \"bold\" keywords or numbers between 1 and 1000 are allowed.")
164+
},
165+
{
166+
type: 'string',
167+
pattern: '^(normal|bold|1000|[1-9][0-9]{0,2})$'
168+
},
169+
{
170+
enum: SUGGESTIONS_FONT_WEIGHT,
171+
}
172+
],
173+
description: localize('terminal.integrated.fontWeightBold', "The font weight to use within the terminal for bold text. Accepts \"normal\" and \"bold\" keywords or numbers between 1 and 1000."),
148174
default: 'bold'
149175
},
150176
'terminal.integrated.cursorBlinking': {

0 commit comments

Comments
 (0)