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 |
| 颜色 | '' | 什么颜色可以制作文字。 | 'bold', 'black', 'blue', 'cyan', 'green', 'grey', 'magenta', 'red', 'white', 'yellow', 'black+bold', 'blue+bold', 'cyan+bold', 'green+bold', 'grey+bold', 'magenta+bold', 'red+bold', 'white+bold', 'yellow+bold' |
| 大胆的 | 错误的 | 文字应该大胆。可以在有或没有定义的颜色的情况下使用。 | 是的,错误 |
如果您将粗体添加到颜色中,则必须以颜色名称为之后。 EB CYAN+BOLD不是Bold+Cyan,因为这将导致例外。