Skip to content

Commit 33a00fd

Browse files
committed
Support terminal.integrated.letterSpacing
Fixes microsoft#49566
1 parent 7c8cdfe commit 33a00fd

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

src/vs/workbench/parts/terminal/browser/terminalTab.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ export class TerminalTab extends Disposable implements ITerminalTab {
446446

447447
const isHorizontal = (direction === Direction.Left || direction === Direction.Right);
448448
const font = this._terminalService.configHelper.getFont();
449+
// TODO: Support letter spacing and line height
449450
const amount = isHorizontal ? font.charWidth : font.charHeight;
450451
if (amount) {
451452
this._splitPaneContainer.resizePane(this._activeInstanceIndex, direction, amount);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ export const TerminalCursorStyle = {
4545

4646
export const TERMINAL_CONFIG_SECTION = 'terminal.integrated';
4747

48+
export const DEFAULT_LETTER_SPACING = 0;
49+
export const MINIMUM_LETTER_SPACING = -5;
50+
export const DEFAULT_LINE_HEIGHT = 1.0;
51+
4852
export type FontWeight = 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
4953

5054
export interface ITerminalConfiguration {
@@ -67,6 +71,7 @@ export interface ITerminalConfiguration {
6771
fontWeightBold: FontWeight;
6872
// fontLigatures: boolean;
6973
fontSize: number;
74+
letterSpacing: number;
7075
lineHeight: number;
7176
setLocaleVariables: boolean;
7277
scrollback: number;
@@ -97,6 +102,7 @@ export interface ITerminalConfigHelper {
97102
export interface ITerminalFont {
98103
fontFamily: string;
99104
fontSize: number;
105+
letterSpacing: number;
100106
lineHeight: number;
101107
charWidth?: number;
102108
charHeight?: number;

src/vs/workbench/parts/terminal/electron-browser/terminal.contribution.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import * as panel from 'vs/workbench/browser/panel';
1313
import * as platform from 'vs/base/common/platform';
1414
import * as terminalCommands from 'vs/workbench/parts/terminal/common/terminalCommands';
1515
import { Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
16-
import { ITerminalService, KEYBINDING_CONTEXT_TERMINAL_FOCUS, KEYBINDING_CONTEXT_TERMINAL_FIND_WIDGET_INPUT_FOCUSED, KEYBINDING_CONTEXT_TERMINAL_TEXT_SELECTED, TERMINAL_PANEL_ID, KEYBINDING_CONTEXT_TERMINAL_FIND_WIDGET_VISIBLE, TerminalCursorStyle, KEYBINDING_CONTEXT_TERMINAL_FIND_WIDGET_NOT_VISIBLE } from 'vs/workbench/parts/terminal/common/terminal';
16+
import { ITerminalService, KEYBINDING_CONTEXT_TERMINAL_FOCUS, KEYBINDING_CONTEXT_TERMINAL_FIND_WIDGET_INPUT_FOCUSED, KEYBINDING_CONTEXT_TERMINAL_TEXT_SELECTED, TERMINAL_PANEL_ID, KEYBINDING_CONTEXT_TERMINAL_FIND_WIDGET_VISIBLE, TerminalCursorStyle, KEYBINDING_CONTEXT_TERMINAL_FIND_WIDGET_NOT_VISIBLE, DEFAULT_LINE_HEIGHT, DEFAULT_LETTER_SPACING } from 'vs/workbench/parts/terminal/common/terminal';
1717
import { getTerminalDefaultShellUnixLike, getTerminalDefaultShellWindows } from 'vs/workbench/parts/terminal/node/terminal';
1818
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
1919
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
@@ -140,10 +140,15 @@ configurationRegistry.registerConfiguration({
140140
'type': 'number',
141141
'default': EDITOR_FONT_DEFAULTS.fontSize
142142
},
143+
'terminal.integrated.letterSpacing': {
144+
'description': nls.localize('terminal.integrated.letterSpacing', "Controls the letter spacing of the terminal, this is an integer value which represents the amount of additional pixels to add between characters."),
145+
'type': 'number',
146+
'default': DEFAULT_LETTER_SPACING
147+
},
143148
'terminal.integrated.lineHeight': {
144149
'description': nls.localize('terminal.integrated.lineHeight', "Controls the line height of the terminal, this number is multiplied by the terminal font size to get the actual line-height in pixels."),
145150
'type': 'number',
146-
'default': 1
151+
'default': DEFAULT_LINE_HEIGHT
147152
},
148153
'terminal.integrated.fontWeight': {
149154
'type': 'string',

src/vs/workbench/parts/terminal/electron-browser/terminalConfigHelper.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ import { EDITOR_FONT_DEFAULTS, IEditorOptions } from 'vs/editor/common/config/ed
1010
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1111
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
1212
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
13-
import { ITerminalConfiguration, ITerminalConfigHelper, ITerminalFont, IShellLaunchConfig, IS_WORKSPACE_SHELL_ALLOWED_STORAGE_KEY, TERMINAL_CONFIG_SECTION } from 'vs/workbench/parts/terminal/common/terminal';
13+
import { ITerminalConfiguration, ITerminalConfigHelper, ITerminalFont, IShellLaunchConfig, IS_WORKSPACE_SHELL_ALLOWED_STORAGE_KEY, TERMINAL_CONFIG_SECTION, DEFAULT_LETTER_SPACING, DEFAULT_LINE_HEIGHT, MINIMUM_LETTER_SPACING } from 'vs/workbench/parts/terminal/common/terminal';
1414
import Severity from 'vs/base/common/severity';
1515
import { isFedora } from 'vs/workbench/parts/terminal/node/terminal';
1616
import { Terminal as XTermTerminal } from 'vscode-xterm';
1717
import { INotificationService } from 'vs/platform/notification/common/notification';
1818

19-
const DEFAULT_LINE_HEIGHT = 1.0;
20-
2119
const MINIMUM_FONT_SIZE = 6;
2220
const MAXIMUM_FONT_SIZE = 25;
2321

@@ -50,7 +48,7 @@ export class TerminalConfigHelper implements ITerminalConfigHelper {
5048
this.config = this._configurationService.getValue<ITerminalConfiguration>(TERMINAL_CONFIG_SECTION);
5149
}
5250

53-
private _measureFont(fontFamily: string, fontSize: number, lineHeight: number): ITerminalFont {
51+
private _measureFont(fontFamily: string, fontSize: number, letterSpacing: number, lineHeight: number): ITerminalFont {
5452
// Create charMeasureElement if it hasn't been created or if it was orphaned by its parent
5553
if (!this._charMeasureElement || !this._charMeasureElement.parentElement) {
5654
this._charMeasureElement = document.createElement('div');
@@ -74,6 +72,7 @@ export class TerminalConfigHelper implements ITerminalConfigHelper {
7472
this._lastFontMeasurement = {
7573
fontFamily,
7674
fontSize,
75+
letterSpacing,
7776
lineHeight,
7877
charWidth: rect.width,
7978
charHeight: Math.ceil(rect.height)
@@ -98,12 +97,14 @@ export class TerminalConfigHelper implements ITerminalConfigHelper {
9897
}
9998

10099
let fontSize = this._toInteger(this.config.fontSize, MINIMUM_FONT_SIZE, MAXIMUM_FONT_SIZE, EDITOR_FONT_DEFAULTS.fontSize);
100+
const letterSpacing = this.config.letterSpacing ? Math.max(Math.floor(this.config.letterSpacing), MINIMUM_LETTER_SPACING) : DEFAULT_LETTER_SPACING;
101101
const lineHeight = this.config.lineHeight ? Math.max(this.config.lineHeight, 1) : DEFAULT_LINE_HEIGHT;
102102

103103
if (excludeDimensions) {
104104
return {
105105
fontFamily,
106106
fontSize,
107+
letterSpacing,
107108
lineHeight
108109
};
109110
}
@@ -114,6 +115,7 @@ export class TerminalConfigHelper implements ITerminalConfigHelper {
114115
return {
115116
fontFamily,
116117
fontSize,
118+
letterSpacing,
117119
lineHeight,
118120
charHeight: xterm.charMeasure.height,
119121
charWidth: xterm.charMeasure.width
@@ -122,7 +124,7 @@ export class TerminalConfigHelper implements ITerminalConfigHelper {
122124
}
123125

124126
// Fall back to measuring the font ourselves
125-
return this._measureFont(fontFamily, fontSize, lineHeight);
127+
return this._measureFont(fontFamily, fontSize, letterSpacing, lineHeight);
126128
}
127129

128130
public setWorkspaceShellAllowed(isAllowed: boolean): void {

src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export class TerminalInstance implements ITerminalInstance {
185185
// order to be precise. font.charWidth/charHeight alone as insufficient
186186
// when window.devicePixelRatio changes.
187187
const scaledWidthAvailable = dimension.width * window.devicePixelRatio;
188-
const scaledCharWidth = Math.floor(font.charWidth * window.devicePixelRatio);
188+
const scaledCharWidth = Math.floor(font.charWidth * window.devicePixelRatio) + font.letterSpacing;
189189
this._cols = Math.max(Math.floor(scaledWidthAvailable / scaledCharWidth), 1);
190190

191191
const scaledHeightAvailable = dimension.height * window.devicePixelRatio;
@@ -256,6 +256,7 @@ export class TerminalInstance implements ITerminalInstance {
256256
fontWeight: this._configHelper.config.fontWeight,
257257
fontWeightBold: this._configHelper.config.fontWeightBold,
258258
fontSize: font.fontSize,
259+
letterSpacing: font.letterSpacing,
259260
lineHeight: font.lineHeight,
260261
bellStyle: this._configHelper.config.enableBell ? 'sound' : 'none',
261262
screenReaderMode: accessibilitySupport === 'on',
@@ -848,6 +849,9 @@ export class TerminalInstance implements ITerminalInstance {
848849
// Only apply these settings when the terminal is visible so that
849850
// the characters are measured correctly.
850851
if (this._isVisible) {
852+
if (this._xterm.getOption('letterSpacing') !== font.letterSpacing) {
853+
this._xterm.setOption('letterSpacing', font.letterSpacing);
854+
}
851855
if (this._xterm.getOption('lineHeight') !== font.lineHeight) {
852856
this._xterm.setOption('lineHeight', font.lineHeight);
853857
}

0 commit comments

Comments
 (0)