Skip to content

Commit

Permalink
Add ligatures setting
Browse files Browse the repository at this point in the history
Can't disable without reload right now due to xtermjs/xterm.js#3289
  • Loading branch information
Tyriar committed Apr 2, 2021
1 parent bc94854 commit 36b1761
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
26 changes: 21 additions & 5 deletions src/vs/workbench/contrib/terminal/browser/terminalInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { IAccessibilityService } from 'vs/platform/accessibility/common/accessib
import { ITerminalInstanceService, ITerminalInstance, ITerminalExternalLinkProvider } from 'vs/workbench/contrib/terminal/browser/terminal';
import { TerminalProcessManager } from 'vs/workbench/contrib/terminal/browser/terminalProcessManager';
import type { Terminal as XTermTerminal, IBuffer, ITerminalAddon, RendererType } from 'xterm';
import type { LigaturesAddon } from 'xterm-addon-ligatures';
import type { SearchAddon, ISearchOptions } from 'xterm-addon-search';
import type { Unicode11Addon } from 'xterm-addon-unicode11';
import type { WebglAddon } from 'xterm-addon-webgl';
Expand Down Expand Up @@ -123,6 +124,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
private _widgetManager: TerminalWidgetManager = this._instantiationService.createInstance(TerminalWidgetManager);
private _linkManager: TerminalLinkManager | undefined;
private _environmentInfo: { widget: EnvironmentVariableInfoWidget, disposable: IDisposable } | undefined;
private _ligaturesAddon: LigaturesAddon | undefined;
private _webglAddon: WebglAddon | undefined;
private _commandTrackerAddon: CommandTrackerAddon | undefined;
private _navigationModeAddon: INavigationMode & ITerminalAddon | undefined;
Expand Down Expand Up @@ -555,11 +557,6 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
this._container.appendChild(this._wrapperElement);
xterm.open(this._xtermElement);


const LigaturesAddon = await this._terminalInstanceService.getXtermLigaturesConstructor();
console.log('load ligatures addon');
xterm.loadAddon(new LigaturesAddon());

const suggestedRendererType = this._storageService.get(SUGGESTED_RENDERER_TYPE, StorageScope.GLOBAL);
if (this._configHelper.config.gpuAcceleration === 'auto' && (suggestedRendererType === 'auto' || suggestedRendererType === undefined)
|| this._configHelper.config.gpuAcceleration === 'on') {
Expand Down Expand Up @@ -1306,6 +1303,11 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
this._disposeOfWebglRenderer();
this._safeSetOption('rendererType', (config.gpuAcceleration === 'auto' && suggestedRendererType === 'dom') ? 'dom' : (config.gpuAcceleration === 'off' ? 'dom' : 'canvas'));
}
if (config.fontLigatures) {
this._enableLigatures();
} else {
this._disableLigatures();
}
this._refreshEnvironmentVariableInfoWidgetState(this._processManager.environmentVariableInfo);
}

Expand Down Expand Up @@ -1345,6 +1347,20 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
this._webglAddon = undefined;
}

private async _enableLigatures(): Promise<void> {
if (!this._xterm || !this._wrapperElement || this._ligaturesAddon) {
return;
}
const LigaturesAddon = await this._terminalInstanceService.getXtermLigaturesConstructor();
this._ligaturesAddon = new LigaturesAddon();
this._xterm.loadAddon(this._ligaturesAddon);
}

private _disableLigatures() {
this._ligaturesAddon?.dispose();
this._ligaturesAddon = undefined;
}

private async _updateUnicodeVersion(): Promise<void> {
if (!this._xterm) {
throw new Error('Cannot update unicode version before xterm has been initialized');
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export interface ITerminalConfiguration {
minimumContrastRatio: number;
mouseWheelScrollSensitivity: number;
sendKeybindingsToShell: boolean;
// fontLigatures: boolean;
fontLigatures: boolean;
fontSize: number;
letterSpacing: number;
lineHeight: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,11 @@ export const terminalConfiguration: IConfigurationNode = {
markdownDescription: localize('terminal.integrated.fontFamily', "Controls the font family of the terminal, this defaults to `#editor.fontFamily#`'s value."),
type: 'string'
},
// TODO: Support font ligatures
// 'terminal.integrated.fontLigatures': {
// 'description': localize('terminal.integrated.fontLigatures', "Controls whether font ligatures are enabled in the terminal."),
// 'type': 'boolean',
// 'default': false
// },
'terminal.integrated.fontLigatures': {
'description': localize('terminal.integrated.fontLigatures', "Controls whether font ligatures are enabled in the terminal."),
'type': 'boolean',
'default': false
},
'terminal.integrated.fontSize': {
description: localize('terminal.integrated.fontSize', "Controls the font size in pixels of the terminal."),
type: 'number',
Expand Down

0 comments on commit 36b1761

Please sign in to comment.