[IPython-dev] default colorscheme

David Warde-Farley wardefar at iro.umontreal.ca
Wed Jul 6 01:10:58 EDT 2011


On 2011-07-04, at 10:09 PM, Min RK wrote:

> LightBG is the default on OSX, because the default terminal is black on white there.  If there's a good way to determine the actual background color, we could use that to make a more informed default decision.

Well, this is ugly as sin since it involves both spawning a subprocess and the unholy AppleScript, but it's an idea:

To retrieve the default background color for a Terminal.app session,

dwf at strafe:~/src$ osascript
tell application "Terminal"
    set thing to background color of default settings
end tell
<Ctrl-D>
0, 0, 0

To retrieve the default background color for the frontmost window of Terminal.app:

dwf at strafe:~/src$ osascript
tell application "Terminal"
    set thing to name of window 0
end tell
<Ctrl-D>
0, 0, 0

To do the same thing in iTerm:

dwf at strafe:~/src$ osascript
tell application "iTerm"
    set thing to background color of current session of current terminal
end tell
<Ctrl-D>
0, 0, 0

In fact, iTerm sets an "COLORFGBG" environment variable, which makes it slightly easier I guess.

Finally, to differentiate between the two:

dwf at strafe:~$ echo $TERM_PROGRAM
Apple_Terminal

dwf at strafe:~$ echo $TERM_PROGRAM
iTerm.app

Terminal.app and iTerm account for the vast majority of users on OS X, I'd say.

Incidentally, 'xterm' just doesn't set the TERM_PROGRAM variable (unless you launch an xterm from one of those terminals, and it inherits the environment of the parent process, but that's a sufficiently bizarro thing to do...)

What do you think?

David


More information about the IPython-dev mailing list