Created
December 25, 2012 02:30
-
-
Save jfinstrom/4371405 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def boxtext(msg): | |
lines = msg.split("\n") | |
width = len(max(lines, key=len))+4 | |
topline = u"\u2554" + u"\u2550"*width + u"\u2557"+"\n" | |
side = u"\u2551" | |
bottom = u"\u255a"+ u"\u2550"*width + u"\u255d"+"\n" | |
box = topline | |
for l in lines: | |
if len(l)<2: | |
continue | |
pad = (width - len(l))/2 | |
box += side | |
box += " "*pad | |
box += l | |
if (len(l) % 2) > 0: | |
box += " " * pad | |
else: | |
box += " " * (pad+1) | |
box += side + "\n" | |
box += bottom | |
return box |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
╔═════════════════════════════════════════════════════════════════════════╗ | |
║ Lorem ipsum dolor sit amet, consectetur adipiscing elit. ║ | |
║ Suspendisse sed magna auctor justo dapibus lacinia in interdum purus. ║ | |
║ Cras ut elit porttitor purus commodo sollicitudin at id metus. ║ | |
║ Vestibulum vehicula sem non nibh cursus rutrum. Nulla nec felis ║ | |
║ gravida ante cursus placerat a vel odio. In quis nulla tristique ║ | |
║ odio tristique porttitor sit amet a enim. Etiam turpis purus, ║ | |
║ laoreet vitae mattis quis, suscipit mattis ante. Duis ac felis dolor. ║ | |
║ In hac habitasse platea dictumst. ║ | |
╚═════════════════════════════════════════════════════════════════════════╝ | |
// On a console there is no gap on the sides... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, jfinstrom. I'm using this app for one program. I can't find out the way to center the box in the console. Could you help me? Thanks.