+def box(
+ title: Optional[str] = None, text: Optional[str] = None, *, width: int = 80, color: str = ''
+):
+ """Draws a box with nice rounded corners.
+
+ >>> box('Title', 'This is text', width=30)
+ ╭────────────────────────────╮
+ │ Title │
+ │ │
+ │ This is text │
+ ╰────────────────────────────╯
+
+ """
+ assert width > 4
+ if color == '':
+ rset = ''
+ else:
+ rset = reset()
+ w = width - 2
+ print(color + '╭' + '─' * w + '╮' + rset)
+ if title is not None:
+ print(
+ color + '│' + rset + justify_string(title, width=w, alignment='c') + color + '│' + rset
+ )
+ print(color + '│' + ' ' * w + '│' + rset)
+ if text is not None:
+ for line in justify_text(text, width=w - 2, alignment='l').split('\n'):
+ tw = len(line)
+ assert tw < w
+ print(color + '│ ' + rset + line + ' ' * (w - tw - 2) + color + ' │' + rset)
+ print(color + '╰' + '─' * w + '╯' + rset)
+
+