summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@posteo.net>2022-02-15 07:13:19 -0800
committerRose Hogenson <rhogenson@posteo.net>2022-02-15 07:13:19 -0800
commit08fef4b9ef771494bd2291edcfebf42b3d8ac5fd (patch)
tree477fa11c7d8378231d2c7220dc58e3ad14f1aa52
parenta906adb9ea2073ee9c23913585ff821558717ac8 (diff)
downloadgpt-adventure-08fef4b9ef771494bd2291edcfebf42b3d8ac5fd.tar.zst
Use real terminal width instead of assuming 72.
-rwxr-xr-xai_dungeon.py8
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))