Overview
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.
Features
- 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.
Installation
pip install wolfsoftware.drawlines
Usage
The main functionality is provided by the draw_line function, which can be used to create lines in the terminal with or without text.
Function Signature
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.
"""
Examples
1. Simple line with default settings
from your_module import draw_line
# Draw a simple dashed line
print(draw_line())
Output
------------------------------------------------------------------------------------------
2. Line with centered text and custom color
# Draw a line with centered text
print(draw_line(text="Hello, World!", position='center'))
Output
------------------------------------- Hello, World! --------------------------------------
If you set the
fill_char=' 'you will simply get centered text with no line.
3. Line with left-aligned text and custom fill character
# Draw a line with left-aligned text and asterisk fill character
print(draw_line(text="Left aligned text", position='left', fill_char='*'))
Output
** Left aligned text *********************************************************************
Customization
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:
| Name | Default Value | Purpose | Allowed Values |
|---|---|---|---|
| text | '' | Any string you want to display within the line. | Any string |
| position | 'center' | Where to place the text. | 'left', 'center', 'right' |
| fill_char | '-' | The character to use when drawing the line. If more than one is given, only the first is used. | Any single character |
| left_pad | 2 | How many fill_chars to use as a prefix when aligning the text left. | Any positive integer |
| right_pad | 2 | How many fill_chars to use as a postfix when aligning the text right. | Any positive integer |
| width | -1 | How wide to draw the line. Defaults to the terminal's width minus one if not specified. | Any integer; -1 for terminal width minus 1 |
| color | '' | What color to make the text. | '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' |
| bold | False | Should the text be bold. This can be used with or without a defined color. | True, False |
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.
Release files for wolfsoftware.drawlines 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| wolfsoftware_drawlines-0.1.3.tar.gz | 10.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| wolfsoftware.drawlines-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.6 kB
Release files / wolfsoftware_drawlines-0.1.3.tar.gz
| Download URL | wolfsoftware_drawlines-0.1.3.tar.gz |
|---|---|
| Size | 10.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c3bcd700d42071dd12ce5192ced291be3025766117480d6cbb1050c065df6832
|
|
BLAKE2b-256 checksum How to use checksums |
94f35a605239d3f77c14fca3d12eced123f2e0f53131dd79fe39dc3f2ad135f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Release files / wolfsoftware.drawlines-0.1.3-py3-none-any.whl
| Download URL | wolfsoftware.drawlines-0.1.3-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8cec821923878d5b5bce18dceb47308e5bf21cff57ae7d64b48431e56a5dba85
|
|
BLAKE2b-256 checksum How to use checksums |
d92b58d3b4bee741cba471ca7603106762e3dd480f4a29939fed6aac0221285d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|