[Question] How to automatically check background color?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[Question] How to automatically check background color?

zdohnal
Hi!

I'm currently trying to write test script for checking background type (based on terminal color) in Vim. I have 'dark' terminal, so Vim normally recognizes it and sets 'background' to 'dark', but when I use:

$ vim -c 'redir @">|silent set bg?|redir END|enew|put|w! testfile|q'

then I have 'backgroung=light' (I think it is default, according some test scripts in src/testdir). Vim will probably communicate with terminal about background after my command is done, so the value is correct in fully loaded Vim... is there a way how to get correct value of 'background'?

Thank you in advance and have a nice day,

Zdenek

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Question] How to automatically check background color?

Bram Moolenaar

Zdenek wrote:

> I'm currently trying to write test script for checking background type
> (based on terminal color) in Vim. I have 'dark' terminal, so Vim
> normally recognizes it and sets 'background' to 'dark', but when I
> use:
>
> $ vim -c 'redir @">|silent set bg?|redir END|enew|put|w! testfile|q'
>
> then I have 'backgroung=light' (I think it is default, according some
> test scripts in src/testdir). Vim will probably communicate with
> terminal about background after my command is done, so the value is
> correct in fully loaded Vim... is there a way how to get correct value
> of 'background'?

Vim tries to obtain the background color from the terminal by sending
t_RB.  So first check if t_RB is set.

This doesn't happen right away, thus Vim may first draw the windows
before the response comes.  Then Vim will redraw if needed.  You can
find the response in v:termrbgresp.  You could set a timer to check for
the value and act accordingly.  Or use an OptionSet autocommand to
trigger on 'background' changing.

--
Vi is clearly superior to emacs, since "vi" has only two characters
(and two keystrokes), while "emacs" has five.  (Randy C. Ford)

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.