提交 99dafc38 编写于 作者: M Martin Aeschlimann

[theme] adopt ITheme in standalone editor

上级 d97b01e3
......@@ -53,8 +53,8 @@ declare module monaco {
declare module monaco.editor {
#includeAll(vs/editor/browser/standalone/standaloneEditor;modes.=>languages.;editorCommon.=>):
#include(vs/editor/common/services/standaloneColorService): BuiltinTheme, ITheme
#include(vs/editor/common/modes/supports/tokenization): IThemeRule
#include(vs/editor/common/services/standaloneColorService): BuiltinTheme, IStandaloneThemeData, IColors
#include(vs/editor/common/modes/supports/tokenization): ITokenThemeRule
#include(vs/editor/common/services/webWorker): MonacoWebWorker, IWebWorkerOptions
#include(vs/editor/browser/standalone/standaloneCodeEditor): IEditorConstructionOptions, IDiffEditorConstructionOptions, IStandaloneCodeEditor, IStandaloneDiffEditor
export interface ICommandHandler {
......
......@@ -4,25 +4,91 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import { Theme, IThemeRule, generateTokensCSSForColorMap } from 'vs/editor/common/modes/supports/tokenization';
import { IStandaloneColorService, BuiltinTheme, ITheme } from 'vs/editor/common/services/standaloneColorService';
import { TokenTheme, ITokenThemeRule, generateTokensCSSForColorMap } from 'vs/editor/common/modes/supports/tokenization';
import { IStandaloneColorService, BuiltinTheme, IStandaloneThemeData, IStandaloneTheme, IColors } from 'vs/editor/common/services/standaloneColorService';
import { vs, vs_dark, hc_black } from 'vs/editor/common/standalone/themes';
import * as dom from 'vs/base/browser/dom';
import { TokenizationRegistry } from 'vs/editor/common/modes';
import { Color } from "vs/base/common/color";
import { Extensions, IColorRegistry, ColorIdentifier } from 'vs/platform/theme/common/colorRegistry';
import { Extensions as ThemingExtensions, IThemingRegistry, ICssStyleCollector } from 'vs/platform/theme/common/themeService';
import { Registry } from 'vs/platform/platform';
class KnownTheme {
cssClassName: string;
rules: IThemeRule[];
const VS_THEME_NAME = 'vs';
const VS_DARK_THEME_NAME = 'vs-dark';
const HC_BLACK_THEME_NAME = 'hc-black';
constructor(cssClassName: string, rules: IThemeRule[]) {
this.cssClassName = cssClassName;
const colorRegistry = <IColorRegistry>Registry.as(Extensions.ColorContribution);
const themingRegistry = Registry.as<IThemingRegistry>(ThemingExtensions.ThemingContribution);
class StandaloneTheme implements IStandaloneTheme {
id: string;
selector: string;
private rules: ITokenThemeRule[];
base: string;
private colors: { [colorId: string]: Color };
private defaultColors: { [colorId: string]: Color };
private _tokenTheme: TokenTheme;
constructor(base: string, name: string, colors: IColors, rules: ITokenThemeRule[]) {
if (name.length > 0) {
this.id = base + ' ' + name;
this.selector = base + '.' + name;
} else {
this.id = base;
this.selector = base;
}
this.rules = rules;
this.colors = {};
for (let id in colors) {
this.colors[id] = Color.fromHex(colors[id]);
}
this.defaultColors = {};
}
}
const VS_THEME_NAME = 'vs';
const VS_DARK_THEME_NAME = 'vs-dark';
const HC_BLACK_THEME_NAME = 'hc-black';
public getColor(colorId: ColorIdentifier, useDefault?: boolean): Color {
if (this.colors.hasOwnProperty(colorId)) {
return this.colors[colorId];
}
if (useDefault !== false) {
return this.getDefault(colorId);
}
return null;
}
private getDefault(colorId: ColorIdentifier): Color {
if (this.defaultColors.hasOwnProperty(colorId)) {
return this.defaultColors[colorId];
}
let color = colorRegistry.resolveDefaultColor(colorId, this);
this.defaultColors[colorId] = color;
return color;
}
public isDefault(colorId: ColorIdentifier): boolean {
if (!this.colors.hasOwnProperty(colorId)) {
return true;
}
let color = this.colors[colorId];
let defaultValue = this.getDefault(colorId);
return color ? !!defaultValue : color.equals(defaultValue);
}
public get type() {
switch (this.base) {
case VS_THEME_NAME: return 'light';
case HC_BLACK_THEME_NAME: return 'hc';
default: return 'dark';
}
}
public get tokenTheme(): TokenTheme {
if (!this._tokenTheme) {
this._tokenTheme = TokenTheme.createFromRawTokenTheme(this.rules);
}
return this._tokenTheme;
}
}
function isBuiltinTheme(themeName: string): themeName is BuiltinTheme {
return (
......@@ -32,7 +98,7 @@ function isBuiltinTheme(themeName: string): themeName is BuiltinTheme {
);
}
function getBuiltinRules(builtinTheme: BuiltinTheme): IThemeRule[] {
function getBuiltinRules(builtinTheme: BuiltinTheme): IStandaloneThemeData {
switch (builtinTheme) {
case VS_THEME_NAME:
return vs;
......@@ -43,25 +109,30 @@ function getBuiltinRules(builtinTheme: BuiltinTheme): IThemeRule[] {
}
}
function newBuiltInTheme(builtinTheme: BuiltinTheme): StandaloneTheme {
let themeData = getBuiltinRules(builtinTheme);
return new StandaloneTheme(builtinTheme, '', themeData.colors, themeData.rules);
}
export class StandaloneColorServiceImpl implements IStandaloneColorService {
_serviceBrand: any;
private _knownThemes: Map<string, KnownTheme>;
private _knownThemes: Map<string, StandaloneTheme>;
private _styleElement: HTMLStyleElement;
private _theme: Theme;
private _theme: IStandaloneTheme;
constructor() {
this._knownThemes = new Map<string, KnownTheme>();
this._knownThemes.set(VS_THEME_NAME, new KnownTheme(VS_THEME_NAME, getBuiltinRules(VS_THEME_NAME)));
this._knownThemes.set(VS_DARK_THEME_NAME, new KnownTheme(VS_DARK_THEME_NAME, getBuiltinRules(VS_DARK_THEME_NAME)));
this._knownThemes.set(HC_BLACK_THEME_NAME, new KnownTheme(HC_BLACK_THEME_NAME, getBuiltinRules(HC_BLACK_THEME_NAME)));
this._knownThemes = new Map<string, StandaloneTheme>();
this._knownThemes.set(VS_THEME_NAME, newBuiltInTheme(VS_THEME_NAME));
this._knownThemes.set(VS_DARK_THEME_NAME, newBuiltInTheme(VS_DARK_THEME_NAME));
this._knownThemes.set(HC_BLACK_THEME_NAME, newBuiltInTheme(HC_BLACK_THEME_NAME));
this._styleElement = dom.createStyleSheet();
this._styleElement.className = 'monaco-tokens-styles';
this._styleElement.className = 'monaco-colors';
this.setTheme(VS_THEME_NAME);
}
public defineTheme(themeName: string, themeData: ITheme): void {
public defineTheme(themeName: string, themeData: IStandaloneThemeData): void {
if (!/^[a-z0-9\-]+$/i.test(themeName) || isBuiltinTheme(themeName)) {
throw new Error('Illegal theme name!');
}
......@@ -69,37 +140,56 @@ export class StandaloneColorServiceImpl implements IStandaloneColorService {
throw new Error('Illegal theme base!');
}
let cssClassName = themeData.base + ' ' + themeName;
let rules: IThemeRule[] = [];
let rules: ITokenThemeRule[] = [];
let colors: IColors = {};
if (themeData.inherit) {
rules = rules.concat(getBuiltinRules(themeData.base));
let baseData = getBuiltinRules(themeData.base);
rules = rules.concat(baseData.rules);
for (let id in baseData.colors) {
colors[id] = baseData.colors[id];
}
}
rules = rules.concat(themeData.rules);
for (let id in themeData.colors) {
colors[id] = themeData.colors[id];
}
this._knownThemes.set(themeName, new KnownTheme(cssClassName, rules));
this._knownThemes.set(themeName, new StandaloneTheme(themeData.base, themeName, colors, rules));
}
public getTheme(): Theme {
public getTheme(): IStandaloneTheme {
return this._theme;
}
public setTheme(themeName: string): string {
let themeData: KnownTheme;
let theme: StandaloneTheme;
if (this._knownThemes.has(themeName)) {
themeData = this._knownThemes.get(themeName);
theme = this._knownThemes.get(themeName);
} else {
themeData = this._knownThemes.get(VS_THEME_NAME);
theme = this._knownThemes.get(VS_THEME_NAME);
}
this._theme = Theme.createFromRawTheme(themeData.rules);
let colorMap = this._theme.getColorMap();
let cssRules = generateTokensCSSForColorMap(colorMap);
this._styleElement.innerHTML = cssRules;
this._theme = theme;
let cssRules = [];
let hasRule = {};
let ruleCollector: ICssStyleCollector = {
addRule: (rule: string) => {
if (!hasRule[rule]) {
cssRules.push(rule);
hasRule[rule] = true;
}
}
};
themingRegistry.getThemingParticipants().forEach(p => p(theme, ruleCollector));
let tokenTheme = theme.tokenTheme;
let colorMap = tokenTheme.getColorMap();
ruleCollector.addRule(generateTokensCSSForColorMap(colorMap));
this._styleElement.innerHTML = cssRules.join('\n');
TokenizationRegistry.setColorMap(colorMap);
return themeData.cssClassName;
return theme.id;
}
}
......@@ -31,7 +31,7 @@ import { ICodeEditorService } from 'vs/editor/common/services/codeEditorService'
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
import { ITextModelResolverService } from 'vs/editor/common/services/resolverService';
import { NULL_STATE, nullTokenize } from 'vs/editor/common/modes/nullMode';
import { ITheme, IStandaloneColorService } from 'vs/editor/common/services/standaloneColorService';
import { IStandaloneThemeData, IStandaloneColorService } from 'vs/editor/common/services/standaloneColorService';
import { Token } from 'vs/editor/common/core/token';
import { FontInfo, BareFontInfo } from 'vs/editor/common/config/fontInfo';
......@@ -301,7 +301,7 @@ export function tokenize(text: string, languageId: string): Token[][] {
/**
* Define a new theme.
*/
export function defineTheme(themeName: string, themeData: ITheme): void {
export function defineTheme(themeName: string, themeData: IStandaloneThemeData): void {
StaticServices.standaloneColorService.get().defineTheme(themeName, themeData);
}
......
......@@ -113,12 +113,12 @@ export class TokenizationSupport2Adapter implements modes.ITokenizationSupport {
private _toBinaryTokens(tokens: IToken[], offsetDelta: number): Uint32Array {
let languageId = this._languageIdentifier.id;
let theme = this._standaloneColorService.getTheme();
let tokenTheme = this._standaloneColorService.getTheme().tokenTheme;
let result: number[] = [], resultLen = 0;
for (let i = 0, len = tokens.length; i < len; i++) {
let t = tokens[i];
let metadata = theme.match(languageId, t.scopes);
let metadata = tokenTheme.match(languageId, t.scopes);
if (resultLen > 0 && result[resultLen - 1] === metadata) {
// same metadata
continue;
......
......@@ -16,7 +16,7 @@ import { IModeService } from 'vs/editor/common/services/modeService';
import { Token, TokenizationResult, TokenizationResult2 } from 'vs/editor/common/core/token';
import { NULL_STATE, NULL_MODE_ID } from 'vs/editor/common/modes/nullMode';
import { IStandaloneColorService } from 'vs/editor/common/services/standaloneColorService';
import { Theme } from 'vs/editor/common/modes/supports/tokenization';
import { TokenTheme } from 'vs/editor/common/modes/supports/tokenization';
const CACHE_STACK_DEPTH = 5;
......@@ -291,13 +291,13 @@ class MonarchClassicTokensCollector implements IMonarchTokensCollector {
class MonarchModernTokensCollector implements IMonarchTokensCollector {
private _modeService: IModeService;
private _theme: Theme;
private _theme: TokenTheme;
private _prependTokens: Uint32Array;
private _tokens: number[];
private _currentLanguageId: modes.LanguageId;
private _lastTokenMetadata: number;
constructor(modeService: IModeService, theme: Theme) {
constructor(modeService: IModeService, theme: TokenTheme) {
this._modeService = modeService;
this._theme = theme;
this._prependTokens = null;
......@@ -429,7 +429,7 @@ export class MonarchTokenizer implements modes.ITokenizationSupport {
}
public tokenize2(line: string, lineState: modes.IState, offsetDelta: number): TokenizationResult2 {
let tokensCollector = new MonarchModernTokensCollector(this._modeService, this._standaloneColorService.getTheme());
let tokensCollector = new MonarchModernTokensCollector(this._modeService, this._standaloneColorService.getTheme().tokenTheme);
let endLineState = this._tokenize(line, <MonarchLineState>lineState, offsetDelta, tokensCollector);
return tokensCollector.finalize(endLineState);
}
......
......@@ -7,14 +7,14 @@
import { ColorId, FontStyle, MetadataConsts, LanguageId, StandardTokenType } from 'vs/editor/common/modes';
import { Color } from 'vs/base/common/color';
export interface IThemeRule {
export interface ITokenThemeRule {
token: string;
foreground?: string;
background?: string;
fontStyle?: string;
}
export class ParsedThemeRule {
export class ParsedTokenThemeRule {
_parsedThemeRuleBrand: void;
readonly token: string;
......@@ -45,11 +45,11 @@ export class ParsedThemeRule {
/**
* Parse a raw theme into rules.
*/
export function parseTheme(source: IThemeRule[]): ParsedThemeRule[] {
export function parseTokenTheme(source: ITokenThemeRule[]): ParsedTokenThemeRule[] {
if (!source || !Array.isArray(source)) {
return [];
}
let result: ParsedThemeRule[] = [], resultLen = 0;
let result: ParsedTokenThemeRule[] = [], resultLen = 0;
for (let i = 0, len = source.length; i < len; i++) {
let entry = source[i];
......@@ -84,7 +84,7 @@ export function parseTheme(source: IThemeRule[]): ParsedThemeRule[] {
background = entry.background;
}
result[resultLen++] = new ParsedThemeRule(
result[resultLen++] = new ParsedTokenThemeRule(
entry.token || '',
i,
fontStyle,
......@@ -99,7 +99,7 @@ export function parseTheme(source: IThemeRule[]): ParsedThemeRule[] {
/**
* Resolve rules (i.e. inheritance).
*/
function resolveParsedThemeRules(parsedThemeRules: ParsedThemeRule[]): Theme {
function resolveParsedTokenThemeRules(parsedThemeRules: ParsedTokenThemeRule[]): TokenTheme {
// Sort rules lexicographically, and then by index if necessary
parsedThemeRules.sort((a, b) => {
......@@ -136,7 +136,7 @@ function resolveParsedThemeRules(parsedThemeRules: ParsedThemeRule[]): Theme {
root.insert(rule.token, rule.fontStyle, colorMap.getId(rule.foreground), colorMap.getId(rule.background));
}
return new Theme(colorMap, root);
return new TokenTheme(colorMap, root);
}
export class ColorMap {
......@@ -175,14 +175,14 @@ export class ColorMap {
}
export class Theme {
export class TokenTheme {
public static createFromRawTheme(source: IThemeRule[]): Theme {
return this.createFromParsedTheme(parseTheme(source));
public static createFromRawTokenTheme(source: ITokenThemeRule[]): TokenTheme {
return this.createFromParsedTokenTheme(parseTokenTheme(source));
}
public static createFromParsedTheme(source: ParsedThemeRule[]): Theme {
return resolveParsedThemeRules(source);
public static createFromParsedTokenTheme(source: ParsedTokenThemeRule[]): TokenTheme {
return resolveParsedTokenThemeRules(source);
}
private readonly _colorMap: ColorMap;
......
......@@ -5,16 +5,23 @@
'use strict';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { Theme, IThemeRule } from 'vs/editor/common/modes/supports/tokenization';
import { TokenTheme, ITokenThemeRule } from 'vs/editor/common/modes/supports/tokenization';
import { ITheme } from "vs/platform/theme/common/themeService";
export var IStandaloneColorService = createDecorator<IStandaloneColorService>('standaloneColorService');
export type BuiltinTheme = 'vs' | 'vs-dark' | 'hc-black';
export type IColors = { [colorId: string]: string; };
export interface ITheme {
export interface IStandaloneThemeData {
base: BuiltinTheme;
inherit: boolean;
rules: IThemeRule[];
rules: ITokenThemeRule[];
colors: IColors;
}
export interface IStandaloneTheme extends ITheme {
tokenTheme: TokenTheme;
}
export interface IStandaloneColorService {
......@@ -22,7 +29,7 @@ export interface IStandaloneColorService {
setTheme(themeName: string): string;
defineTheme(themeName: string, themeData: ITheme): void;
defineTheme(themeName: string, themeData: IStandaloneThemeData): void;
getTheme(): Theme;
getTheme(): IStandaloneTheme;
}
......@@ -5,175 +5,204 @@
'use strict';
import { IThemeRule } from 'vs/editor/common/modes/supports/tokenization';
/* -------------------------------- Begin vs tokens -------------------------------- */
export const vs: IThemeRule[] = [
{ token: '', foreground: '000000', background: 'fffffe' },
{ token: 'invalid', foreground: 'cd3131' },
{ token: 'emphasis', fontStyle: 'italic' },
{ token: 'strong', fontStyle: 'bold' },
{ token: 'variable', foreground: '001188' },
{ token: 'variable.predefined', foreground: '4864AA' },
{ token: 'constant', foreground: 'dd0000' },
{ token: 'comment', foreground: '008000' },
{ token: 'number', foreground: '09885A' },
{ token: 'number.hex', foreground: '3030c0' },
{ token: 'regexp', foreground: '800000' },
{ token: 'annotation', foreground: '808080' },
{ token: 'type', foreground: '008080' },
{ token: 'delimiter', foreground: '000000' },
{ token: 'delimiter.html', foreground: '383838' },
{ token: 'delimiter.xml', foreground: '0000FF' },
{ token: 'tag', foreground: '800000' },
{ token: 'tag.id.jade', foreground: '4F76AC' },
{ token: 'tag.class.jade', foreground: '4F76AC' },
{ token: 'meta.scss', foreground: '800000' },
{ token: 'metatag', foreground: 'e00000' },
{ token: 'metatag.content.html', foreground: 'FF0000' },
{ token: 'metatag.html', foreground: '808080' },
{ token: 'metatag.xml', foreground: '808080' },
{ token: 'metatag.php', fontStyle: 'bold' },
{ token: 'key', foreground: '863B00' },
{ token: 'string.key.json', foreground: 'A31515' },
{ token: 'string.value.json', foreground: '0451A5' },
{ token: 'attribute.name', foreground: 'FF0000' },
{ token: 'attribute.value', foreground: '0451A5' },
{ token: 'attribute.value.number', foreground: '09885A' },
{ token: 'attribute.value.unit', foreground: '09885A' },
{ token: 'attribute.value.html', foreground: '0000FF' },
{ token: 'attribute.value.xml', foreground: '0000FF' },
{ token: 'string', foreground: 'A31515' },
{ token: 'string.html', foreground: '0000FF' },
{ token: 'string.sql', foreground: 'FF0000' },
{ token: 'string.yaml', foreground: '0451A5' },
{ token: 'keyword', foreground: '0000FF' },
{ token: 'keyword.json', foreground: '0451A5' },
{ token: 'keyword.flow', foreground: 'AF00DB' },
{ token: 'keyword.flow.scss', foreground: '0000FF' },
{ token: 'operator.scss', foreground: '666666' },
{ token: 'operator.sql', foreground: '778899' },
{ token: 'operator.swift', foreground: '666666' },
{ token: 'predefined.sql', foreground: 'FF00FF' },
];
/* -------------------------------- End vs tokens -------------------------------- */
/* -------------------------------- Begin vs-dark tokens -------------------------------- */
export const vs_dark: IThemeRule[] = [
{ token: '', foreground: 'D4D4D4', background: '1E1E1E' },
{ token: 'invalid', foreground: 'f44747' },
{ token: 'emphasis', fontStyle: 'italic' },
{ token: 'strong', fontStyle: 'bold' },
{ token: 'variable', foreground: '74B0DF' },
{ token: 'variable.predefined', foreground: '4864AA' },
{ token: 'variable.parameter', foreground: '9CDCFE' },
{ token: 'constant', foreground: '569CD6' },
{ token: 'comment', foreground: '608B4E' },
{ token: 'number', foreground: 'B5CEA8' },
{ token: 'number.hex', foreground: '5BB498' },
{ token: 'regexp', foreground: 'B46695' },
{ token: 'annotation', foreground: 'cc6666' },
{ token: 'type', foreground: '3DC9B0' },
{ token: 'delimiter', foreground: 'DCDCDC' },
{ token: 'delimiter.html', foreground: '808080' },
{ token: 'delimiter.xml', foreground: '808080' },
{ token: 'tag', foreground: '569CD6' },
{ token: 'tag.id.jade', foreground: '4F76AC' },
{ token: 'tag.class.jade', foreground: '4F76AC' },
{ token: 'meta.scss', foreground: 'A79873' },
{ token: 'meta.tag', foreground: 'CE9178' },
{ token: 'metatag', foreground: 'DD6A6F' },
{ token: 'metatag.content.html', foreground: '9CDCFE' },
{ token: 'metatag.html', foreground: '569CD6' },
{ token: 'metatag.xml', foreground: '569CD6' },
{ token: 'metatag.php', fontStyle: 'bold' },
{ token: 'key', foreground: '9CDCFE' },
{ token: 'string.key.json', foreground: '9CDCFE' },
{ token: 'string.value.json', foreground: 'CE9178' },
{ token: 'attribute.name', foreground: '9CDCFE' },
{ token: 'attribute.value', foreground: 'CE9178' },
{ token: 'attribute.value.number.css', foreground: 'B5CEA8' },
{ token: 'attribute.value.unit.css', foreground: 'B5CEA8' },
{ token: 'attribute.value.hex.css', foreground: 'D4D4D4' },
{ token: 'string', foreground: 'CE9178' },
{ token: 'string.sql', foreground: 'FF0000' },
{ token: 'keyword', foreground: '569CD6' },
{ token: 'keyword.flow', foreground: 'C586C0' },
{ token: 'keyword.json', foreground: 'CE9178' },
{ token: 'keyword.flow.scss', foreground: '569CD6' },
{ token: 'operator.scss', foreground: '909090' },
{ token: 'operator.sql', foreground: '778899' },
{ token: 'operator.swift', foreground: '909090' },
{ token: 'predefined.sql', foreground: 'FF00FF' },
];
/* -------------------------------- End vs-dark tokens -------------------------------- */
/* -------------------------------- Begin hc-black tokens -------------------------------- */
export const hc_black: IThemeRule[] = [
{ token: '', foreground: 'FFFFFF', background: '000000' },
{ token: 'invalid', foreground: 'f44747' },
{ token: 'emphasis', fontStyle: 'italic' },
{ token: 'strong', fontStyle: 'bold' },
{ token: 'variable', foreground: '1AEBFF' },
{ token: 'variable.parameter', foreground: '9CDCFE' },
{ token: 'constant', foreground: '569CD6' },
{ token: 'comment', foreground: '608B4E' },
{ token: 'number', foreground: 'FFFFFF' },
{ token: 'regexp', foreground: 'C0C0C0' },
{ token: 'annotation', foreground: '569CD6' },
{ token: 'type', foreground: '3DC9B0' },
{ token: 'delimiter', foreground: 'FFFF00' },
{ token: 'delimiter.html', foreground: 'FFFF00' },
{ token: 'tag', foreground: '569CD6' },
{ token: 'tag.id.jade', foreground: '4F76AC' },
{ token: 'tag.class.jade', foreground: '4F76AC' },
{ token: 'meta', foreground: 'D4D4D4' },
{ token: 'meta.tag', foreground: 'CE9178' },
{ token: 'metatag', foreground: '569CD6' },
{ token: 'metatag.content.html', foreground: '1AEBFF' },
{ token: 'metatag.html', foreground: '569CD6' },
{ token: 'metatag.xml', foreground: '569CD6' },
{ token: 'metatag.php', fontStyle: 'bold' },
{ token: 'key', foreground: '9CDCFE' },
{ token: 'string.key', foreground: '9CDCFE' },
{ token: 'string.value', foreground: 'CE9178' },
{ token: 'attribute.name', foreground: '569CD6' },
{ token: 'attribute.value', foreground: '3FF23F' },
{ token: 'string', foreground: 'CE9178' },
{ token: 'string.sql', foreground: 'FF0000' },
{ token: 'keyword', foreground: '569CD6' },
{ token: 'keyword.flow', foreground: 'C586C0' },
{ token: 'operator.sql', foreground: '778899' },
{ token: 'operator.swift', foreground: '909090' },
{ token: 'predefined.sql', foreground: 'FF00FF' },
];
/* -------------------------------- End hc-black tokens -------------------------------- */
import { IStandaloneThemeData } from "vs/editor/common/services/standaloneColorService";
/* -------------------------------- Begin vs theme -------------------------------- */
export const vs: IStandaloneThemeData = {
base: 'vs',
inherit: false,
rules: [
{ token: '', foreground: '000000', background: 'fffffe' },
{ token: 'invalid', foreground: 'cd3131' },
{ token: 'emphasis', fontStyle: 'italic' },
{ token: 'strong', fontStyle: 'bold' },
{ token: 'variable', foreground: '001188' },
{ token: 'variable.predefined', foreground: '4864AA' },
{ token: 'constant', foreground: 'dd0000' },
{ token: 'comment', foreground: '008000' },
{ token: 'number', foreground: '09885A' },
{ token: 'number.hex', foreground: '3030c0' },
{ token: 'regexp', foreground: '800000' },
{ token: 'annotation', foreground: '808080' },
{ token: 'type', foreground: '008080' },
{ token: 'delimiter', foreground: '000000' },
{ token: 'delimiter.html', foreground: '383838' },
{ token: 'delimiter.xml', foreground: '0000FF' },
{ token: 'tag', foreground: '800000' },
{ token: 'tag.id.jade', foreground: '4F76AC' },
{ token: 'tag.class.jade', foreground: '4F76AC' },
{ token: 'meta.scss', foreground: '800000' },
{ token: 'metatag', foreground: 'e00000' },
{ token: 'metatag.content.html', foreground: 'FF0000' },
{ token: 'metatag.html', foreground: '808080' },
{ token: 'metatag.xml', foreground: '808080' },
{ token: 'metatag.php', fontStyle: 'bold' },
{ token: 'key', foreground: '863B00' },
{ token: 'string.key.json', foreground: 'A31515' },
{ token: 'string.value.json', foreground: '0451A5' },
{ token: 'attribute.name', foreground: 'FF0000' },
{ token: 'attribute.value', foreground: '0451A5' },
{ token: 'attribute.value.number', foreground: '09885A' },
{ token: 'attribute.value.unit', foreground: '09885A' },
{ token: 'attribute.value.html', foreground: '0000FF' },
{ token: 'attribute.value.xml', foreground: '0000FF' },
{ token: 'string', foreground: 'A31515' },
{ token: 'string.html', foreground: '0000FF' },
{ token: 'string.sql', foreground: 'FF0000' },
{ token: 'string.yaml', foreground: '0451A5' },
{ token: 'keyword', foreground: '0000FF' },
{ token: 'keyword.json', foreground: '0451A5' },
{ token: 'keyword.flow', foreground: 'AF00DB' },
{ token: 'keyword.flow.scss', foreground: '0000FF' },
{ token: 'operator.scss', foreground: '666666' },
{ token: 'operator.sql', foreground: '778899' },
{ token: 'operator.swift', foreground: '666666' },
{ token: 'predefined.sql', foreground: 'FF00FF' },
],
colors: {
editorBackground: '#FFFFFF',
editorForeground: '#000000',
editorInactiveSelection: '#E5EBF1',
editorGuide: '#D3D3D3',
editorSelectionHighlightColor: '#ADD6FF4D'
}
};
/* -------------------------------- End vs theme -------------------------------- */
/* -------------------------------- Begin vs-dark theme -------------------------------- */
export const vs_dark: IStandaloneThemeData = {
base: 'vs-dark',
inherit: false,
rules: [
{ token: '', foreground: 'D4D4D4', background: '1E1E1E' },
{ token: 'invalid', foreground: 'f44747' },
{ token: 'emphasis', fontStyle: 'italic' },
{ token: 'strong', fontStyle: 'bold' },
{ token: 'variable', foreground: '74B0DF' },
{ token: 'variable.predefined', foreground: '4864AA' },
{ token: 'variable.parameter', foreground: '9CDCFE' },
{ token: 'constant', foreground: '569CD6' },
{ token: 'comment', foreground: '608B4E' },
{ token: 'number', foreground: 'B5CEA8' },
{ token: 'number.hex', foreground: '5BB498' },
{ token: 'regexp', foreground: 'B46695' },
{ token: 'annotation', foreground: 'cc6666' },
{ token: 'type', foreground: '3DC9B0' },
{ token: 'delimiter', foreground: 'DCDCDC' },
{ token: 'delimiter.html', foreground: '808080' },
{ token: 'delimiter.xml', foreground: '808080' },
{ token: 'tag', foreground: '569CD6' },
{ token: 'tag.id.jade', foreground: '4F76AC' },
{ token: 'tag.class.jade', foreground: '4F76AC' },
{ token: 'meta.scss', foreground: 'A79873' },
{ token: 'meta.tag', foreground: 'CE9178' },
{ token: 'metatag', foreground: 'DD6A6F' },
{ token: 'metatag.content.html', foreground: '9CDCFE' },
{ token: 'metatag.html', foreground: '569CD6' },
{ token: 'metatag.xml', foreground: '569CD6' },
{ token: 'metatag.php', fontStyle: 'bold' },
{ token: 'key', foreground: '9CDCFE' },
{ token: 'string.key.json', foreground: '9CDCFE' },
{ token: 'string.value.json', foreground: 'CE9178' },
{ token: 'attribute.name', foreground: '9CDCFE' },
{ token: 'attribute.value', foreground: 'CE9178' },
{ token: 'attribute.value.number.css', foreground: 'B5CEA8' },
{ token: 'attribute.value.unit.css', foreground: 'B5CEA8' },
{ token: 'attribute.value.hex.css', foreground: 'D4D4D4' },
{ token: 'string', foreground: 'CE9178' },
{ token: 'string.sql', foreground: 'FF0000' },
{ token: 'keyword', foreground: '569CD6' },
{ token: 'keyword.flow', foreground: 'C586C0' },
{ token: 'keyword.json', foreground: 'CE9178' },
{ token: 'keyword.flow.scss', foreground: '569CD6' },
{ token: 'operator.scss', foreground: '909090' },
{ token: 'operator.sql', foreground: '778899' },
{ token: 'operator.swift', foreground: '909090' },
{ token: 'predefined.sql', foreground: 'FF00FF' },
],
colors: {
editorBackground: '#1E1E1E',
editorForeground: '#D4D4D4',
editorInactiveSelection: '#3A3D41',
editorGuide: '#404040',
editorSelectionHighlightColor: '#ADD6FF26'
}
};
/* -------------------------------- End vs-dark theme -------------------------------- */
/* -------------------------------- Begin hc-black theme -------------------------------- */
export const hc_black: IStandaloneThemeData = {
base: 'hc-black',
inherit: false,
rules: [
{ token: '', foreground: 'FFFFFF', background: '000000' },
{ token: 'invalid', foreground: 'f44747' },
{ token: 'emphasis', fontStyle: 'italic' },
{ token: 'strong', fontStyle: 'bold' },
{ token: 'variable', foreground: '1AEBFF' },
{ token: 'variable.parameter', foreground: '9CDCFE' },
{ token: 'constant', foreground: '569CD6' },
{ token: 'comment', foreground: '608B4E' },
{ token: 'number', foreground: 'FFFFFF' },
{ token: 'regexp', foreground: 'C0C0C0' },
{ token: 'annotation', foreground: '569CD6' },
{ token: 'type', foreground: '3DC9B0' },
{ token: 'delimiter', foreground: 'FFFF00' },
{ token: 'delimiter.html', foreground: 'FFFF00' },
{ token: 'tag', foreground: '569CD6' },
{ token: 'tag.id.jade', foreground: '4F76AC' },
{ token: 'tag.class.jade', foreground: '4F76AC' },
{ token: 'meta', foreground: 'D4D4D4' },
{ token: 'meta.tag', foreground: 'CE9178' },
{ token: 'metatag', foreground: '569CD6' },
{ token: 'metatag.content.html', foreground: '1AEBFF' },
{ token: 'metatag.html', foreground: '569CD6' },
{ token: 'metatag.xml', foreground: '569CD6' },
{ token: 'metatag.php', fontStyle: 'bold' },
{ token: 'key', foreground: '9CDCFE' },
{ token: 'string.key', foreground: '9CDCFE' },
{ token: 'string.value', foreground: 'CE9178' },
{ token: 'attribute.name', foreground: '569CD6' },
{ token: 'attribute.value', foreground: '3FF23F' },
{ token: 'string', foreground: 'CE9178' },
{ token: 'string.sql', foreground: 'FF0000' },
{ token: 'keyword', foreground: '569CD6' },
{ token: 'keyword.flow', foreground: 'C586C0' },
{ token: 'operator.sql', foreground: '778899' },
{ token: 'operator.swift', foreground: '909090' },
{ token: 'predefined.sql', foreground: 'FF00FF' },
],
colors: {
editorBackground: '#000000',
editorForeground: '#FFFFFF',
editorGuide: '#FFFFFF',
}
};
/* -------------------------------- End hc-black theme -------------------------------- */
......@@ -5,13 +5,13 @@
'use strict';
import * as assert from 'assert';
import { strcmp, parseTheme, Theme, ParsedThemeRule, ColorMap, ExternalThemeTrieElement, ThemeTrieElementRule } from 'vs/editor/common/modes/supports/tokenization';
import { strcmp, parseTokenTheme, TokenTheme, ParsedTokenThemeRule, ColorMap, ExternalThemeTrieElement, ThemeTrieElementRule } from 'vs/editor/common/modes/supports/tokenization';
import { FontStyle } from 'vs/editor/common/modes';
suite('Theme matching', () => {
suite('Token theme matching', () => {
test('gives higher priority to deeper matches', () => {
let theme = Theme.createFromRawTheme([
let theme = TokenTheme.createFromRawTokenTheme([
{ token: '', foreground: '100000', background: '200000' },
{ token: 'punctuation.definition.string.begin.html', foreground: '300000' },
{ token: 'punctuation.definition.string', foreground: '400000' },
......@@ -29,7 +29,7 @@ suite('Theme matching', () => {
});
test('can match', () => {
let theme = Theme.createFromRawTheme([
let theme = TokenTheme.createFromRawTokenTheme([
{ token: '', foreground: 'F8F8F2', background: '272822' },
{ token: 'source', background: '100000' },
{ token: 'something', background: '100000' },
......@@ -121,11 +121,11 @@ suite('Theme matching', () => {
});
});
suite('Theme parsing', () => {
suite('Token theme parsing', () => {
test('can parse', () => {
let actual = parseTheme([
let actual = parseTokenTheme([
{ token: '', foreground: 'F8F8F2', background: '272822' },
{ token: 'source', background: '100000' },
{ token: 'something', background: '100000' },
......@@ -140,24 +140,24 @@ suite('Theme parsing', () => {
]);
let expected = [
new ParsedThemeRule('', 0, FontStyle.NotSet, 'F8F8F2', '272822'),
new ParsedThemeRule('source', 1, FontStyle.NotSet, null, '100000'),
new ParsedThemeRule('something', 2, FontStyle.NotSet, null, '100000'),
new ParsedThemeRule('bar', 3, FontStyle.NotSet, null, '010000'),
new ParsedThemeRule('baz', 4, FontStyle.NotSet, null, '010000'),
new ParsedThemeRule('bar', 5, FontStyle.Bold, null, null),
new ParsedThemeRule('constant', 6, FontStyle.Italic, 'ff0000', null),
new ParsedThemeRule('constant.numeric', 7, FontStyle.NotSet, '00ff00', null),
new ParsedThemeRule('constant.numeric.hex', 8, FontStyle.Bold, null, null),
new ParsedThemeRule('constant.numeric.oct', 9, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, null, null),
new ParsedThemeRule('constant.numeric.dec', 10, FontStyle.None, '0000ff', null),
new ParsedTokenThemeRule('', 0, FontStyle.NotSet, 'F8F8F2', '272822'),
new ParsedTokenThemeRule('source', 1, FontStyle.NotSet, null, '100000'),
new ParsedTokenThemeRule('something', 2, FontStyle.NotSet, null, '100000'),
new ParsedTokenThemeRule('bar', 3, FontStyle.NotSet, null, '010000'),
new ParsedTokenThemeRule('baz', 4, FontStyle.NotSet, null, '010000'),
new ParsedTokenThemeRule('bar', 5, FontStyle.Bold, null, null),
new ParsedTokenThemeRule('constant', 6, FontStyle.Italic, 'ff0000', null),
new ParsedTokenThemeRule('constant.numeric', 7, FontStyle.NotSet, '00ff00', null),
new ParsedTokenThemeRule('constant.numeric.hex', 8, FontStyle.Bold, null, null),
new ParsedTokenThemeRule('constant.numeric.oct', 9, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, null, null),
new ParsedTokenThemeRule('constant.numeric.dec', 10, FontStyle.None, '0000ff', null),
];
assert.deepEqual(actual, expected);
});
});
suite('Theme resolving', () => {
suite('Token theme resolving', () => {
test('strcmp works', () => {
let actual = ['bar', 'z', 'zu', 'a', 'ab', ''].sort(strcmp);
......@@ -167,7 +167,7 @@ suite('Theme resolving', () => {
});
test('always has defaults', () => {
let actual = Theme.createFromParsedTheme([]);
let actual = TokenTheme.createFromParsedTokenTheme([]);
let colorMap = new ColorMap();
const _A = colorMap.getId('000000');
const _B = colorMap.getId('ffffff');
......@@ -176,8 +176,8 @@ suite('Theme resolving', () => {
});
test('respects incoming defaults 1', () => {
let actual = Theme.createFromParsedTheme([
new ParsedThemeRule('', -1, FontStyle.NotSet, null, null)
let actual = TokenTheme.createFromParsedTokenTheme([
new ParsedTokenThemeRule('', -1, FontStyle.NotSet, null, null)
]);
let colorMap = new ColorMap();
const _A = colorMap.getId('000000');
......@@ -187,8 +187,8 @@ suite('Theme resolving', () => {
});
test('respects incoming defaults 2', () => {
let actual = Theme.createFromParsedTheme([
new ParsedThemeRule('', -1, FontStyle.None, null, null)
let actual = TokenTheme.createFromParsedTokenTheme([
new ParsedTokenThemeRule('', -1, FontStyle.None, null, null)
]);
let colorMap = new ColorMap();
const _A = colorMap.getId('000000');
......@@ -198,8 +198,8 @@ suite('Theme resolving', () => {
});
test('respects incoming defaults 3', () => {
let actual = Theme.createFromParsedTheme([
new ParsedThemeRule('', -1, FontStyle.Bold, null, null)
let actual = TokenTheme.createFromParsedTokenTheme([
new ParsedTokenThemeRule('', -1, FontStyle.Bold, null, null)
]);
let colorMap = new ColorMap();
const _A = colorMap.getId('000000');
......@@ -209,8 +209,8 @@ suite('Theme resolving', () => {
});
test('respects incoming defaults 4', () => {
let actual = Theme.createFromParsedTheme([
new ParsedThemeRule('', -1, FontStyle.NotSet, 'ff0000', null)
let actual = TokenTheme.createFromParsedTokenTheme([
new ParsedTokenThemeRule('', -1, FontStyle.NotSet, 'ff0000', null)
]);
let colorMap = new ColorMap();
const _A = colorMap.getId('ff0000');
......@@ -220,8 +220,8 @@ suite('Theme resolving', () => {
});
test('respects incoming defaults 5', () => {
let actual = Theme.createFromParsedTheme([
new ParsedThemeRule('', -1, FontStyle.NotSet, null, 'ff0000')
let actual = TokenTheme.createFromParsedTokenTheme([
new ParsedTokenThemeRule('', -1, FontStyle.NotSet, null, 'ff0000')
]);
let colorMap = new ColorMap();
const _A = colorMap.getId('000000');
......@@ -231,10 +231,10 @@ suite('Theme resolving', () => {
});
test('can merge incoming defaults', () => {
let actual = Theme.createFromParsedTheme([
new ParsedThemeRule('', -1, FontStyle.NotSet, null, 'ff0000'),
new ParsedThemeRule('', -1, FontStyle.NotSet, '00ff00', null),
new ParsedThemeRule('', -1, FontStyle.Bold, null, null),
let actual = TokenTheme.createFromParsedTokenTheme([
new ParsedTokenThemeRule('', -1, FontStyle.NotSet, null, 'ff0000'),
new ParsedTokenThemeRule('', -1, FontStyle.NotSet, '00ff00', null),
new ParsedTokenThemeRule('', -1, FontStyle.Bold, null, null),
]);
let colorMap = new ColorMap();
const _A = colorMap.getId('00ff00');
......@@ -244,9 +244,9 @@ suite('Theme resolving', () => {
});
test('defaults are inherited', () => {
let actual = Theme.createFromParsedTheme([
new ParsedThemeRule('', -1, FontStyle.NotSet, 'F8F8F2', '272822'),
new ParsedThemeRule('var', -1, FontStyle.NotSet, 'ff0000', null)
let actual = TokenTheme.createFromParsedTokenTheme([
new ParsedTokenThemeRule('', -1, FontStyle.NotSet, 'F8F8F2', '272822'),
new ParsedTokenThemeRule('var', -1, FontStyle.NotSet, 'ff0000', null)
]);
let colorMap = new ColorMap();
const _A = colorMap.getId('F8F8F2');
......@@ -260,10 +260,10 @@ suite('Theme resolving', () => {
});
test('same rules get merged', () => {
let actual = Theme.createFromParsedTheme([
new ParsedThemeRule('', -1, FontStyle.NotSet, 'F8F8F2', '272822'),
new ParsedThemeRule('var', 1, FontStyle.Bold, null, null),
new ParsedThemeRule('var', 0, FontStyle.NotSet, 'ff0000', null),
let actual = TokenTheme.createFromParsedTokenTheme([
new ParsedTokenThemeRule('', -1, FontStyle.NotSet, 'F8F8F2', '272822'),
new ParsedTokenThemeRule('var', 1, FontStyle.Bold, null, null),
new ParsedTokenThemeRule('var', 0, FontStyle.NotSet, 'ff0000', null),
]);
let colorMap = new ColorMap();
const _A = colorMap.getId('F8F8F2');
......@@ -277,10 +277,10 @@ suite('Theme resolving', () => {
});
test('rules are inherited 1', () => {
let actual = Theme.createFromParsedTheme([
new ParsedThemeRule('', -1, FontStyle.NotSet, 'F8F8F2', '272822'),
new ParsedThemeRule('var', -1, FontStyle.Bold, 'ff0000', null),
new ParsedThemeRule('var.identifier', -1, FontStyle.NotSet, '00ff00', null),
let actual = TokenTheme.createFromParsedTokenTheme([
new ParsedTokenThemeRule('', -1, FontStyle.NotSet, 'F8F8F2', '272822'),
new ParsedTokenThemeRule('var', -1, FontStyle.Bold, 'ff0000', null),
new ParsedTokenThemeRule('var.identifier', -1, FontStyle.NotSet, '00ff00', null),
]);
let colorMap = new ColorMap();
const _A = colorMap.getId('F8F8F2');
......@@ -297,15 +297,15 @@ suite('Theme resolving', () => {
});
test('rules are inherited 2', () => {
let actual = Theme.createFromParsedTheme([
new ParsedThemeRule('', -1, FontStyle.NotSet, 'F8F8F2', '272822'),
new ParsedThemeRule('var', -1, FontStyle.Bold, 'ff0000', null),
new ParsedThemeRule('var.identifier', -1, FontStyle.NotSet, '00ff00', null),
new ParsedThemeRule('constant', 4, FontStyle.Italic, '100000', null),
new ParsedThemeRule('constant.numeric', 5, FontStyle.NotSet, '200000', null),
new ParsedThemeRule('constant.numeric.hex', 6, FontStyle.Bold, null, null),
new ParsedThemeRule('constant.numeric.oct', 7, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, null, null),
new ParsedThemeRule('constant.numeric.dec', 8, FontStyle.None, '300000', null),
let actual = TokenTheme.createFromParsedTokenTheme([
new ParsedTokenThemeRule('', -1, FontStyle.NotSet, 'F8F8F2', '272822'),
new ParsedTokenThemeRule('var', -1, FontStyle.Bold, 'ff0000', null),
new ParsedTokenThemeRule('var.identifier', -1, FontStyle.NotSet, '00ff00', null),
new ParsedTokenThemeRule('constant', 4, FontStyle.Italic, '100000', null),
new ParsedTokenThemeRule('constant.numeric', 5, FontStyle.NotSet, '200000', null),
new ParsedTokenThemeRule('constant.numeric.hex', 6, FontStyle.Bold, null, null),
new ParsedTokenThemeRule('constant.numeric.oct', 7, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, null, null),
new ParsedTokenThemeRule('constant.numeric.dec', 8, FontStyle.None, '300000', null),
]);
let colorMap = new ColorMap();
const _A = colorMap.getId('F8F8F2');
......
......@@ -875,17 +875,22 @@ declare module monaco.editor {
/**
* Define a new theme.
*/
export function defineTheme(themeName: string, themeData: ITheme): void;
export function defineTheme(themeName: string, themeData: IStandaloneThemeData): void;
export type BuiltinTheme = 'vs' | 'vs-dark' | 'hc-black';
export interface ITheme {
export interface IStandaloneThemeData {
base: BuiltinTheme;
inherit: boolean;
rules: IThemeRule[];
rules: ITokenThemeRule[];
colors: IColors;
}
export interface IThemeRule {
export type IColors = {
[colorId: string]: string;
};
export interface ITokenThemeRule {
token: string;
foreground?: string;
background?: string;
......
......@@ -19,7 +19,6 @@ export type ThemeType = 'light' | 'dark' | 'hc';
export interface ITheme {
readonly selector: string;
readonly label: string;
readonly type: ThemeType;
/**
......
......@@ -984,7 +984,6 @@ export class TestWindowsService implements IWindowsService {
export class TestTheme implements ITheme {
selector: string;
label: string;
type: 'light' | 'dark' | 'hc';
getColor(color: string, useDefault?: boolean): Color {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册