Advertisement
kingjamez12

box

Dec 13th, 2019
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. """ Module boxed_msg1 that prints a box around text.
  2.  
  3. """
  4.  
  5. def box_msg(msg, indent=1, width=None, title=None):
  6. """Print message-box with optional title."""
  7. lines = msg.split('\n')
  8. space = " " * indent
  9.  
  10. if not width:
  11. width = max(map(len, lines))
  12. box = f'╔{"═" * (width + indent * 2)}╗\n' # upper_border
  13.  
  14. if title:
  15. box += f'║{space}{title:^{width}}{space}║\n' # title
  16. box += f'║{space}{"-" * width:<{width}}{space}║\n' # underscore
  17. box += ''.join([f'║{space}{line:<{width}}{space}║\n' for line in lines])
  18. box += f'╚{"═" * (width + indent * 2)}╝' # lower_border
  19. print(box)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement