[英]How do I detect if my Python script is running in the 'Windows Terminal'
[英]How do I detect the current background color of the terminal in which my python script was invoked?
我正在使用 xfce4 終端,我希望能夠檢測背景顏色是設置為黑色還是白色(或者可能是其他顏色)
我的代碼如下所示:
def print_color(string, style, textColor, background):
string = "\033[{};{};{}m{}\033[m ".format(style,textColor,background,string)
print(string)
我想檢測當前的背景顏色並使用它而不是傳入它。
我試過不設置它,像這樣:
def print_color(string, style, textColor):
string = "\033[{};{};m{}\033[m ".format(style,textColor,string)
print(string)
但這並沒有像我預期的那樣奏效。
XFCE4終端使用VTE,對colors的查詢缺乏響應能力。 那將是DECRQSS的 SGR 風格,這在 VTE 中大多未實現。
(顯示的示例無論如何都不起作用)。 這與 GTK+ 工具包無關。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.