|
|
|
|
@ -53,17 +53,6 @@ def wrap_text(text: str, width: int = 78) -> str:
|
|
|
|
|
return "\n\n".join(wrapped)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def truncate_letter(body: str, max_chars: int = 3000) -> str:
|
|
|
|
|
"""Truncate very long letters with an ellipsis note."""
|
|
|
|
|
if len(body) <= max_chars:
|
|
|
|
|
return body
|
|
|
|
|
truncated = body[:max_chars]
|
|
|
|
|
last_period = truncated.rfind(".")
|
|
|
|
|
if last_period > max_chars // 2:
|
|
|
|
|
truncated = truncated[: last_period + 1]
|
|
|
|
|
return truncated + "\n\n […letter continues…]"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def display_letter(letter: dict) -> None:
|
|
|
|
|
"""Pretty-print a single love letter to the terminal."""
|
|
|
|
|
print()
|
|
|
|
|
@ -75,8 +64,7 @@ def display_letter(letter: dict) -> None:
|
|
|
|
|
print(SEPARATOR)
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
|
|
body = truncate_letter(letter["body"])
|
|
|
|
|
print(wrap_text(body))
|
|
|
|
|
print(wrap_text(letter["body"]))
|
|
|
|
|
|
|
|
|
|
print()
|
|
|
|
|
print(SEPARATOR)
|
|
|
|
|
|