draw lines package
v0.1.3
โมดูล Python สำหรับการวาดเส้นสไตล์และสีในเทอร์มินัล ยูทิลิตี้นี้ช่วยให้สามารถปรับแต่งรูปแบบบรรทัดสีและการวางตำแหน่งข้อความทำให้เป็นเครื่องมืออเนกประสงค์สำหรับการเพิ่มเอาต์พุตของแอปพลิเคชัน CLI
colorama สำหรับการจัดการสีและสไตล์เพื่อให้มั่นใจว่าเข้ากันได้กับระบบปฏิบัติการที่แตกต่างกัน pip install wolfsoftware.drawlines ฟังก์ชั่นหลักมีให้โดยฟังก์ชัน draw_line ซึ่งสามารถใช้ในการสร้างบรรทัดในเทอร์มินัลที่มีหรือไม่มีข้อความ
def draw_line ( text = '' , position = 'center' , fill_char = '-' , pad = 2 , width = - 1 , color = '' ):
"""
Draw a line across the terminal with optional text.
Args:
text (str): Text to include in the line. Defaults to '' (no text).
position (str): Position of the text ('left', 'right', 'center'). Defaults to 'center'.
fill_char (str): Character used to fill the line. Defaults to '-'.
pad (int): Padding characters around the text. Defaults to 2.
width (int): Total width of the line; defaults to the terminal width if set to -1.
color (str): Color and style of the text, e.g., 'red', 'blue+bold'. Defaults to no color.
""" from your_module import draw_line
# Draw a simple dashed line
print ( draw_line ())------------------------------------------------------------------------------------------ # Draw a line with centered text
print ( draw_line ( text = "Hello, World!" , position = 'center' ))------------------------------------- Hello, World ! --------------------------------------หากคุณตั้งค่า
fill_char=' 'คุณจะได้รับข้อความที่เป็นศูนย์กลางโดยไม่มีบรรทัด
# Draw a line with left-aligned text and asterisk fill character
print ( draw_line ( text = "Left aligned text" , position = 'left' , fill_char = '*' )) ** Left aligned text ********************************************************************* ส่วนนี้ให้รายละเอียดเกี่ยวกับวิธีที่คุณสามารถปรับแต่งพารามิเตอร์ฟังก์ชัน draw_line ด้านล่างคือตารางที่แสดงรายการแต่ละพารามิเตอร์ค่าเริ่มต้นวัตถุประสงค์และค่าที่อนุญาต:
| ชื่อ | ค่าเริ่มต้น | วัตถุประสงค์ | ค่าที่อนุญาต |
|---|---|---|---|
| ข้อความ | - | สตริงใด ๆ ที่คุณต้องการแสดงภายในบรรทัด | สตริงใด ๆ |
| ตำแหน่ง | 'ศูนย์' | สถานที่วางข้อความ | 'ซ้าย', 'กึ่งกลาง', 'ขวา' |
| Fill_char | - | อักขระที่จะใช้เมื่อวาดเส้น หากได้รับมากกว่าหนึ่งรายการจะใช้เฉพาะครั้งแรก | ตัวละครตัวเดียว |
| ซ้าย _pad | 2 | Fill_chars ใช้กี่คำนำเมื่อจัดเรียงข้อความที่เหลือ | จำนวนเต็มบวกใด ๆ |
| right_pad | 2 | Fill_chars ใช้กี่ postfix เมื่อจัดตำแหน่งข้อความที่ถูกต้อง | จำนวนเต็มบวกใด ๆ |
| ความกว้าง | -1 | การวาดเส้นกว้างแค่ไหน ค่าเริ่มต้นไปยังความกว้างของเทอร์มินัลลบหนึ่งหากไม่ได้ระบุ | จำนวนเต็มใด ๆ ; -1 สำหรับความกว้างเทอร์มินัลลบ 1 |
| สี | - | สีอะไรที่จะสร้างข้อความ | 'bold', 'ดำ', 'สีน้ำเงิน', 'Cyan', 'Green', 'Grey', 'Magenta', 'Red', 'White', 'Yellow', 'Black+Bold', 'Blue+Bold', 'Cyan+Bold', 'Green+Bold', 'Grey+Bold', 'Magenta+Bold' |
| ตัวหนา | เท็จ | ข้อความควรเป็นตัวหนา สามารถใช้กับหรือไม่มีสีที่กำหนด | จริงเท็จ |
หากคุณกำลังเพิ่มตัวหนาเป็นสีมัน จะต้อง มาหลังจากชื่อสี EB Cyan+Bold Not Bold+Cyan เพราะจะทำให้เกิดข้อยกเว้นที่จะโยน