Is it possible to programmatically & dynamically get
& set
the colors of V.S. Code's theme property's using the V.S. Code API?
The snippet bellow demonstrates using The VSCode API, and its method, getConfiguration()
, to change settings. 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. 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.
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.
In the API you can get some workbench colors, like:
const wb_color = new vscode.ThemeColor ( 'activityBar.background' )
This is probably of limited use though. You can also get the theme kind (e.g. 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