Untitled
unknown
plain_text
2 years ago
1.7 kB
6
Indexable
import textwrap
def print_header(library_name: str, version: str, description: str, author: str, max_width: int = 60) -> None:
"""
Prints a well-formatted header for your Python library with a decorative box and text wrapping.
Args:
library_name (str): The name of your library.
version (str): The version of your library.
description (str): A brief description of your library's functionality (wrapped to fit within max_width).
author (str): The author or maintainer of the library.
max_width (int, optional): The maximum width for text wrapping. Defaults to 60.
"""
corner = "╭" # Top left corner
top_border = "─" * (max_width + 4) # Top border with padding
bottom_border = top_border
side_border = "│" # Side border
# Wrap description using textwrap
wrapped_description = textwrap.fill(description, width=max_width - 6) # Account for side borders
header_lines = [
f"{corner}{top_border}{corner}",
f"{side_border} {library_name} v{version} {side_border}",
f"{side_border} {wrapped_description} {side_border}",
f"{side_border} by {author} {side_border}",
f"{corner}{bottom_border}{corner}",
]
print("\n".join(header_lines))
# Example usage
library_name = "My Awesome Library with a Very Long Name That Needs Wrapping"
version = "1.0.0"
description = "This is a library for simplifying complex tasks. It can handle various operations and make your code more efficient. It's incredibly useful for data manipulation and automation." # Test longer content
author = "Your Name"
print_header(library_name, version, description, author)
Editor is loading...
Leave a Comment