简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM