简体   繁体   English

使用 python 从终端获取当前默认文本颜色

[英]Get current default text color from terminal using python

I am printing some data to the screen and I want to color code certain values.我正在将一些数据打印到屏幕上,我想对某些值进行颜色编码。 For example, if the number is above 100 , I want it to be red.例如,如果数字大于100 ,我希望它是红色的。 I can do this by printing "\033[91m {}\033[00m" to the line before the number as explained in this post .我可以通过将"\033[91m {}\033[00m"打印到数字之前的行来做到这一点,如本文所述。 I will need to go back to the 'default' color after that, however, but how do I know what the user's default color is?之后我需要将 go 恢复为“默认”颜色,但是我怎么知道用户的默认颜色是什么? I have my background as black and the text shows up as white, but for another user who has white background and black text, setting the text color back to 'white' will break.我的背景为黑色,文本显示为白色,但对于另一个拥有白色背景和黑色文本的用户,将文本颜色设置回“白色”将会中断。

Is there a way, in Python to find the user's current 'default' text color?有没有办法在Python中找到用户当前的“默认”文本颜色?

What I understood, is that u are asking to to get the default profile color of the user, of which u have change color of!我的理解是,您要求获取用户的默认配置文件颜色,您已经更改了其中的颜色!

Eg: User is using ' Bright Green font color on Black background ', you change it to ' Red font color on White background '.例如:用户正在使用“黑色背景上的亮绿色字体颜色”,您将其更改为“白色背景上的红色字体颜色”。 Now how to get/know the default colors and set them back to it!现在如何获取/了解默认值 colors 并将它们设置回默认值!


You can use the sequence \033[0m in python [also directly for terminal (bash scripting) or command prompt (batch scripting) / powershell (ps scripting)您可以在python中使用序列\033[0m [也可以直接用于终端(bash 脚本)或命令提示符(批处理脚本)/ powershell (ps 脚本)

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

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