term printer
v1.1
طباعة "لون النص" و "تنسيق النص" على المصطلح مع بيثون
※ قد لا يعمل اعتمادًا على نظام التشغيل والقذيفة المستخدمة.
$ pip install term-printer from term_printer import Color , Color256 , ColorRGB , StdText , cprint إذا كنت ترغب في تجاوز وظيفة print Bultin
from term_printer import Color , Color256 , ColorRGB , StdText , cprint as print ينطبق على جميع الأحرف.
يمكنك تحديد Format Color Color256 و ColorRGB .
قادر على تحديد أكثر من واحد.
from term_printer import Color , Color256 , ColorRGB , Format , cprint
# default
cprint ( "this is a default pen" )
# bold
cprint ( "this is a bold pen" , attrs = [ Format . BOLD ])
# italic
cprint ( "this is a italic pen" , attrs = [ Format . ITALIC ])
# red color
cprint ( "this is a red pen" , attrs = [ Color . RED ])
# bright red color
cprint ( "this is a bright red pen" , attrs = [ Color . BRIGHT_RED ])
# background magenta color
cprint ( "this is a bg magenta pen" , attrs = [ Color . BG_MAGENTA ])
# background bright magenta color
cprint ( "this is a bg bright magenta pen" , attrs = [ Color . BG_BRIGHT_MAGENTA ])
# magenta color & italic
cprint ( "this is a magenta italic pen" , attrs = [ Color . MAGENTA , Format . ITALIC ])
# bold & italic
cprint ( "this is a bold italic pen" , attrs = [ Format . BOLD , Format . ITALIC ])
# cyan color & bold & italic
cprint ( "this is a cyan bold italic pen" , attrs = [ Color . CYAN , Format . BOLD , Format . ITALIC ])
# 8-bit color 154
cprint ( "this is a 8-bit 154 pen" , attrs = [ Color256 ( 154 )])
# 8-bit bg color 154 and magenta color
cprint ( "this is a bg 8-bit 154 pen" , attrs = [ Color256 ( 154 , is_bg = True ), Color . MAGENTA ])
# rgb(100, 255, 255) color
cprint ( "this is a rgb(100, 255, 255) pen" , attrs = [ ColorRGB ( 100 , 255 , 255 )])
# bg rgb(100, 255, 255) color and black color
cprint (
"this is a bg rgb(100, 255, 255) pen" ,
attrs = [ ColorRGB ( 100 , 255 , 255 , is_bg = True ), Color . BLACK ],
) from term_printer import Color , Format , StdText , cprint
# default
cprint ( "this is a default pen" )
# bold
cprint ( f"this is a { StdText ( 'bold' , Format . BOLD ) } pen" )
# italic
cprint ( f"this is a { StdText ( 'italic' , Format . ITALIC ) } pen" )
# reverse
cprint ( f"this is a { StdText ( 'reverse' , Format . REVERSE ) } pen" )
# red color
cprint ( f"this is a { StdText ( 'red' , Color . RED ) } pen" )
# background magenta color
cprint ( f"this is a { StdText ( 'bg magenta' , Color . BG_MAGENTA ) } pen" )
# magenta color & italic
cprint ( f"this is a { StdText ( 'magenta' , Color . MAGENTA ) } { StdText ( 'italic' , Format . ITALIC ) } pen" )
# bold & italic
cprint ( f"this is a { StdText ( 'bold' , Format . BOLD ) } { StdText ( 'italic' , Format . ITALIC ) } pen" )
# cyan color & bold & italic
cprint ( f"this is a { StdText ( 'cyan' , Color . CYAN ) } { StdText ( 'bold' , Format . BOLD ) } { StdText ( 'italic' , Format . ITALIC ) } pen" ) class Color ( Enum )تعداد فئة.
مثال
from term_printer import Color
Color . RED # RED foreground color
Color . BG_RED # RED background color
Color . BLUE # BLUE foreground color
Color . BG_BLUE # BLUE background colorالتعريف بألوان 3 بت و 4 بت
class Color256 ( n : int , is_bg : bool = False ) الحجة الأولى تأخذ int (0 - 255).
الحجة الثانية تأخذ bool (الافتراضي: خطأ).
خطأ: تغيير اللون الأمامي
صحيح: تغيير لون الخلفية
مثال
from term_printer import Color256
Color256 ( 9 ) # RED foreground color
Color256 ( 9 , True ) # RED background color
Color256 ( 12 ) # BLUE foreground color
Color256 ( 12 , True ) # BLUE background colorالتعريف هو 8 بت 256 لون
class ColorRGB ( r : int , g : int , b : int , is_bg : bool = False ) ثلاث حجج تأخذ int (0 - 255).
الحجة الرابعة تأخذ bool (افتراضي: خطأ).
خطأ: تغيير اللون الأمامي
صحيح: تغيير لون الخلفية
مثال
from term_printer import ColorRGB
ColorRGB ( 255 , 0 , 0 ) # RED foreground color
ColorRGB ( 255 , 0 , 0 , True ) # RED background color
ColorRGB ( 0 , 0 , 255 ) # BLUE foreground color
ColorRGB ( 0 , 0 , 255 , True ) # BLUE background color class Format ( Enum ):
BOLD = 1
FAINT = 2
ITALIC = 3
UNDERLINE = 4
BLINK = 5
FAST_BLINK = 6
REVERSE = 7
CONCEAL = 8
STRIKE = 9تعداد فئة.
مثال
from term_printer import Format
Format . BOLD # BOLD font
Format . FAINT # FAINT font
Format . ITALIC # ITALIC font
Format . UNDERLINE # UNDERLINE fontالتعريف هو SGR