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

Terminal theme autodetection should support GNU Screen #8302

Open
jwodder opened this issue Nov 6, 2023 · 2 comments
Open

Terminal theme autodetection should support GNU Screen #8302

jwodder opened this issue Nov 6, 2023 · 2 comments
Labels
blocked enhancement a request to improve CLI

Comments

@jwodder
Copy link

jwodder commented Nov 6, 2023

Describe the feature or problem you’d like to solve

When viewing rendered Markdown via a command like gh repo view, gh attempts to automatically determine whether the current terminal theme is light-on-dark or dark-on-light so it can decide what Glamour theme to default to. This works in some cases, but there's one case where it doesn't work (and it affects me, so it's important): when running gh in GNU Screen. (By "doesn't work," I mean that gh falls back to the "dark" Glamour style even when my terminal is black-on-white and thus should get the "light" Glamour style.)

Proposed solution

I'm assuming that gh currently tries to detect the terminal theme by outputting the xterm-specific sequence "\x1b]11;?\x1b\\" and parsing whatever the terminal sends back. This does not work for Screen. Per the source code for the termbg Rust library, the correct sequence to use when the TERM envvar starts with "screen" is "\x1bP\x1b]11;?\x07\x1b\\\x03", and I can confirm that this works as of Screen 4.9.1. (termbg also lists "\x1bPtmux;\x1b\x1b]11;?\x07\x1b\\\x03" for when the TMUX envvar is set; this also works on my Screen.)

It's likely that gh may be using a third-party library for autodetection, but I don't know what that would be. If so, this feature request will have to be forwarded to that library.

@jwodder jwodder added the enhancement a request to improve CLI label Nov 6, 2023
@cliAutomation cliAutomation added the needs-triage needs to be reviewed label Nov 6, 2023
@samcoe
Copy link
Contributor

samcoe commented Nov 7, 2023

@jwodder Sorry that you have run into this issue. I was able to reproduce it locally. As you correctly surmised we are using a third party package, termenv, to do our determining of the terminal theme. I took a quick glance at the code there and spotted this which seems to suggest that when using screen or tmux that it bails on trying to determine the terminal theme, falls back to using the environment variable COLORFGBG, and if that is not set then uses black. I was able to use that information to trigger the correct markdown theme using:

COLORFGBG="1;15" gh repo view cli/cli

Overall, I think this feature request should be forwarded to termenv to see if they would like to support screen using the specific sequence you mentioned. What do you think?

@samcoe samcoe added needs-user-input and removed needs-triage needs to be reviewed labels Nov 7, 2023
@jwodder
Copy link
Author

jwodder commented Nov 7, 2023

@samcoe Issue filed upstream: muesli/termenv#158

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked enhancement a request to improve CLI
Projects
None yet
Development

No branches or pull requests

3 participants