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 | ' - ' | 繪製線路時要使用的字符。如果給出了多個,則僅使用第一個。 | 任何一個字符 |
| left_pad | 2 | 在對齊左文本時,有多少個填充_chars用作前綴。 | 任何積極的整數 |
| right_pad | 2 | 正確對齊文本時,有多少個填充_chars用作後綴。 | 任何積極的整數 |
| 寬度 | -1 | 繪製線路的寬度。如果未指定,則默認為終端的寬度減去一個。 | 任何整數; -1對於端子寬度負1 |
| 顏色 | '' | 什麼顏色可以製作文字。 | “大膽”,“黑色”,“藍色”,“藍色”,“綠色”,“灰色”,“洋紅色”,“紅色”,“紅色”,“白色”,“黃色”,“黑色+大膽”,“藍色+大膽”,“藍色+大膽”,“綠色+大膽”,“灰色+大膽”,“灰色+大膽',' |
| 大膽的 | 錯誤的 | 文字應該大膽。可以在有或沒有定義的顏色的情況下使用。 | 是的,錯誤 |
如果您將粗體添加到顏色中,則必須以顏色名稱為之後。 EB CYAN+BOLD不是Bold+Cyan,因為這將導致例外。