Bug 1262837 - Tracker: make _remote_ vim doing the right decisions about 'set background'
Summary: Tracker: make _remote_ vim doing the right decisions about 'set background'
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: vim
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Pavel Raiskup
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On: 1262843 1262863 1264682
Blocks: 1377316
TreeView+ depends on / blocked
 
Reported: 2015-09-14 13:06 UTC by Pavel Raiskup
Modified: 2020-03-21 13:02 UTC (History)
6 users (show)

Fixed In Version:
Clone Of:
: 1377316 (view as bug list)
Environment:
Last Closed: 2020-03-21 13:02:14 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
KDE Software Compilation 352945 0 NOR RESOLVED PATCH/RFE: add support for terminal background detection (vim background autodetection) 2020-03-21 13:00:49 UTC
Red Hat Bugzilla 1159920 0 unspecified CLOSED Please switch default to bg=dark 2021-02-22 00:41:40 UTC

Internal Links: 1159920

Description Pavel Raiskup 2015-09-14 13:06:41 UTC
Users of 'dark' terminals know that 'vim' binary started remotely (over ssh)
does not choose correct theme (light vs. dark).  There exists variable
$COLORFGBG (that env var is e.g. exported by KDE's 'konsole' terminal
emulator).  As long as the COLORFGBG variable is set (correctly) in
environment, vim is able to choose right theme automatically.

The problem is, however, that tools like 'su', 'runuser', 'sudo', 'ssh' do
trim environment for security reasons;  including $COLORFGBG (which is
otherwise safe variable).

Some of those tools allow "white-listing" of safe variables, some not (and
maybe its even not desired feature).  This bug is thus mentioned as tracker
for particular config-changes for the tools that allow it.

Comment 1 Pavel Raiskup 2015-09-14 13:08:22 UTC
util-linux does not seem to have it implemented (yet?):
https://github.com/karelzak/util-linux/issues/221

Comment 2 Jakub Jelen 2015-09-17 10:22:29 UTC
Pavel. You must have some special setup. Why does this work well with Gnome and dark terminals? What is special with KDE? Isn't it broken there? I never experienced such problem on any of systems I am connecting to.

In ssh, we are sending and accepting only locale variables and XMODIFIERS. I don't think this report for KDE is enough to change default for whole distribution.

Comment 3 Pavel Raiskup 2015-09-17 10:50:38 UTC
Jakub, you claim that vim is able to detect whether set 'bg=dark' or 'bg=light'
based on XMODIFIERS?  Can you please send me content of your $XMODIFIERS
variable (to allow me to test it in KDE..)?  Thanks.

Comment 4 Jakub Jelen 2015-09-17 11:48:01 UTC
I don't know how and if it is related to XMODIFIERS or how is it done, but I have different machines and under Gnome it never happened, to me to have problem with colours of vim. It looks (almost) the same with dark terminal and dark background everywhere.

My XMODIFIERS variable looks like this:

[root@rawhide ~]# echo $XMODIFIERS
@im=ibus

You report is quite vague. There is no test case and my knowledge about vim is not not so deep to know how to "vim is able to detect whether set 'bg=dark' or 'bg=light'". Can you be more specific?

