summaryrefslogtreecommitdiff
path: root/text_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'text_utils.py')
-rw-r--r--text_utils.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/text_utils.py b/text_utils.py
index 1a8fa18..3be32ff 100644
--- a/text_utils.py
+++ b/text_utils.py
@@ -169,6 +169,19 @@ def generate_padded_columns(text: List[str]) -> str:
yield out
+def wrap_string(text: str, n: int) -> str:
+ chunks = text.split()
+ out = ''
+ width = 0
+ for chunk in chunks:
+ if width + len(chunk) > n:
+ out += '\n'
+ width = 0
+ out += chunk + ' '
+ width += len(chunk) + 1
+ return out
+
+
class Indenter:
"""
with Indenter(pad_count = 8) as i: