提交 33a00fd4 编写于 作者: D Daniel Imms

Support terminal.integrated.letterSpacing

Fixes #49566
上级 7c8cdfe9
......@@ -446,6 +446,7 @@ export class TerminalTab extends Disposable implements ITerminalTab {
const isHorizontal = (direction === Direction.Left || direction === Direction.Right);
const font = this._terminalService.configHelper.getFont();
// TODO: Support letter spacing and line height
const amount = isHorizontal ? font.charWidth : font.charHeight;
if (amount) {
this._splitPaneContainer.resizePane(this._activeInstanceIndex, direction, amount);
......
......@@ -45,6 +45,10 @@ export const TerminalCursorStyle = {
export const TERMINAL_CONFIG_SECTION = 'terminal.integrated';
export const DEFAULT_LETTER_SPACING = 0;
export const MINIMUM_LETTER_SPACING = -5;
export const DEFAULT_LINE_HEIGHT = 1.0;
export type FontWeight = 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
export interface ITerminalConfiguration {
......@@ -67,6 +71,7 @@ export interface ITerminalConfiguration {
fontWeightBold: FontWeight;
// fontLigatures: boolean;
fontSize: number;
letterSpacing: number;
lineHeight: number;
setLocaleVariables: boolean;
scrollback: number;
......@@ -97,6 +102,7 @@ export interface ITerminalConfigHelper {
export interface ITerminalFont {
fontFamily: string;
fontSize: number;
letterSpacing: number;
lineHeight: number;
charWidth?: number;
charHeight?: number;
......
......@@ -13,7 +13,7 @@ import * as panel from 'vs/workbench/browser/panel';
import * as platform from 'vs/base/common/platform';
import * as terminalCommands from 'vs/workbench/parts/terminal/common/terminalCommands';
import { Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
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';
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';
import { getTerminalDefaultShellUnixLike, getTerminalDefaultShellWindows } from 'vs/workbench/parts/terminal/node/terminal';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
......@@ -140,10 +140,15 @@ configurationRegistry.registerConfiguration({
'type': 'number',
'default': EDITOR_FONT_DEFAULTS.fontSize
},
'terminal.integrated.letterSpacing': {
'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."),
'type': 'number',
'default': DEFAULT_LETTER_SPACING
},
'terminal.integrated.lineHeight': {
'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."),
'type': 'number',
'default': 1
'default': DEFAULT_LINE_HEIGHT
},
'terminal.integrated.fontWeight': {
'type': 'string',
......
......@@ -10,14 +10,12 @@ import { EDITOR_FONT_DEFAULTS, IEditorOptions } from 'vs/editor/common/config/ed
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { ITerminalConfiguration, ITerminalConfigHelper, ITerminalFont, IShellLaunchConfig, IS_WORKSPACE_SHELL_ALLOWED_STORAGE_KEY, TERMINAL_CONFIG_SECTION } from 'vs/workbench/parts/terminal/common/terminal';
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';
import Severity from 'vs/base/common/severity';
import { isFedora } from 'vs/workbench/parts/terminal/node/terminal';
import { Terminal as XTermTerminal } from 'vscode-xterm';
import { INotificationService } from 'vs/platform/notification/common/notification';
const DEFAULT_LINE_HEIGHT = 1.0;
const MINIMUM_FONT_SIZE = 6;
const MAXIMUM_FONT_SIZE = 25;
......@@ -50,7 +48,7 @@ export class TerminalConfigHelper implements ITerminalConfigHelper {
this.config = this._configurationService.getValue<ITerminalConfiguration>(TERMINAL_CONFIG_SECTION);
}
private _measureFont(fontFamily: string, fontSize: number, lineHeight: number): ITerminalFont {
private _measureFont(fontFamily: string, fontSize: number, letterSpacing: number, lineHeight: number): ITerminalFont {
// Create charMeasureElement if it hasn't been created or if it was orphaned by its parent
if (!this._charMeasureElement || !this._charMeasureElement.parentElement) {
this._charMeasureElement = document.createElement('div');
......@@ -74,6 +72,7 @@ export class TerminalConfigHelper implements ITerminalConfigHelper {
this._lastFontMeasurement = {
fontFamily,
fontSize,
letterSpacing,
lineHeight,
charWidth: rect.width,
charHeight: Math.ceil(rect.height)
......@@ -98,12 +97,14 @@ export class TerminalConfigHelper implements ITerminalConfigHelper {
}
let fontSize = this._toInteger(this.config.fontSize, MINIMUM_FONT_SIZE, MAXIMUM_FONT_SIZE, EDITOR_FONT_DEFAULTS.fontSize);
const letterSpacing = this.config.letterSpacing ? Math.max(Math.floor(this.config.letterSpacing), MINIMUM_LETTER_SPACING) : DEFAULT_LETTER_SPACING;
const lineHeight = this.config.lineHeight ? Math.max(this.config.lineHeight, 1) : DEFAULT_LINE_HEIGHT;
if (excludeDimensions) {
return {
fontFamily,
fontSize,
letterSpacing,
lineHeight
};
}
......@@ -114,6 +115,7 @@ export class TerminalConfigHelper implements ITerminalConfigHelper {
return {
fontFamily,
fontSize,
letterSpacing,
lineHeight,
charHeight: xterm.charMeasure.height,
charWidth: xterm.charMeasure.width
......@@ -122,7 +124,7 @@ export class TerminalConfigHelper implements ITerminalConfigHelper {
}
// Fall back to measuring the font ourselves
return this._measureFont(fontFamily, fontSize, lineHeight);
return this._measureFont(fontFamily, fontSize, letterSpacing, lineHeight);
}
public setWorkspaceShellAllowed(isAllowed: boolean): void {
......
......@@ -185,7 +185,7 @@ export class TerminalInstance implements ITerminalInstance {
// order to be precise. font.charWidth/charHeight alone as insufficient
// when window.devicePixelRatio changes.
const scaledWidthAvailable = dimension.width * window.devicePixelRatio;
const scaledCharWidth = Math.floor(font.charWidth * window.devicePixelRatio);
const scaledCharWidth = Math.floor(font.charWidth * window.devicePixelRatio) + font.letterSpacing;
this._cols = Math.max(Math.floor(scaledWidthAvailable / scaledCharWidth), 1);
const scaledHeightAvailable = dimension.height * window.devicePixelRatio;
......@@ -256,6 +256,7 @@ export class TerminalInstance implements ITerminalInstance {
fontWeight: this._configHelper.config.fontWeight,
fontWeightBold: this._configHelper.config.fontWeightBold,
fontSize: font.fontSize,
letterSpacing: font.letterSpacing,
lineHeight: font.lineHeight,
bellStyle: this._configHelper.config.enableBell ? 'sound' : 'none',
screenReaderMode: accessibilitySupport === 'on',
......@@ -848,6 +849,9 @@ export class TerminalInstance implements ITerminalInstance {
// Only apply these settings when the terminal is visible so that
// the characters are measured correctly.
if (this._isVisible) {
if (this._xterm.getOption('letterSpacing') !== font.letterSpacing) {
this._xterm.setOption('letterSpacing', font.letterSpacing);
}
if (this._xterm.getOption('lineHeight') !== font.lineHeight) {
this._xterm.setOption('lineHeight', font.lineHeight);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册