dalance / termbg

A Rust library for terminal background color detection
Apache License 2.0
80 stars 5 forks source link

Incorrect colors and "Dark" state for macOS Terminal.app with default theme #8

Open zachriggle opened 3 years ago

zachriggle commented 3 years ago

termbg is pretty great and easy to use / test via cargo run.

However, I noticed that when using macOS Terminal.app, with the default profile ("Basic"), the results are incorrect.

It seems that termbg (or one of its dependencies) does not take into account the macOS systemwide appearance, which changes the color of the default terminal from white (Light mode) to black (Dark mode). This setting may change at any time, and can be fetched with:

$ defaults read -globalDomain AppleInterfaceStyle
# prints "Dark" or nothing

Note that this is the ONLY Terminal.app Profile which behaves this way (AFAIK).

Examples

Screen Shot 2021-07-21 at 4 00 03 AM Screen Shot 2021-07-21 at 3 58 47 AM
zachriggle commented 3 years ago

As a follow-up, this appears non-trivial to detect as the xterm control sequences lie.

https://github.com/dalance/termbg/blob/b2be3b50d20502a5b7e6d34eab6a4eedb0151693/src/lib.rs#L183-L191

For Terminal.app, regardless of whether the System Appearance is Light (white background) or Dark (black background) the same result is returned.

$ ( echo -e "\x1b]11;?\x1b\\" > /dev/tty; read -r line </dev/tty; echo "$line" | xxd )
00000000: 1b5d 3131 3b72 6762 3a31 6531 652f 3165  .]11;rgb:1e1e/1e
00000010: 3165 2f31 6531 6507 0a                   1e/1e1e..

A possible fix is special-case detection for:

septatrix commented 2 years ago

This seems like a bug report should be filed to apple