- 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)
+ for line in text.split('\n'):
+ tw = len(string_utils.strip_ansi_sequences(line))
+ assert tw <= w
+ ret += color + '│ ' + rset + line + ' ' * (w - tw - 2) + color + ' │' + rset + '\n'
+ ret += color + '╰' + '─' * w + '╯' + rset + '\n'
+ return ret
+
+
+def print_box(
+ title: Optional[str] = None, text: Optional[str] = None, *, width: int = 80, color: str = ''
+) -> None:
+ """Draws a box with nice rounded corners.
+
+ >>> print_box('Title', 'This is text', width=30)
+ ╭────────────────────────────╮
+ │ Title │
+ │ │
+ │ This is text │
+ ╰────────────────────────────╯
+
+ >>> print_box(None, 'OK', width=6)
+ ╭────╮
+ │ OK │
+ ╰────╯
+
+ """
+ print(preformatted_box(title, text, width=width, color=color), end='')