After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 733423 - Please set COLORFGBG environment variable for automatic color detection
Please set COLORFGBG environment variable for automatic color detection
Status: RESOLVED WONTFIX
Product: gnome-terminal
Classification: Core
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: GNOME Terminal Maintainers
GNOME Terminal Maintainers
Depends on:
Blocks:
 
 
Reported: 2014-07-19 21:17 UTC by Josh Triplett
Modified: 2017-03-13 13:02 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Josh Triplett 2014-07-19 21:17:38 UTC
Various terminals, including urxvt and konsole, set an environment variable "COLORFGBG" to allow applications to detect the foreground and background colors.  Various programs, such as vim, use this to determine whether to use a color scheme that works best on a light or dark background.  Please consider setting this variable in gnome-terminal as well.

Semantics: COLORFGBG should contain two fields separated by a semicolon, representing the foreground and background colors, respectively.  Each one should consist of a number from 0-15 if that color matches color 0-15, or "default" otherwise.
Comment 1 Egmont Koblinger 2014-07-20 19:03:49 UTC
Out of quite a few terminals I've just tried on linux, only urxvt and konsole set it (the ones that don't: xterm, st, terminology, pterm).  Konsole and Urxvt use different syntax and semantics, i.e. for me konsole sets it to "0;15" (even though I use the "Black on Light Yellow" color scheme - so why not "default" instead of "15"?), whereas my urxvt sets it to "0;default;15" (it's actually black on white - but why three fields?).  So in neither of these two does the value match your specification.

I'd argue that COLORFGBG is broken by design.  First, the value of "default" according to your specification would be completely useless in case the bg or fg color doesn't exactly match the white or black palette colors (and using the word "default" is really unfortunate).  Second, there's absolutely no way to update the env variable upon profile change (or runtime change of the palette, either via settings or via escape sequences).  Third, I _guess_ its value is not forwarded by ssh and friends.

Instead, I recommend using the OSC 4/10/11 escape sequences, which are already supported by vte/gnome-terminal. You're free to write a .bashrc or equivalent that queries the actual colors using these escapes and sets COLORFGBG accordingly, or a wrapper in front of vim that sets this. You can probably even put this in the shell code that shows the prompt, resulting in the variable being updated soon after a profile change - something g-t couldn't do.

Also, I'd consider asking vim developers to add support for OSC 4/10/11 querying the color, in addition to checking COLORFGBG.
Comment 2 Egmont Koblinger 2014-07-20 23:39:36 UTC
Here's an example .bashrc fragment, feel free to improve as you wish.

if [ -n "$VTE_VERSION" -a -z "$COLORFGBG" ]; then
  stty -echo
  echo -ne '\e]10;?\a\e]11;?\a'
  IFS=: read -t 0.1 -d $'\a' x fg
  IFS=: read -t 0.1 -d $'\a' x bg
  if [[ ${fg:0:1} =~ [01234567] ]]; then
    export COLORFGBG='0;15'
  else
    export COLORFGBG='15;0'
  fi
  unset x fg bg
  stty echo
fi
Comment 3 Egmont Koblinger 2014-07-25 23:20:56 UTC
You can also use
  xtermcontrol --get-fg
  xtermcontrol --get-bg
etc.
Comment 4 Christian Persch 2014-08-16 17:09:58 UTC
Egmont is right; WONTFIX.