Boxn

Python script to detect the width of your text and put a box around it

#!/usr/bin/env python3
import sys
lines = [line.rstrip("\n") for line in sys.stdin]
if not lines:
    sys.exit()
width = len(lines[0])
for n, line in enumerate(lines, 1):
    if len(line) > width:
        sys.exit(f"Line {n} is {len(line)} characters, exceeds box width {width}")
print("+" + "-" * (width + 2) + "+")
for line in lines:
    print(f"| {line:<{width}} |")
print("+" + "-" * (width + 2) + "+")

Unknown's avatar

About Linuxgal

Need a spiritual home? Consider joining us at Mary Queen of the Universe Latter-day Buddhislamic Free Will Christian UFO Synagogue of Vishnu
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a comment