diff options
| author | Rose Hogenson <rhogenson@posteo.net> | 2022-02-15 07:13:19 -0800 |
|---|---|---|
| committer | Rose Hogenson <rhogenson@posteo.net> | 2022-02-15 07:13:19 -0800 |
| commit | 08fef4b9ef771494bd2291edcfebf42b3d8ac5fd (patch) | |
| tree | 477fa11c7d8378231d2c7220dc58e3ad14f1aa52 /ai_dungeon.py | |
| parent | Auto-download nltk packages if they're missing. (diff) | |
| download | gpt-adventure-08fef4b9ef771494bd2291edcfebf42b3d8ac5fd.tar.zst | |
Use real terminal width instead of assuming 72.
Diffstat (limited to 'ai_dungeon.py')
| -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)) |
