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

Protect against color schemes that don't support changing the background #235

Open
micampe opened this issue Oct 13, 2023 · 0 comments
Open

Comments

@micampe
Copy link

micampe commented Oct 13, 2023

Some color schemes don't support toggling light/dark background and trying to do it results in a mangled color scheme.

I fixed this by overriding the yob map, but I was wondering if there is interest to merge this here.

This is my function (I'm not good at vimscript so let me know any feedback):

function! s:ToggleBackground() abort
  let oldcolors = g:colors_name

  if &background == 'light'
    set background=dark
  else
    set background=light
  endif

  if !exists("g:colors_name") || oldcolors != g:colors_name
    execute 'colorscheme ' . oldcolors
    redraw | echo 'Color scheme ' . oldcolors . ' does not support changing the background'
  endif
endfunction

if this is interesting for the project I can create a pull request (or just take the function from here, I don't mind).

To integrate properly it would also have to support the enable/disable commands too. I don't use those so I didn't do it here but I can add it.

halostatue added a commit to halostatue/vim-pairs that referenced this issue Sep 11, 2024
- Expose most of the functions used for map building through autoload so
  that others can more easily add maps in the same manner without
  copying code.

- Incorporate tpope#230, tpope#228, a
  variation of a solution for tpope#235,

- Use <ScriptCmd> instead of `:<C-U>`, which required some rethinking
  because of the use of `<C-R>=`.

- Added additional maps from
  - phongnh/vim-toggler: conceallevel, showmatch, incsearch, expandtab,
    showcmd
  - riceissa/vim-more-toggling: syntax
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

1 participant