From b10d30a46e601c9ee1f843241f2d69a1f90f7a94 Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Tue, 7 Sep 2021 22:20:40 -0700 Subject: Various changes. --- text_utils.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'text_utils.py') 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: -- cgit v1.3