Comment 5 Pavel Raiskup 2015-09-17 12:25:09 UTC
(In reply to Jakub Jelen from comment #4)
> I don't know how and if it is related to XMODIFIERS or how is it done, but I
> have different machines and under Gnome it never happened, to me to have
> problem with colours of vim. It looks (almost) the same with dark terminal
> and dark background everywhere.
> 
> My XMODIFIERS variable looks like this:
> 
> [root@rawhide ~]# echo $XMODIFIERS
> @im=ibus

Its not related to XMODIFIERS.  However I tried gnome-terminal installed
in KDE, and it really works (for some reason).  I thought the responsible code
was term_bg_default(), but I bet it is unlikely.  Let me look at it more
carefuly.

> You report is quite vague. There is no test case and my knowledge about vim
> is not not so deep to know how to "vim is able to detect whether set
> 'bg=dark' or 'bg=light'". Can you be more specific?

Start vim and press: ":set bg<ENTER>", you'll get 'background=dark' or
'background=light'.

Comment 6 Pavel Raiskup 2015-09-17 14:54:57 UTC
(In reply to Pavel Raiskup from comment #5)
> Its not related to XMODIFIERS.  However I tried gnome-terminal installed in
> KDE, and it really works (for some reason).  I thought the responsible code
> was term_bg_default(), but I bet it is unlikely.  Let me look at it more
> carefuly.

Ok, the reason why gnome-terminal works and konsole (KDE) not is because
konsole is based on xterm, that does not understand the "background color
request" (vim is able to read the response):

   echo -e "\033]11;?\a"

vte291 (gnome-terminal's backend probably?) OTOH is able to give proper
response.  Dunno how realistic is hacking support for background RGB request
in konsole/xterm -- I'll try to file a appropriate bugs.

Comment 7 Pavel Raiskup 2015-09-21 07:49:00 UTC
Hmm, while trying to detect why fix for bug 1264682 did not help against
{RHEL,CentOS}{6,7} vim, I realized that vim's background color detection
is quite new feature (see also bug).

Comment 8 Pavel Raiskup 2015-10-07 14:08:40 UTC
(In reply to Pavel Raiskup from comment #7)
> Hmm, while trying to detect why fix for bug 1264682 did not help against
> {RHEL,CentOS}{6,7} vim, I realized that vim's background color detection
> is quite new feature (see also bug).

By that I meant that forwarding COLORFGBG still makes sense.  Even though
patch for konsole was accepted by upstream.  COLORFGBG should work against
boxes with older vim.

(In reply to Jakub Jelen from comment #4)
> I don't know how and if it is related to XMODIFIERS or how is it done, but I
> have different machines and under Gnome it never happened, to me to have
> problem with colours of vim.

This does not seem to be truth.  Try to ssh to CentOS machine from
gnome-terminal (with dark background).  And the bug 1159920 sounds like
this has been pain historically even on local box.

Comment 9 Lubomir Rintel 2015-11-06 08:28:45 UTC
Please don't use COLORFGBG.

It's a terrible hack that doesn't work when you change the settings at runtime. There's a xterm escape sequence that terminals use to communicate the color set.

Problem is that some terminals don't support the "\033]11;?\007" sequence when they set TERM=xterm. VTE (gnome-terminal, xterm) however works well and other terminals should be fixed.

See bug #1159920

Comment 10 Pavel Raiskup 2015-11-06 09:00:21 UTC
(In reply to Lubomir Rintel from comment #9)
> Please don't use COLORFGBG.

Lubomir, I believed we could manage to make this work against older systems
like CentOS 5/6 -- allowing ssh server accept COLORFGBG is much easier task
than updating vim to know how to ask the terminal what background color
is currently used.  

> It's a terrible hack that doesn't work when you change the settings at
> runtime. There's a xterm escape sequence that terminals use to communicate
> the color set.

As long as vim is sensitive to COLORFGBG, it is absolutely harmless variable
which may be passed through ssh.  Who plans to change COLORFGBG at vim's
runtime?  It's inherited from shell environment and if konsole changes
background, its not changed in vim.

The fact is that 'konsole' already automatically exports COLORFGBG now.

> Problem is that some terminals don't support the "\033]11;?\007" sequence
> when they set TERM=xterm. VTE (gnome-terminal, xterm) however works well and
> other terminals should be fixed.
> 
> See bug #1159920

Other terminals might be fixed -- I payed attention to fix konsole if you read
this bug carefully -- but sufficiently new vim won't be distributed on older
boxes.

Comment 11 Karsten Hopp 2016-04-28 14:13:39 UTC
Pavel, can this be closed or reassigned to you ?

Comment 12 Pavel Raiskup 2020-03-21 13:02:14 UTC
The important patch is now in RHEL7+ vim, and recent Fedora boxes.
Konsole in KDE is fixed as well in Fedora.  This is fixed from my POV.


Note You need to log in before you can comment on or make changes to this bug.