diff options
-rw-r--r-- | src/console/actions/console.ts | 1 | ||||
-rw-r--r-- | src/shared/settings/Properties.ts | 24 | ||||
-rw-r--r-- | src/shared/settings/Settings.ts | 3 | ||||
-rw-r--r-- | src/shared/settings/schema.json | 4 | ||||
-rw-r--r-- | src/shared/settings/validate.js | 45 |
5 files changed, 75 insertions, 2 deletions
diff --git a/src/console/actions/console.ts b/src/console/actions/console.ts index 80ea6b0..6282791 100644 --- a/src/console/actions/console.ts +++ b/src/console/actions/console.ts @@ -26,6 +26,7 @@ const propertyDocs: { [key: string]: string } = { hintchars: "hint characters on follow mode", smoothscroll: "smooth scroll", complete: "which are completed at the open page", + colorscheme: "color scheme of the console", }; const hide = (): actions.ConsoleAction => { diff --git a/src/shared/settings/Properties.ts b/src/shared/settings/Properties.ts index cf10d61..38f1d3b 100644 --- a/src/shared/settings/Properties.ts +++ b/src/shared/settings/Properties.ts @@ -1,16 +1,24 @@ +enum ColorScheme { + System = "system", + Light = "light", + Dark = "dark", +} + export type PropertiesJSON = { hintchars?: string; smoothscroll?: boolean; complete?: string; + colorscheme?: ColorScheme; }; export type PropertyTypes = { hintchars: string; smoothscroll: string; complete: string; + colorscheme: string; }; -type PropertyName = "hintchars" | "smoothscroll" | "complete"; +type PropertyName = "hintchars" | "smoothscroll" | "complete" | "colorscheme"; type PropertyDef = { name: PropertyName; @@ -38,12 +46,19 @@ const defs: PropertyDef[] = [ defaultValue: "sbh", type: "string", }, + { + name: "colorscheme", + description: "color scheme of the console", + defaultValue: ColorScheme.System, + type: "string", + }, ]; const defaultValues = { hintchars: "abcdefghijklmnopqrstuvwxyz", smoothscroll: false, complete: "sbh", + colorscheme: ColorScheme.System, }; export default class Properties { @@ -53,18 +68,23 @@ export default class Properties { public complete: string; + public colorscheme: ColorScheme; + constructor({ hintchars, smoothscroll, complete, + colorscheme, }: { hintchars?: string; smoothscroll?: boolean; complete?: string; + colorscheme?: ColorScheme; } = {}) { this.hintchars = hintchars || defaultValues.hintchars; this.smoothscroll = smoothscroll || defaultValues.smoothscroll; this.complete = complete || defaultValues.complete; + this.colorscheme = colorscheme || defaultValues.colorscheme; } static fromJSON(json: PropertiesJSON): Properties { @@ -76,6 +96,7 @@ export default class Properties { hintchars: "string", smoothscroll: "boolean", complete: "string", + colorscheme: "string", }; } @@ -92,6 +113,7 @@ export default class Properties { hintchars: this.hintchars, smoothscroll: this.smoothscroll, complete: this.complete, + colorscheme: this.colorscheme, }; } } diff --git a/src/shared/settings/Settings.ts b/src/shared/settings/Settings.ts index 1bb9249..6f178ea 100644 --- a/src/shared/settings/Settings.ts +++ b/src/shared/settings/Settings.ts @@ -156,7 +156,8 @@ export const DefaultSettingJSONText = `{ "properties": { "hintchars": "abcdefghijklmnopqrstuvwxyz", "smoothscroll": false, - "complete": "sbh" + "complete": "sbh", + "colorscheme": "system" }, "blacklist": [ ] diff --git a/src/shared/settings/schema.json b/src/shared/settings/schema.json index 31d47f1..be0f2ec 100644 --- a/src/shared/settings/schema.json +++ b/src/shared/settings/schema.json @@ -48,6 +48,10 @@ }, "complete": { "type": "string" + }, + "colorscheme": { + "type": "string", + "enum": ["system", "light", "dark"] } } }, diff --git a/src/shared/settings/validate.js b/src/shared/settings/validate.js index 236488d..30f7888 100644 --- a/src/shared/settings/validate.js +++ b/src/shared/settings/validate.js @@ -1,4 +1,5 @@ 'use strict'; +var equal = require('ajv/lib/compile/equal'); var validate = (function() { var pattern0 = new RegExp('.*'); var refVal = []; @@ -273,6 +274,46 @@ var validate = (function() { } var valid2 = errors === errs_2; } + if (valid2) { + var data2 = data1.colorscheme; + if (data2 === undefined) { + valid2 = true; + } else { + var errs_2 = errors; + if (typeof data2 !== "string") { + validate.errors = [{ + keyword: 'type', + dataPath: (dataPath || '') + '.properties.colorscheme', + schemaPath: '#/properties/properties/properties/colorscheme/type', + params: { + type: 'string' + }, + message: 'should be string' + }]; + return false; + } + var schema2 = validate.schema.properties.properties.properties.colorscheme.enum; + var valid2; + valid2 = false; + for (var i2 = 0; i2 < schema2.length; i2++) + if (equal(data2, schema2[i2])) { + valid2 = true; + break; + } if (!valid2) { + validate.errors = [{ + keyword: 'enum', + dataPath: (dataPath || '') + '.properties.colorscheme', + schemaPath: '#/properties/properties/properties/colorscheme/enum', + params: { + allowedValues: schema2 + }, + message: 'should be equal to one of the allowed values' + }]; + return false; + } + var valid2 = errors === errs_2; + } + } } } } else { @@ -535,6 +576,10 @@ validate.schema = { }, "complete": { "type": "string" + }, + "colorscheme": { + "type": "string", + "enum": ["system", "light", "dark"] } } }, |