Add linewrap option 'auto' (#1507)

* Add linewrap option 'auto'

* Specify the exception thrown

* Add BDD test

* Specify name instead of number

* Create test for linewrap auto and fancy format

* Fix linewrap auto for fancy format
This commit is contained in:
Jonathan van der Steege 2022-07-30 21:22:04 +02:00 committed by GitHub
parent 252c63f4dd
commit 80bfff384e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 66 additions and 7 deletions

View file

@ -1,6 +1,8 @@
# Copyright (C) 2012-2022 jrnl contributors
# License: https://www.gnu.org/licenses/gpl-3.0.html
import logging
import os
from textwrap import TextWrapper
from jrnl.exception import JrnlException
@ -36,7 +38,22 @@ class FancyExporter(TextExporter):
def export_entry(cls, entry):
"""Returns a fancy unicode representation of a single entry."""
date_str = entry.date.strftime(entry.journal.config["timeformat"])
linewrap = entry.journal.config["linewrap"] or 78
if entry.journal.config["linewrap"]:
linewrap = entry.journal.config["linewrap"]
if linewrap == "auto":
try:
linewrap = os.get_terminal_size().columns
except OSError:
logging.debug(
"Can't determine terminal size automatically 'linewrap': '%s'",
entry.journal.config["linewrap"],
)
linewrap = 79
else:
linewrap = 79
initial_linewrap = max((1, linewrap - len(date_str) - 2))
body_linewrap = linewrap - 2
card = [