diff options
| -rwxr-xr-x | ai_dungeon.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/ai_dungeon.py b/ai_dungeon.py index 58ad206..eb44a87 100755 --- a/ai_dungeon.py +++ b/ai_dungeon.py @@ -4,6 +4,7 @@ import argparse import re +import shutil import sys import nltk @@ -82,15 +83,16 @@ def pick_flavor() -> str: def wrap(message: str) -> str: - """Wrap long lines to 72 characters.""" + """Wrap long lines to terminal width characters.""" + width = shutil.get_terminal_size().columns res = [] for line in message.split("\n"): - if len(line) < 72: + if len(line) < width: res.append(line) continue split_line = [] for word in line.split(" "): - if not split_line or len(" ".join(split_line)) + len(word) < 72: + if not split_line or len(" ".join(split_line)) + len(word) < width: split_line.append(word) continue res.append(" ".join(split_line)) |
