Charles Dawson
Charles Dawson

Reputation: 1

How do I detect the current background color of the terminal in which my python script was invoked?

I am using a xfce4 terminal and I want to be able to detect if the background color is set to either black or white (or presumably some other color)

My code looks like this:

def print_color(string, style, textColor, background):  
     string = "\033[{};{};{}m{}\033[m ".format(style,textColor,background,string)  
     print(string)

I would like to detect the current background color and use it instead of passing it in.

I've tried not setting it, like this:

def print_color(string, style, textColor):  
     string = "\033[{};{};m{}\033[m ".format(style,textColor,string)  
     print(string)

but that did not work as I expected.

Upvotes: 0

Views: 478

Answers (1)

Thomas Dickey
Thomas Dickey

Reputation: 54475

XFCE4 terminal uses VTE, which lacks the ability to respond to queries of the colors. That would be the SGR flavor of DECRQSS, which is mostly unimplemented in VTE.

(The example shown wouldn't work anyway). This is unrelated to the GTK+ toolkit.

Upvotes: 1

Related Questions