简体   繁体   English

如何检测调用了我的 python 脚本的终端的当前背景颜色?

[英]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)我正在使用 xfce4 终端,我希望能够检测背景颜色是设置为黑色还是白色(或者可能是其他颜色)

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. XFCE4终端使用VTE,对colors的查询缺乏响应能力。 That would be the SGR flavor of DECRQSS , which is mostly unimplemented in VTE.那将是DECRQSS的 SGR 风格,这在 VTE 中大多未实现。

(The example shown wouldn't work anyway). (显示的示例无论如何都不起作用)。 This is unrelated to the GTK+ toolkit.这与 GTK+ 工具包无关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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