-
Notifications
You must be signed in to change notification settings - Fork 28.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Part of #136055
- Loading branch information
Showing
7 changed files
with
238 additions
and
121 deletions.
There are no files selected for viewing
143 changes: 143 additions & 0 deletions
143
src/vs/workbench/contrib/terminal/browser/addons/xtermTerminal.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import type { ITheme, RendererType, Terminal as IXtermTerminal } from 'xterm'; | ||
// import { IXtermCore } from 'vs/workbench/contrib/terminal/browser/xterm-private'; | ||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; | ||
import { TerminalConfigHelper } from 'vs/workbench/contrib/terminal/browser/terminalConfigHelper'; | ||
import { DisposableStore } from 'vs/base/common/lifecycle'; | ||
import { IEditorOptions } from 'vs/editor/common/config/editorOptions'; | ||
import { TerminalLocation, TerminalSettingId } from 'vs/platform/terminal/common/terminal'; | ||
import { IColorTheme, IThemeService } from 'vs/platform/theme/common/themeService'; | ||
import { IViewDescriptorService, ViewContainerLocation } from 'vs/workbench/common/views'; | ||
import { editorBackground } from 'vs/platform/theme/common/colorRegistry'; | ||
import { ansiColorIdentifiers, TERMINAL_BACKGROUND_COLOR, TERMINAL_CURSOR_BACKGROUND_COLOR, TERMINAL_CURSOR_FOREGROUND_COLOR, TERMINAL_FOREGROUND_COLOR, TERMINAL_SELECTION_BACKGROUND_COLOR } from 'vs/workbench/contrib/terminal/common/terminalColorRegistry'; | ||
import { TERMINAL_VIEW_ID } from 'vs/workbench/contrib/terminal/common/terminal'; | ||
import { PANEL_BACKGROUND, SIDE_BAR_BACKGROUND } from 'vs/workbench/common/theme'; | ||
import { Color } from 'vs/base/common/color'; | ||
|
||
export const enum XtermTerminalConstants { | ||
DefaultCols = 80, | ||
DefaultRows = 30, | ||
MaxSupportedCols = 5000, | ||
MaxCanvasWidth = 8000 | ||
} | ||
|
||
/** | ||
* Wraps the xterm object with additional functionality. Interaction with the backing process is out | ||
* of the scope of this class. | ||
*/ | ||
export class XtermTerminal extends DisposableStore { | ||
/** The raw xterm.js instance */ | ||
readonly raw: IXtermTerminal; | ||
target?: TerminalLocation; | ||
|
||
// private _core: IXtermCore; | ||
private static _suggestedRendererType: 'canvas' | 'dom' | undefined = undefined; | ||
private _cols: number = 0; | ||
private _rows: number = 0; | ||
|
||
/** | ||
* @param xtermCtor The xterm.js constructor, this is passed in so it can be fetched lazily | ||
* outside of this class such that {@link raw} is not nullable. | ||
*/ | ||
constructor( | ||
xtermCtor: typeof IXtermTerminal, | ||
private readonly _configHelper: TerminalConfigHelper, | ||
@IConfigurationService private readonly _configurationService: IConfigurationService, | ||
@IThemeService private readonly _themeService: IThemeService, | ||
@IViewDescriptorService private readonly _viewDescriptorService: IViewDescriptorService, | ||
) { | ||
super(); | ||
|
||
const font = this._configHelper.getFont(undefined, true); | ||
const config = this._configHelper.config; | ||
const editorOptions = this._configurationService.getValue<IEditorOptions>('editor'); | ||
|
||
this.raw = this.add(new xtermCtor({ | ||
cols: this._cols || XtermTerminalConstants.DefaultCols, | ||
rows: this._rows || XtermTerminalConstants.DefaultRows, | ||
altClickMovesCursor: config.altClickMovesCursor && editorOptions.multiCursorModifier === 'alt', | ||
scrollback: config.scrollback, | ||
theme: this._getXtermTheme(), | ||
drawBoldTextInBrightColors: config.drawBoldTextInBrightColors, | ||
fontFamily: font.fontFamily, | ||
fontWeight: config.fontWeight, | ||
fontWeightBold: config.fontWeightBold, | ||
fontSize: font.fontSize, | ||
letterSpacing: font.letterSpacing, | ||
lineHeight: font.lineHeight, | ||
minimumContrastRatio: config.minimumContrastRatio, | ||
cursorBlink: config.cursorBlinking, | ||
cursorStyle: config.cursorStyle === 'line' ? 'bar' : config.cursorStyle, | ||
cursorWidth: config.cursorWidth, | ||
bellStyle: 'none', | ||
macOptionIsMeta: config.macOptionIsMeta, | ||
macOptionClickForcesSelection: config.macOptionClickForcesSelection, | ||
rightClickSelectsWord: config.rightClickBehavior === 'selectWord', | ||
fastScrollModifier: 'alt', | ||
fastScrollSensitivity: editorOptions.fastScrollSensitivity, | ||
scrollSensitivity: editorOptions.mouseWheelScrollSensitivity, | ||
rendererType: this._getBuiltInXtermRenderer(config.gpuAcceleration, XtermTerminal._suggestedRendererType), | ||
wordSeparator: config.wordSeparators | ||
})); | ||
|
||
this.add(this._configurationService.onDidChangeConfiguration(async e => { | ||
if (e.affectsConfiguration(TerminalSettingId.GpuAcceleration)) { | ||
XtermTerminal._suggestedRendererType = undefined; | ||
} | ||
})); | ||
} | ||
|
||
private _getBuiltInXtermRenderer(gpuAcceleration: string, suggestedRendererType?: string): RendererType { | ||
let rendererType: RendererType = 'canvas'; | ||
if (gpuAcceleration === 'off' || (gpuAcceleration === 'auto' && suggestedRendererType === 'dom')) { | ||
rendererType = 'dom'; | ||
} | ||
return rendererType; | ||
} | ||
|
||
private _getXtermTheme(theme?: IColorTheme): ITheme { | ||
if (!theme) { | ||
theme = this._themeService.getColorTheme(); | ||
} | ||
|
||
const location = this._viewDescriptorService.getViewLocationById(TERMINAL_VIEW_ID)!; | ||
const foregroundColor = theme.getColor(TERMINAL_FOREGROUND_COLOR); | ||
let backgroundColor: Color | undefined; | ||
if (this.target === TerminalLocation.Editor) { | ||
backgroundColor = theme.getColor(TERMINAL_BACKGROUND_COLOR) || theme.getColor(editorBackground); | ||
} else { | ||
backgroundColor = theme.getColor(TERMINAL_BACKGROUND_COLOR) || (location === ViewContainerLocation.Panel ? theme.getColor(PANEL_BACKGROUND) : theme.getColor(SIDE_BAR_BACKGROUND)); | ||
} | ||
const cursorColor = theme.getColor(TERMINAL_CURSOR_FOREGROUND_COLOR) || foregroundColor; | ||
const cursorAccentColor = theme.getColor(TERMINAL_CURSOR_BACKGROUND_COLOR) || backgroundColor; | ||
const selectionColor = theme.getColor(TERMINAL_SELECTION_BACKGROUND_COLOR); | ||
|
||
return { | ||
background: backgroundColor ? backgroundColor.toString() : undefined, | ||
foreground: foregroundColor ? foregroundColor.toString() : undefined, | ||
cursor: cursorColor ? cursorColor.toString() : undefined, | ||
cursorAccent: cursorAccentColor ? cursorAccentColor.toString() : undefined, | ||
selection: selectionColor ? selectionColor.toString() : undefined, | ||
black: theme.getColor(ansiColorIdentifiers[0])!.toString(), | ||
red: theme.getColor(ansiColorIdentifiers[1])!.toString(), | ||
green: theme.getColor(ansiColorIdentifiers[2])!.toString(), | ||
yellow: theme.getColor(ansiColorIdentifiers[3])!.toString(), | ||
blue: theme.getColor(ansiColorIdentifiers[4])!.toString(), | ||
magenta: theme.getColor(ansiColorIdentifiers[5])!.toString(), | ||
cyan: theme.getColor(ansiColorIdentifiers[6])!.toString(), | ||
white: theme.getColor(ansiColorIdentifiers[7])!.toString(), | ||
brightBlack: theme.getColor(ansiColorIdentifiers[8])!.toString(), | ||
brightRed: theme.getColor(ansiColorIdentifiers[9])!.toString(), | ||
brightGreen: theme.getColor(ansiColorIdentifiers[10])!.toString(), | ||
brightYellow: theme.getColor(ansiColorIdentifiers[11])!.toString(), | ||
brightBlue: theme.getColor(ansiColorIdentifiers[12])!.toString(), | ||
brightMagenta: theme.getColor(ansiColorIdentifiers[13])!.toString(), | ||
brightCyan: theme.getColor(ansiColorIdentifiers[14])!.toString(), | ||
brightWhite: theme.getColor(ansiColorIdentifiers[15])!.toString() | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.