Subject: 28.0.50; Emacs doesn't detect the terminal background color in macOS Terminal or iTerm2

From: Daniel Martín <[email-masked]>
Date: Mon, 31 May 2021 00:20:35 +0200

Steps to reproduce the problem:

- Start macOS Terminal or iTerm2 (both are probably the most popular
terminals for macOS).

- Switch the terminal background color to a dark color.

- emacs -nw -Q

Actual result:

Colored text is sometimes very difficult to read, because Emacs assumes
it's running on a light terminal background, and configures the faces
accordingly.

Expected result:

Emacs faces are those of a dark background.

Workaround:

Customize frame-background-mode to 'dark.

Here's some information about macOS Terminal and iTerm2.  Apparently,
they both identify as xterm-256color and support querying the background
color:

macOS Terminal:

$ printf '\e[>0c'
1;95;0c

$ printf '\e]11;?\e\'
11;rgb:0000/0000/0000

$ echo $TERM
xterm-256color

iTerm2:

$ printf '\e[>0c'
0;95;0c

$ printf '\e]11;?\e\'
11;rgb:0000/0000/0000

$ echo $TERM
xterm-256color

I tried to fix the problem by taking a look at xterm--version-handler in
xterm.el, but the version logic is a bit difficult to understand.  Is
there some documentation about the versions and capabilities somewhere?
I'm worried about changing things there may cause regressions in other
terminals.

Thanks.