diff options
| author | Scott Gasch <[email protected]> | 2021-09-07 22:20:40 -0700 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2021-09-07 22:20:40 -0700 |
| commit | b10d30a46e601c9ee1f843241f2d69a1f90f7a94 (patch) | |
| tree | 30c95e6f4333b57ff3ae7a4dee278b2097612d10 /text_utils.py | |
| parent | f49bb9db0c6d1a8622dca1717db68462a4209112 (diff) | |
Various changes.
Diffstat (limited to 'text_utils.py')
| -rw-r--r-- | text_utils.py | 13 |
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: |
