dalance / termbg

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

Environment variable fallback for unsupported terminals #18

Open nickolay opened 1 year ago

nickolay commented 1 year ago

For unsupported terminals it would be nice to have some fallback.

According to https://unix.stackexchange.com/questions/245378/common-environment-variable-to-set-dark-or-light-terminal-background / https://github.com/rocky/shell-term-background there's no well-established standard, but the COLORFGBG environment variable has some potential: Value 15;0 is for a dark background (technically white on black) and 0;15 (technically black on white) is for a light background.

Would you be willing to adopting this?

dalance commented 1 year ago

Detection through COLORFGBG was implemented previously. https://github.com/dalance/termbg/blob/763d16e362a437c4718e3dc0eafcacbfb69e0dec/src/lib.rs#L124

I removed it because there seems to be a few usable case, but it can be reverted if it is useful.

nickolay commented 1 year ago

Oh, sorry, didn't see that!

To elaborate on why I thought it would be nice to have some fallback: as a user of an unsupported terminal with light background, I'd like to indicate my preference once (e.g. by setting COLORFGBG) instead of finding a way to configure colors for every program I'm trying out.

Of course this would only have noticeable effect when enough programs use termbg, but I assume that's the goal:)

Anyway, thanks for your work on this crate! Getting the rust ecosystem to properly support light-background terminals would be really nice to people like me who can't read white-on-black without straining their eyes too much.

dalance commented 1 year ago

I added the fallback and released v0.4.2.

nickolay commented 1 year ago

Wow you're fast!

On Windows though unsupported terminals are detected as Terminal::Windows and as far as I can see from_winapi can't fail, so the fallback doesn't work well. Do you think it's appropriate to submit pull requests to make pub fn terminal() detect specific unsupported terminals (e.g. ConEmuPID -> ConEmu -> fallback to COLORFGBG)?