Sample Header Ad - 728x90

common environment variable to set dark or light terminal background

21 votes
3 answers
10376 views
I have written a number of debuggers that all can colorize source code text shown in a terminal session. They all understand that some terminals have a dark background and some have a light background and that of course the colors need to be different depending on the terminal scheme. It is annoying to have to set to the other scheme when your terminal doesn't match the default background, so I'd like to find a way to figure this out automatically. Suggestions? (They all support options --highlight={light|dark|plain}) One simple mechanism would be to key off an environment variable. For my shell profiles I've been using DARK_BACKGROUND_COLOR, but If there is already some sort of default name like there is for PAGER, EDITOR, SHELL, HOME, etc. I'd like to use that. Is there such a environment name convention? Other suggestions? *Edit:* Based on the accepted answer and discussion, I have switched from using DARK_BACKGROUND_COLOR to COLORFGBG. Value 15;0 is for a dark background (technically white on black) and 0;15 (technically black on white) is for a light background.
Asked by rocky (2018 rep)
Nov 25, 2015, 11:37 AM
Last activity: Mar 16, 2024, 04:35 PM