Add cursor style, get multiple global settings working

This commit is contained in:
Daniel Imms
2016-11-04 17:55:07 -07:00
parent 18a0e9d164
commit 06753a756c
2 changed files with 36 additions and 22 deletions
+6
View File
@@ -16,7 +16,13 @@ export interface IColorSet {
type?: string; type?: string;
} }
ui?: { ui?: {
/** The default background color */
background?: string; background?: string;
/** The default foreground color */
foreground?: string; foreground?: string;
/** The color of the editor cursor/caret */
cursor?: string;
selectionHighlight?: string;
} }
} }
+30 -22
View File
@@ -10,14 +10,6 @@ export interface IVscodeJsonTheme {
settings?: IVscodeJsonThemeSetting[]; settings?: IVscodeJsonThemeSetting[];
} }
export interface IVscodeJsonGlobalSetting {
name: string;
settings: {
background?: string
foreground?: string
};
}
export interface IVscodeJsonThemeSetting { export interface IVscodeJsonThemeSetting {
name: string; name: string;
scope: string; scope: string;
@@ -44,12 +36,12 @@ enum FontStyle {
function getGlobalSettingGenerator(name: string): ColorGenerator { function getGlobalSettingGenerator(name: string): ColorGenerator {
return (color: string) => { return (color: string) => {
let globalSetting: IVscodeJsonGlobalSetting = { if (!color) {
'name': name, return undefined;
'settings': {} }
}; const result: any = {};
(<any>globalSetting.settings)[name] = color; result[name] = color;
return globalSetting; return result
}; };
} }
@@ -79,15 +71,18 @@ function getSimpleColorGenerator(name: string, scope: string, fontStyle: number
} }
} }
// An ordered list of rules to be applied if the source conditions are met const vscodeJsonGlobalThemeRules: IRuleGenerator[] = [
const vscodeJsonThemeRules: IRuleGenerator[] = [
// Global settings // Global settings
{ source: set => set.ui.background, { source: set => set.ui.background,
generate: getGlobalSettingGenerator('background') }, generate: getGlobalSettingGenerator('background') },
{ source: set => set.ui.foreground, { source: set => set.ui.foreground,
generate: getGlobalSettingGenerator('foreground') }, generate: getGlobalSettingGenerator('foreground') },
{ source: set => set.ui.cursor,
generate: getGlobalSettingGenerator('caret') }
];
// Syntax // An ordered list of rules to be applied if the source conditions are met
const vscodeJsonThemeRules: IRuleGenerator[] = [
// string: It's important that string is put first so that other scopes can override strings // string: It's important that string is put first so that other scopes can override strings
// within template expressions // within template expressions
{ source: set => set.syntax.string, { source: set => set.syntax.string,
@@ -122,15 +117,28 @@ const vscodeJsonThemeRules: IRuleGenerator[] = [
export class VscodeThemeGenerator implements IThemeGenerator { export class VscodeThemeGenerator implements IThemeGenerator {
public generateTheme(name: string, colorSet: IColorSet): string { public generateTheme(name: string, colorSet: IColorSet): string {
let theme: IVscodeJsonTheme = {}; const theme: IVscodeJsonTheme = {};
theme.name = name; theme.name = name;
theme.settings = []; theme.settings = [];
//{"name":"background","settings":{"background":"#151515","caret":"#0000FF"}}
const globalSetting: any = {
name: 'Global settings',
settings: {}
};
vscodeJsonGlobalThemeRules.forEach(ruleGenerator => {
const color = <string>ruleGenerator.source(colorSet);
if (color) {
const generated = ruleGenerator.generate(color);
globalSetting.settings[Object.keys(generated)[0]] = color;
}
});
theme.settings.push(globalSetting);
vscodeJsonThemeRules.forEach(ruleGenerator => { vscodeJsonThemeRules.forEach(ruleGenerator => {
try { const color = <string>ruleGenerator.source(colorSet);
let color = <string>ruleGenerator.source(colorSet); if (color) {
theme.settings.push(ruleGenerator.generate(color)); theme.settings.push(ruleGenerator.generate(color));
} catch (ex) {
// Ignore when source color does not exist
} }
}); });
return JSON.stringify(theme); return JSON.stringify(theme);