From da396c235c0e977a60a33366b9f00d60760837c4 Mon Sep 17 00:00:00 2001 From: Jonathan van der Steege Date: Sun, 17 Jul 2022 15:11:18 +0200 Subject: [PATCH] Fix linewrap auto for fancy format --- jrnl/Entry.py | 5 ++--- jrnl/plugins/fancy_exporter.py | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/jrnl/Entry.py b/jrnl/Entry.py index 3c9a978c..6754072f 100644 --- a/jrnl/Entry.py +++ b/jrnl/Entry.py @@ -2,13 +2,12 @@ # License: https://www.gnu.org/licenses/gpl-3.0.html import datetime +import logging +import os import re import ansiwrap -import os -import logging - from .color import colorize from .color import highlight_tags_with_background_color diff --git a/jrnl/plugins/fancy_exporter.py b/jrnl/plugins/fancy_exporter.py index b9567bfd..e00d2a54 100644 --- a/jrnl/plugins/fancy_exporter.py +++ b/jrnl/plugins/fancy_exporter.py @@ -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 = [