Improve the readability and appearance of your print statements.
If you would rather take a look at the code instead of the documentation, open directly the example.py
file.
Import the CLIPrintTool
class from cli_print_tool.py
from cli_print_tool import CLIPrintTool
(Optional) Import the TextAlignment
class from cli_print_tool.py
to change the text alignment (by default left-aligned).
from cli_print_tool import CLIPrintTool, TextAlignment
Create a CLIPrintTool
object.
CLIPrintTool()
(Optional) Specify the maximum line length for your content (by default 100 characters).
CLIPrintTool(120) # custom max length of 120 characters
Use the public methods from CLIPrintTool
to print your formatted text content.
CLIPrintTool().textbox("Hello World!")
Takes two parameters and prints long text wrapped to respect the maximum line length.
Parameter | Type | Required | Default Value |
---|---|---|---|
text | String | Yes | None |
alignment | TextAlignment | No | TextAlignment.left |
Prints long text wrapped to respect the maximum line length and left-aligned.
long_text = "This is a very very very very very long sentence. And here is another one, but don't worry about that \
CLIPrintTool will automatically wrap the text to respect the maximum line length (by default 100 characters)."
CLIPrintTool().text(long_text)
Prints long text wrapped to respect the maximum line length and centered.
Note: The TextAlignment
class needs to be imported from cli_print_tool.py
to change the text alignment.
long_text = "This is a very very very very very long sentence. And here is another one, but don't worry about that \
CLIPrintTool will automatically wrap the text to respect the maximum line length (by default 100 characters)."
CLIPrintTool().text(long_text, TextAlignment.center)
Prints long text wrapped to respect the maximum line length and right-aligned.
Note: The TextAlignment
class needs to be imported from cli_print_tool.py
to change the text alignment.
long_text = "This is a very very very very very long sentence. And here is another one, but don't worry about that \
CLIPrintTool will automatically wrap the text to respect the maximum line length (by default 100 characters)."
CLIPrintTool().text(long_text, TextAlignment.right)
Takes two parameters and prints text inside a box.
Parameter | Type | Required | Default Value |
---|---|---|---|
text | String | Yes | None |
alignment | TextAlignment | No | TextAlignment.left |
Prints text inside a box and left-aligned.
CLIPrintTool().textbox("The quick, brown fox jumps over a lazy dog.")
Prints text inside a box and centered.
Note: The TextAlignment
class needs to be imported from cli_print_tool.py
to change the text alignment.
CLIPrintTool().textbox("The quick, brown fox jumps over a lazy dog.", TextAlignment.center)
Prints text inside a box and right-aligned.
Note: The TextAlignment
class needs to be imported from cli_print_tool.py
to change the text alignment.
CLIPrintTool().textbox("The quick, brown fox jumps over a lazy dog.", TextAlignment.right)
Takes four parameters and prints two texts vertically separated by a line (divider).
Alignment of title and subtitle could be optionally altered using the TextAlignment
enum.
Parameter | Type | Required | Default Value |
---|---|---|---|
title | String | Yes | None |
subtitle | String | Yes | None |
title_alignment | TextAlignment | No | TextAlignment.left |
subtitle_alignment | TextAlignment | No | TextAlignment.left |
Prints two texts vertically separated by a line (divider) and left-aligned.
CLIPrintTool().heading("This is a Title", "This is a Subtitle")
Prints two texts vertically separated by a line (divider) and centered.
Note: The TextAlignment
class needs to be imported from cli_print_tool.py
to change the text alignment.
CLIPrintTool().heading("This is a Title", "This is a Subtitle", TextAlignment.center, TextAlignment.center)
Prints two texts vertically separated by a line (divider) and right-aligned.
Note: The TextAlignment
class needs to be imported from cli_print_tool.py
to change the text alignment.
CLIPrintTool().heading("This is a Title", "This is a Subtitle", TextAlignment.right, TextAlignment.right)
Prints two texts separated by a line (divider), with title vertically centred, and subtitle left-aligned.
Note: The TextAlignment
class needs to be imported from cli_print_tool.py
to change the text alignment.
CLIPrintTool().heading("This is a Title", "This is a Subtitle", TextAlignment.center, TextAlignment.left)
Takes four parameters and prints a list of elements vertically with a title (optional).
Alignment of elements and title could be optionally altered using the TextAlignment
enum.
Note: Blank lines can be added between elements by using the CLIPrintTool.NEW_LINE
constant. To see how it's used, refer to example 4.1.
Parameter | Type | Required | Default Value |
---|---|---|---|
elements | List of String | Yes | None |
title | String | No | "" |
title_alignment | TextAlignment | No | TextAlignment.left |
elements_alignment | TextAlignment | No | TextAlignment.left |
Prints a list of elements vertically without title and left-aligned.
CLIPrintTool().list(["System Information", "Crash Reports", "Exit"])
Prints a list of elements vertically without title and centered.
Note: The TextAlignment
class needs to be imported from cli_print_tool.py
to change the text alignment.
CLIPrintTool().list(["System Information", "Crash Reports", "Exit"], elements_alignment=TextAlignment.center)
Prints a list of elements vertically without title and right-aligned.
Note: The TextAlignment
class needs to be imported from cli_print_tool.py
to change the text alignment.
CLIPrintTool().list(["System Information", "Crash Reports", "Exit"], elements_alignment=TextAlignment.right)
Prints a list of elements vertically with title and left-aligned.
CLIPrintTool().list(["System Information", "Crash Reports", "Exit"], "MAIN MENU")
Prints a list of elements vertically with title and left-aligned.
Note: The CLIPrintTool.NEW_LINE
constant was added inside our list of menu options to display a blank line.
menu_options = ["System Information", "Crash Reports", CLIPrintTool.NEW_LINE, "Exit"]
CLIPrintTool().list(menu_options, "MAIN MENU")
Prints a list of elements vertically with title and centered.
Note: The TextAlignment
class needs to be imported from cli_print_tool.py
to change the text alignment.
CLIPrintTool().list(["System Information", "Crash Reports", "Exit"], "MAIN MENU", TextAlignment.center, TextAlignment.center)
Prints a list of elements vertically with title and right-aligned.
Note: The TextAlignment
class needs to be imported from cli_print_tool.py
to change the text alignment.
CLIPrintTool().list(["System Information", "Crash Reports", "Exit"], "MAIN MENU", TextAlignment.right, TextAlignment.right)
Prints a list of elements left-aligned, with title center-aligned.
Note: The TextAlignment
class needs to be imported from cli_print_tool.py
to change the text alignment.
CLIPrintTool().list(["System Information", "Crash Reports", "Exit"], "MAIN MENU", TextAlignment.center)