提交 46df55c9 编写于 作者: D Daniel Imms 提交者: GitHub

Merge pull request #13169 from Microsoft/tyriar/6979_terminal_themes

Enable terminal themes via tmTheme
......@@ -34,6 +34,23 @@ interface ThemeGlobalSettings {
referenceHighlight?: string;
activeLinkForeground?: string;
ansiBlack?: string;
ansiRed?: string;
ansiGreen?: string;
ansiYellow?: string;
ansiBlue?: string;
ansiMagenta?: string;
ansiCyan?: string;
ansiWhite?: string;
ansiBrightBlack?: string;
ansiBrightRed?: string;
ansiBrightGreen?: string;
ansiBrightYellow?: string;
ansiBrightBlue?: string;
ansiBrightMagenta?: string;
ansiBrightCyan?: string;
ansiBrightWhite?: string;
}
class Theme {
......@@ -170,6 +187,57 @@ export class SearchViewStylesContribution {
}
}
export class TerminalStylesContribution {
private static ansiColorMap = {
ansiBlack: 0,
ansiRed: 1,
ansiGreen: 2,
ansiYellow: 3,
ansiBlue: 4,
ansiMagenta: 5,
ansiCyan: 6,
ansiWhite: 7,
ansiBrightBlack: 8,
ansiBrightRed: 9,
ansiBrightGreen: 10,
ansiBrightYellow: 11,
ansiBrightBlue: 12,
ansiBrightMagenta: 13,
ansiBrightCyan: 14,
ansiBrightWhite: 15
};
/**
* Converts a CSS hex color (#rrggbb) to a CSS rgba color (rgba(r, g, b, a)).
*/
private _convertHexCssColorToRgba(hex: string, alpha: number): string {
const r = parseInt(hex.substr(1, 2), 16);
const g = parseInt(hex.substr(3, 2), 16);
const b = parseInt(hex.substr(5, 2), 16);
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
}
public contributeStyles(themeId: string, themeDocument: IThemeDocument, cssRules: string[]): void {
const theme = new Theme(themeId, themeDocument);
if (theme.hasGlobalSettings()) {
const keys = Object.keys(theme.getGlobalSettings());
keys.filter(key => key.indexOf('ansi') === 0).forEach(key => {
if (key in TerminalStylesContribution.ansiColorMap) {
const color = theme.getGlobalSettings()[key];
const index = TerminalStylesContribution.ansiColorMap[key];
const rgba = this._convertHexCssColorToRgba(color, 0.996);
cssRules.push(`.${theme.getSelector()} .panel.integrated-terminal .xterm .xterm-color-${index} { color: ${color}; }`);
cssRules.push(`.${theme.getSelector()} .panel.integrated-terminal .xterm .xterm-color-${index}::selection { background-color: ${rgba}; }`);
cssRules.push(`.${theme.getSelector()} .panel.integrated-terminal .xterm .xterm-bg-color-${index} { background-color: ${color}; }`);
cssRules.push(`.${theme.getSelector()} .panel.integrated-terminal .xterm .xterm-bg-color-${index}::selection { color: ${color}; }`);
}
});
}
}
}
abstract class EditorStyleRules extends StyleRules {
protected addBackgroundColorRule(theme: Theme, selector: string, color: string | Color, rules: string[]): void {
......
......@@ -12,7 +12,7 @@ import { IThemeExtensionPoint } from 'vs/platform/theme/common/themeExtensionPoi
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
import { ExtensionsRegistry, IExtensionMessageCollector } from 'vs/platform/extensions/common/extensionsRegistry';
import { IThemeService, IThemeData, IThemeSetting, IThemeDocument } from 'vs/workbench/services/themes/common/themeService';
import { TokenStylesContribution, EditorStylesContribution, SearchViewStylesContribution } from 'vs/workbench/services/themes/electron-browser/stylesContributions';
import { TokenStylesContribution, EditorStylesContribution, SearchViewStylesContribution, TerminalStylesContribution } from 'vs/workbench/services/themes/electron-browser/stylesContributions';
import { getBaseThemeId } from 'vs/platform/theme/common/themes';
import { IWindowService } from 'vs/workbench/services/window/electron-browser/windowService';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
......@@ -637,6 +637,7 @@ function _processThemeObject(themeId: string, themeDocument: IThemeDocument): st
new TokenStylesContribution().contributeStyles(themeId, themeDocument, cssRules);
new EditorStylesContribution().contributeStyles(themeId, themeDocument, cssRules);
new SearchViewStylesContribution().contributeStyles(themeId, themeDocument, cssRules);
new TerminalStylesContribution().contributeStyles(themeId, themeDocument, cssRules);
}
return cssRules.join('\n');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册