summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2022-04-17 11:23:13 -0700
committerScott Gasch <[email protected]>2022-04-17 11:23:13 -0700
commite11d9b0958b2874bd67360552e9214d965fe0d12 (patch)
treeeb9e946f2c2f1bf57ac7704dce9adb9cb465f393
parentade09c17caf24b483525c99e61506bc5cd99a990 (diff)
Preformatted box that doesn't wrap the contents.
-rw-r--r--text_utils.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/text_utils.py b/text_utils.py
index f04c618..b426619 100644
--- a/text_utils.py
+++ b/text_utils.py
@@ -373,6 +373,15 @@ def box(
title: Optional[str] = None, text: Optional[str] = None, *, width: int = 80, color: str = ''
) -> str:
assert width > 4
+ if text is not None:
+ text = justify_text(text, width=width - 4, alignment='l')
+ return preformatted_box(title, text, width=width, color=color)
+
+
+def preformatted_box(
+ title: Optional[str] = None, text: Optional[str] = None, *, width=80, color: str = ''
+) -> str:
+ assert width > 4
ret = ''
if color == '':
rset = ''
@@ -393,9 +402,9 @@ def box(
)
ret += color + '│' + ' ' * w + '│' + rset + '\n'
if text is not None:
- for line in justify_text(text, width=w - 2, alignment='l').split('\n'):
+ for line in text.split('\n'):
tw = len(string_utils.strip_ansi_sequences(line))
- assert tw < w
+ assert tw <= w
ret += color + '│ ' + rset + line + ' ' * (w - tw - 2) + color + ' │' + rset + '\n'
ret += color + '╰' + '─' * w + '╯' + rset + '\n'
return ret