Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background transparency setting broken #71

Open
baco opened this issue Jul 13, 2022 · 9 comments
Open

Background transparency setting broken #71

baco opened this issue Jul 13, 2022 · 9 comments

Comments

@baco
Copy link
Contributor

baco commented Jul 13, 2022

Until 2 days ago I used to have the following working settings:
init.vim:

let g:vscode_style = 'dark'
let g:vscode_transparent = v:true

silent! colorscheme vscode

but, as I only wanted background transparency on terminals and not on other UIs, I also had:
ginit.vim:

if exists('g:colors_name') && g:colors_name == 'vscode'
	let g:vscode_transparent = v:false
	syntax reset
endif

all working like a charm. Transparent background on terminals default VSCode-like background otherwise.

After a recent merge, both settings stopped working. The documentation about them is gone, and there is no indication on how to keep having the settings in vim-script as it used to.

@Mofiqul
Copy link
Owner

Mofiqul commented Jul 14, 2022

Now you can achieve the same using the setup function.

Just overrides the Normal group like below

group_overrides = {
    -- this supports the same val table as vim.api.nvim_set_hl
    -- use colors from this colorscheme by requiring vscode.colors!
    Normal = { fg = c.vscFront, bg = 'NONE' },
}

You can also do transparent = true setup function

@baco
Copy link
Contributor Author

baco commented Jul 14, 2022

I understand, but the setup function is Lua. For the time being I have not migrated my init.vim nor ginit.vim to init.lua (and I can not find the time to do that either, right now).

Perhaps you are suggesting I include something like lua require('vscode').setup({ transparent = true }) in my current init.vim. I've also detected an issue with that, calling :lua require('vscode').setup({ transparent = false }) later on to try to restore the background inside a Nvim UI (Nvim-GTK to be precise) doesn't bring the background back once it's been set to 'NONE'.

@Mofiqul
Copy link
Owner

Mofiqul commented Jul 15, 2022

It's because once you set transparent=true that vscBack is overwritten by NONE from #1e1e1e.

For your use case, you can use

local c = require('vscode.colors')
require('vscode').setup({
    transparent = false,
    group_overrides = {
        Normal = { fg=c.vscFront, bg= (vim.g.colors_name and vim.g.colors_name == 'vscode') and c.vscBack or c.vscNone},
    }
})

@Mofiqul
Copy link
Owner

Mofiqul commented Jul 15, 2022

@yochem also added backward compitibility. your existing setup supposed to work but sadly its not. In my setting its working. I am so sorry that I am currently too busy to look into. If someone fix I will merge it otherwise have to wait a bit.

@baco
Copy link
Contributor Author

baco commented Jul 15, 2022

Ok, many things happening here:

  1. the setting was renamed, used to be g:vscode_transparent, the same termination as the Lua setting, but it suddenly change to g:vscode_transparency:
    ecb73a11 .. 5b812ce5
-	if vim.g.vscode_transparent then
-		colors.vscBack = 'NONE'
-	end

+         transparent = vim.g.vscode_transparency == 1,
...
+    if opts.transparent then
+        opts.color_overrides.vscBack = 'NONE'
+    end
  1. Also the logic changed. Before, using the native Vim's boolean value (v:true) would work (because it was being stored/evaluated as it came), now it's explicitly compared to the literal 1.

I still don't know why re-setting the option and the syntax wouldn't restore the color, because it seems to be doing almost the same in behind (.vscBack = 'NONE').

@yochem, which is gonna be, vim.g.vscode_transparent or vim.g.vscode_transparency? Can it evaluate to Lua's true, also when storing Vim's v:true in the options (seems more accurate)?

@yochem
Copy link
Contributor

yochem commented Jul 16, 2022

Hi, sorry for this! I based the backwards compatibility on the README, and found an error in it:

image

see here.

In the lua part the variable has a different name than in the vim part (transparency vs transparent). Also, both look to be using 1/0. The code however just evaluated the to-lua-converted vim.g.transparent value. The explicit check with == 1 was because Lua evaluates 0 also as true. I'll create a PR for it to fix this.

@yochem
Copy link
Contributor

yochem commented Jul 16, 2022

To comply to the documentation and code before my PR, I will only change vim.g.transparency to vim.g.transparent. Even though it would be better if all values could be set with v:true|v:false, I won't change it to that because the code that checks for the vim.g.vscode_* variables is only there for backwards compatibility.

I've also detected an issue with that, calling :lua require('vscode').setup({ transparent = false }) later on to try to restore the background inside a Nvim UI (Nvim-GTK to be precise) doesn't bring the background back once it's been set to 'NONE'.

Might this be because vim.g.vscode_transparent is still set to 1?

@baco
Copy link
Contributor Author

baco commented Jul 16, 2022

I won't change it to that because the code that checks for the vim.g.vscode_* variables is only there for backwards compatibility.

Wouldn't be as easy as:

transparent = vim.g.vscode_transparency == true or vim.g.vscode_transparency == 1,
italic_comments = vim.g.vscode_italic_comment == true or vim.g.vscode_italic_comment == 1,
  1. It would be more backwards compatible, even to those configs that use boolean values instead of integers
  2. Technically speaking, checking the boolean value (rather than the integer one) would represent the exact same semantics used in the code before (as shown in the commits linked in my previous message)

@baco
Copy link
Contributor Author

baco commented Jul 17, 2022

local c = require('vscode.colors')
require('vscode').setup({
    transparent = false,
    group_overrides = {
        Normal = { fg=c.vscFront, bg= (vim.g.colors_name and vim.g.colors_name == 'vscode') and c.vscBack or c.vscNone},
    }
})

@Mofiqul I've tried a variant of this (has the same outcome), putting in ginit.vim:

if exists('g:colors_name') && g:colors_name == 'vscode'
	let g:vscode_transparent = v:false
lua <<EOF
	local c = require('vscode.colors')
	require('vscode').setup({ group_overrides = { Normal = { fg=c.vscFront, bg=c.vscBack } } })
EOF
endif

Both variants work (yours and mine), but with the same weird effect. After restoring the background color, the front color for spaces become more brilliant than they should:
image

Instead, if I didn't make the background transparent on init.vim and tried to restored later on ginit.vim it should look dimmer:
image

Any idea on what's happening there and how could I solve that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants