Inglés | 中文
Es un paquete simple para personalizar el color de impresión de la consola.
Pypi: https://pypi.org/project/colorprt/

Agregamos una configuración de color predeterminada en nuestro paquete.
from colorprt . default import warn_color , success_color , error_color
warn_color . print ( "Print a warn message" )
success_color . print ( "Print a success message" )
error_color . print ( "Print an error message" ) Descubrimos que algunas personas usan este paquete en el servidor Linux, para que no haya finalizaciones automáticas. Se preocupará a los usuarios. Por lo tanto, agregamos una característica que no necesita escribir: mode= ; foreground= ; background=
Simplemente llame a funciones o clase como esta:
En versiones antiguas:
from colorprt import colorprt , Back , Fore
# CAUTION: Do not use this after version: 3.0.0
colorprt ( "Hello World" , backgound = Back . RED )Utilice nuevas funciones:
from colorprt import colorprt , Back , Fore
colorprt ( "Hello World" , Back . RED , Fore . YELLOW )pip install colorprt La función colorprt es una extensión de la función print . Puede personalizar el estilo de impresión.
from colorprt import colorprt , Back , Fore
hello_else = "Hello Michael"
colorprt ( "Hello World" , hello_else , Back . RED , Fore . BLUE end = "x100 times n " )
Además, puede usar la clase ColorprtConfig para establecer cadenas de colores.
from colorprt import ColorprtConfig , Mode , Back , Fore
pycolor_config = ColorprtConfig ( Mode . BOLD , Back . DEFAULT , Fore . RED )
# You can use ColorprtConfig to set a color string configuration
colored_formatted_str = pycolor_config ( "I love You!!" )
print ( colored_formatted_str )
# or just use print method
pycolor_config . print ( "I love you!!" , end = "x10086 n " ) Si solo desea las cadenas formateadas de color ANSI, puede usar la clase colorstr .
from colorprt import colorstr , Mode , Back , Fore , ColorprtConfig
hate_print_config = ColorprtConfig ( Mode . UNDER_LINE , Back . DEFAULT , Fore . YELLOW )
print ( colorstr ( "I love You!!" , Mode . BOLD , Back . DEFAULT , Fore . RED )
+ colorstr ( "I hate you" , hate_print_config ))Si usa str () para forzar el cambio a la cadena. Conseguirás
>>> str(colorstr("I love You!!", Mode.BOLD, Back.DEFAULT, Fore.RED)
+ colorstr("I hate you", hate_print_config))
>>> 'x1b[0mx1b[1;31mI love You!!x1b[0mx1b[4;33mI hate youx1b[0mx1b[0m'
from colorprt import colorstr , Mode , Back , Fore , ColorprtConfig
hate_print_config = ColorprtConfig ( Mode . UNDER_LINE , Back . DEFAULT , Fore . YELLOW )
output = str ( colorstr ( 'I hate You' , hate_print_config ))