A Python module for drawing styled and colored lines in the terminal. This utility allows for the customization of line styles, colors, and text positioning, making it a versatile tool for enhancing the output of CLI applications.
- Customizable text positions: left, right, or center.
- Support for various text colors and styles including bold.
- Adjustable line width and padding.
- Uses
coloramafor color and style handling, ensuring compatibility across different operating systems.
pip install wolfsoftware.drawlinesThe main functionality is provided by the draw_line function, which can be used to create lines in the terminal with or without text.
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! --------------------------------------If you set the
fill_char=' 'you will simply get centered text with no line.
# 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 *********************************************************************This section provides details on how you can customize the draw_line function parameters. Below is a table listing each parameter, its default value, purpose, and allowed values:
If you are adding bold to a color it must come after the color name. E.b. cyan+bold NOT bold+cyan as this will cause an exception to be thrown.
