VSCode自定义配色方案的实现
说明
本文更新于2019-02-18,使用vscode 1.14.1,操作系统为windows。
配置文件
“文件-首选项-颜色主题”即可显示所有可用的颜色主题,上下选择后enter即可。也可通过ctrl+shift+p输入color theme
回车后调出“首选项:颜色主题”面板。
记vscode的安装目录为$release
,默认的颜色主题配置文件都位于$release/resources/app/extensions
目录中。以theme-
开头的目录即为颜色主题配置(事实上,其中有些是文件图标主题)。除若干主题会共用一个目录外(theme-defaults
),大多数主题都是一个主题一个目录。
每个颜色主题配置目录包含以下文件:themes
目录、ossreadme.json
、package.json
。themes
目录下通常使用.json
设置具体的配色方案;ossreadme.json
描述版权等相关信息,可以忽略;package.json
令vscode读取后能区分不同的配色方案。
下面新增一个灰色调颜色主题。在$release/resources/app/extensions
目录下新增如下目录结构。如果你不关心配置文件相关参数的解释,可无需细读后面内容,只需将相应的配置文本复制至配置文件中即可,但需注意文件均为utf-8编码。
$release/resources/app/extensions/ \_ theme-gv-gray/ \_ themes/ | \_ gv-gray-color-theme.json |_ package.json
预览图
package.json
package.json文件内容如下:
{ "name": "theme-gv-gray", "version": "0.1.0", "publisher": "gv", "engines": { "vscode": "*" }, "contributes": { "themes": [ { "label": "gv-gray", "uitheme": "vs", "path": "./themes/gv-gray-color-theme.json" } ] } }
参数名 | 作用 |
---|---|
name | 主题id,必需在vscode中全局唯一,即所有主题的package.json中该值均不能重复 |
contributes -> themes -> label | 主题名,“文件-首选项-颜色主题”的列表中显示该值 |
contributes -> themes -> uitheme | vscode整体的ui主题,vs为浅色主题 |
contributes -> themes -> path | 定义配色方案的文件名,如为相对路径则相对于此文件 |
因配置文件内容太长放至文末,以下说明对照配置文件内容阅读更易理解。
vscode使用其以下两个节点:
参数名 | 作用 |
---|---|
colors | vscode各个ui组件的颜色 |
tokencolors | 语法高亮颜色 |
colors节点的内容直接通过键值对参数描述,以下列举几个参数的作用:
图示 | 参数名 | 作用 |
---|---|---|
2 | activitybar.background | 活动栏背景色 |
1 | activitybar.foreground | 活动栏前景色(例如用于图标) |
12 | editor.background | 编辑器背景颜色 |
13 | editor.foreground | 编辑器默认前景色 |
editor.findmatchbackground | 当前搜索匹配项的颜色 | |
editor.findmatchhighlightbackground | 其他搜索匹配项的颜色 | |
15 | editor.linehighlightbackground | 光标所在行高亮文本的背景颜色 |
editor.selectionbackground | 编辑器所选内容的颜色 | |
editor.selectionhighlightbackground | 与所选内容具有相同内容的区域颜色 | |
editor.rangehighlightbackground | 突出显示范围的背景颜色,例如 "quick open" 和“查找”功能 | |
16 | editorbracketmatch.background | 匹配括号的背景色 |
14 | editorcursor.foreground | 编辑器光标颜色 |
11 | editorgutter.background | 编辑器导航线的背景色,导航线包括边缘符号和行号 |
10 | editorlinenumber.foreground | 编辑器行号颜色 |
5 | sidebar.background | 侧边栏背景色 |
4 | sidebar.foreground | 侧边栏前景色 |
3 | sidebarsectionheader.background | 侧边栏节标题的背景颜色 |
17 | statusbar.background | 标准状态栏背景色 |
17 | statusbar.nofolderbackground | 没有打开文件夹时状态栏的背景色 |
17 | statusbar.debuggingbackground | 调试程序时状态栏的背景色 |
9 | tab.activebackground | 活动选项卡的背景色 |
8 | tab.activeforeground | 活动组中活动选项卡的前景色 |
7 | tab.inactivebackground | 非活动选项卡的背景色 |
6 | tab.inactiveforeground | 活动组中非活动选项卡的前景色 |
tokencolors
tokencolors使用一个对象数组描述各语法高亮颜色。每个对象有如下结构:
{ "name": "comment", "scope": [ "comment", "punctuation.definition.comment" ], "settings": { "background": "#ffffff", "fontstyle": "italic", "foreground": "#000000" } }
参数名 | 作用 |
---|---|
name | 规则描述,一段容易理解的描述性文字 |
scope | 作用域,指定使用那些vscode内部对象,其含义参看scope naming |
setting -> background | 背景色,可选 |
setting -> fontstyle | 字体,可选,为bold、italic、underline |
setting -> foreground | 前景色,可选 |
以下列举文末的配置文件中几个name所指定的参数的作用:
参数名 | 作用 |
---|---|
character | 字符 |
class | 类名 |
comment | 注释 |
function | 函数名 |
keyword | 关键字 |
number | 数值 |
operator | 运算符 |
parameter | 函数参数 |
punctuation | 标点符号 |
string | 字符串 |
type | 内置类型 |
variable | 变量名 |
文件内容
{ "name": "gv-gray", "colors": { "activitybar.background": "#e0e0e0", "activitybar.foreground": "#000000", "editor.background": "#c8c8c8", "editor.foreground": "#000000", "editor.findmatchbackground": "#ffff00", "editor.findmatchhighlightbackground": "#ffff00", "editor.linehighlightbackground": "#c0c0c0", "editor.selectionbackground": "#b0b0b0", "editor.selectionhighlightbackground": "#dfdfdf", "editor.rangehighlightbackground": "#b0b0b0", "editorbracketmatch.background": "#b0b0b0", "editorcursor.foreground": "#333333", "editorgutter.background": "#d3d3d3", "editorlinenumber.foreground": "#777777", "sidebar.background": "#f5f5f5", "sidebar.foreground": "#000000", "sidebarsectionheader.background": "#e0e0e0", "statusbar.background": "#444444", "statusbar.nofolderbackground": "#444444", "statusbar.debuggingbackground": "#444444", "tab.activebackground": "#afafaf", "tab.activeforeground": "#000000", "tab.inactivebackground": "#e0e0e0", "tab.inactiveforeground": "#000000", // other colors. "activitybarbadge.background": "#705697", "button.background": "#705697", "dropdown.background": "#f5f5f5", "editorgroup.dropbackground": "#c9d0d988", "editorwhitespace.foreground": "#aaaaaa", "focusborder": "#a6b39b", "inputoption.activeborder": "#adafb7", "inputvalidation.infoborder": "#4ec1e5", "inputvalidation.infobackground": "#f2fcff", "inputvalidation.warningbackground": "#fffee2", "inputvalidation.warningborder": "#ffe055", "inputvalidation.errorbackground": "#ffeaea", "inputvalidation.errorborder": "#f1897f", "list.activeselectionforeground": "#6c6c6c", "list.focusbackground": "#cadeb9", "list.activeselectionbackground": "#c4d9b1", "list.inactiveselectionbackground": "#d3dbcd", "list.highlightforeground": "#9769dc", "notification.background": "#442e66", "panel.background": "#f5f5f5", "peekvieweditor.matchhighlightbackground": "#c2dfe3", "peekviewtitle.background": "#f2f8fc", "peekvieweditor.background": "#f2f8fc", "peekviewresult.background": "#f2f8fc", "peekview.border": "#705697", "peekviewresult.matchhighlightbackground": "#93c6d6", "pickergroup.foreground": "#a6b39b", "pickergroup.border": "#749351" }, "tokencolors": [ { "settings": { "background": "#ffffff", "foreground": "#000000" } }, { "name": "character", "scope": [ "constant", "constant.character" ], "settings": { "foreground": "#008000" } }, { "name": "class", "scope": [ "entity.name.type", "entity.other.inherited-class", "support.class" ], "settings": { "foreground": "#000080" } }, { "name": "comment", "scope": [ "comment", "punctuation.definition.comment" ], "settings": { "fontstyle": "italic", "foreground": "#0066ff" } }, { "name": "function", "scope": [ "entity.name.function", "support.function" ], "settings": { "foreground": "#000000" } }, { "name": "keyword", "scope": [ "keyword", "storage" ], "settings": { "fontstyle": "bold", "foreground": "#000080" } }, { "name": "number", "scope": [ "constant.numeric" ], "settings": { "foreground": "#0044bb" } }, { "name": "operator", "scope": "keyword.operator", "settings": { "foreground": "#000000" } }, { "name": "parameter", "scope": "variable.parameter", "settings": { "fontstyle": "underline" } }, { "name": "punctuation", "scope": "punctuation", "settings": { "foreground": "#000000" } }, { "name": "string", "scope": "string", "settings": { "foreground": "#008000" } }, { "name": "type", "scope": [ "storage.type", "support.type" ], "settings": { "fontstyle": "", "foreground": "#000080" } }, { "name": "variable", "scope": [ "support.variable", "variable" ], "settings": { "foreground": "#000000" } }, // other token colors. { "name": "comments: preprocessor", "scope": "comment.block.preprocessor", "settings": { "fontstyle": "", "foreground": "#aaaaaa" } }, { "name": "comments: documentation", "scope": [ "comment.documentation", "comment.block.documentation" ], "settings": { "foreground": "#448c27" } }, { "name": "invalid - deprecated", "scope": "invalid.deprecated", "settings": { "background": "#96000014" } }, { "name": "invalid - illegal", "scope": "invalid.illegal", "settings": { "background": "#96000014", "foreground": "#660000" } }, { "name": "language constants", "scope": [ "constant.language", "support.constant", "variable.language" ], "settings": { "foreground": "#ab6526" } }, { "name": "exceptions", "scope": "entity.name.exception", "settings": { "foreground": "#660000" } }, { "name": "sections", "scope": "entity.name.section", "settings": { "fontstyle": "bold" } }, { "name": "strings: escape sequences", "scope": "constant.character.escape", "settings": { "foreground": "#777777" } }, { "name": "strings: regular expressions", "scope": "string.regexp", "settings": { "foreground": "#4b83cd" } }, { "name": "strings: symbols", "scope": "constant.other.symbol", "settings": { "foreground": "#ab6526" } }, { "name": "embedded source", "scope": [ "string source", "text source" ], "settings": { "background": "#eaebe6" } }, { "name": "html: doctype declaration", "scope": [ "meta.tag.sgml.doctype", "meta.tag.sgml.doctype string", "meta.tag.sgml.doctype entity.name.tag", "meta.tag.sgml punctuation.definition.tag.html" ], "settings": { "foreground": "#aaaaaa" } }, { "name": "html: tags", "scope": [ "meta.tag", "punctuation.definition.tag.html", "punctuation.definition.tag.begin.html", "punctuation.definition.tag.end.html" ], "settings": { "foreground": "#91b3e0" } }, { "name": "html: tag names", "scope": "entity.name.tag", "settings": { "foreground": "#4b83cd" } }, { "name": "html: attribute names", "scope": [ "meta.tag entity.other.attribute-name", "entity.other.attribute-name.html" ], "settings": { "fontstyle": "italic", "foreground": "#91b3e0" } }, { "name": "html: entities", "scope": [ "constant.character.entity", "punctuation.definition.entity" ], "settings": { "foreground": "#ab6526" } }, { "name": "css: selectors", "scope": [ "meta.selector", "meta.selector entity", "meta.selector entity punctuation", "entity.name.tag.css" ], "settings": { "foreground": "#7a3e9d" } }, { "name": "css: property names", "scope": [ "meta.property-name", "support.type.property-name" ], "settings": { "foreground": "#ab6526" } }, { "name": "css: property values", "scope": [ "meta.property-value", "meta.property-value constant.other", "support.constant.property-value" ], "settings": { "foreground": "#448c27" } }, { "name": "css: important keyword", "scope": "keyword.other.important", "settings": { "fontstyle": "bold" } }, { "name": "markup: changed", "scope": "markup.changed", "settings": { "background": "#ffffdd", "foreground": "#000000" } }, { "name": "markup: deletion", "scope": "markup.deleted", "settings": { "background": "#ffdddd", "foreground": "#000000" } }, { "name": "markup: emphasis", "scope": "markup.italic", "settings": { "fontstyle": "italic" } }, { "name": "markup: error", "scope": "markup.error", "settings": { "background": "#96000014", "foreground": "#660000" } }, { "name": "markup: insertion", "scope": "markup.inserted", "settings": { "background": "#ddffdd", "foreground": "#000000" } }, { "name": "markup: link", "scope": "meta.link", "settings": { "foreground": "#4b83cd" } }, { "name": "markup: output", "scope": [ "markup.output", "markup.raw" ], "settings": { "foreground": "#777777" } }, { "name": "markup: prompt", "scope": "markup.prompt", "settings": { "foreground": "#777777" } }, { "name": "markup: heading", "scope": "markup.heading", "settings": { "foreground": "#aa3731" } }, { "name": "markup: strong", "scope": "markup.bold", "settings": { "fontstyle": "bold" } }, { "name": "markup: traceback", "scope": "markup.traceback", "settings": { "foreground": "#660000" } }, { "name": "markup: underline", "scope": "markup.underline", "settings": { "fontstyle": "underline" } }, { "name": "markup quote", "scope": "markup.quote", "settings": { "foreground": "#7a3e9d" } }, { "name": "markup lists", "scope": "markup.list", "settings": { "foreground": "#4b83cd" } }, { "name": "markup styling", "scope": [ "markup.bold", "markup.italic" ], "settings": { "foreground": "#448c27" } }, { "name": "markup inline", "scope": "markup.inline.raw", "settings": { "fontstyle": "", "foreground": "#ab6526" } }, { "name": "extra: diff range", "scope": [ "meta.diff.range", "meta.diff.index", "meta.separator" ], "settings": { "background": "#ddddff", "foreground": "#434343" } }, { "name": "extra: diff from", "scope": "meta.diff.header.from-file", "settings": { "background": "#ffdddd", "foreground": "#434343" } }, { "name": "extra: diff to", "scope": "meta.diff.header.to-file", "settings": { "background": "#ddffdd", "foreground": "#434343" } } ] }
到此这篇关于vscode自定义配色方案的实现的文章就介绍到这了,更多相关vscode自定义配色 内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!