Various changes.
[python_utils.git] / text_utils.py
index 1a8fa18499193084db27f4be02e8a985f877fe1a..3be32ff49ec05b2d7ca0978e6cb34b65da64162e 100644 (file)
@@ -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: