简体   繁体   English

是否可以以编程方式访问 VS Codes 主题属性? 比如,一个人可以使用 VS Code API 来更改主题颜色吗?

[英]Is it possible to access VS Codes theme properties programatically? Like, can a person use the VS Code API to change a theme color?

Programmatically Accessing VSCode Theme Properties以编程方式访问 VSCode 主题属性

Is it possible to programmatically & dynamically get & set the colors of VS Code's theme property's using the VS Code API ?是否可以使用VS Code API以编程方式和动态getset VS Code主题属性的颜色?


The snippet bellow demonstrates using The VSCode API , and its method, getConfiguration() , to change settings.下面的代码片段演示了使用VSCode API及其方法getConfiguration()来更改设置。 I was hopping that something like this snippet would work from programmatically changing theme colors, but to no avail.我希望像这个片段这样的东西可以通过以编程方式更改主题颜色来工作,但无济于事。


    const workbenchConfig = vscode.workspace.getConfiguration('workspace');
    const themeColor = workbenchConfig.get(`colorTheme.${themeProperty}`);

    console.log(themeColor)

 
    // The argument colorTheme.${someColor} would is obviously replaced with the       
    // theme's property that I want to access.



I wanted to access the same object that the workbench.ColorCustomizations setting accesses, using the snippet above.我想使用上面的代码片段访问workbench.ColorCustomizations设置访问的同一对象。 My thinking was that I could set the theme colors in the same scope, that is used by workbench.colorCustomizations setting, but my attempt was without success.我的想法是我可以将主题颜色设置在相同的范围内,即workbench.colorCustomizations设置使用的,但我的尝试没有成功。


This has been a topic for a while.这个话题已经有一段时间了。 It depends where and how you want to use it.这取决于你想在哪里以及如何使用它。 In webviews you can access theme colors as css variables as listed in the Theme Color reference and use them in your webview.在 webviews 中,您可以访问主题颜色作为主题颜色参考中列出的 css 变量,并在您的 webview 中使用它们。

In the API you can get some workbench colors, like:在 API 中,您可以获得一些工作台颜色,例如:

const wb_color = new vscode.ThemeColor ( 'activityBar.background' ) 

This is probably of limited use though.不过,这可能用途有限。 You can also get the theme kind (eg light, dark, high contrast) of the window with您还可以获得窗口的主题类型(例如浅色、深色、高对比度)

const theme = window.activeColorTheme.kind

I am not aware of a proper way to set colors programmatically.我不知道以编程方式设置颜色的正确方法。 Perhaps there are a few hackish solutions under the issue, dealing with this question here: https://github.com/Microsoft/vscode/issues/32813也许这个问题下有一些hackish解决方案,在这里处理这个问题: https ://github.com/Microsoft/vscode/issues/32813

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM