Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zachriggle opened this issue Jul 21, 2021 · 2 comments

Comments

@zachriggle
Copy link

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
Copy link
Author

zachriggle commented Jul 21, 2021

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

termbg/src/lib.rs

Lines 183 to 191 in b2be3b5

fn from_xterm(term: Terminal, timeout: Duration) -> Result<Rgb, Error> {
// Query by XTerm control sequence
let query = if term == Terminal::Tmux {
"\x1bPtmux;\x1b\x1b]11;?\x07\x1b\\\x03"
} else if term == Terminal::Screen {
"\x1bP\x1b]11;?\x07\x1b\\\x03"
} else {
"\x1b]11;?\x1b\\"
};

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:

  • $TERM_PROGRAM=Apple_Terminal
  • These specific values (#1e1e1e)
  • Shelling out to defaults read -globalDomain AppleInterfaceStyle
    • If Dark, prints "Dark" if the mode is dark, exits 0
    • If Light, prints a message to stderr, exits 1

@septatrix
Copy link

This seems like a bug report should be filed to apple

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants