Fix linewrap auto for fancy format

This commit is contained in:
Jonathan van der Steege 2022-07-17 15:11:18 +02:00
parent 3ae0ac501a
commit da396c235c
2 changed files with 20 additions and 4 deletions

View file

@ -2,13 +2,12 @@
# License: https://www.gnu.org/licenses/gpl-3.0.html # License: https://www.gnu.org/licenses/gpl-3.0.html
import datetime import datetime
import logging
import os
import re import re
import ansiwrap import ansiwrap
import os
import logging
from .color import colorize from .color import colorize
from .color import highlight_tags_with_background_color from .color import highlight_tags_with_background_color

View file

@ -1,6 +1,8 @@
# Copyright (C) 2012-2022 jrnl contributors # Copyright (C) 2012-2022 jrnl contributors
# License: https://www.gnu.org/licenses/gpl-3.0.html # License: https://www.gnu.org/licenses/gpl-3.0.html
import logging
import os
from textwrap import TextWrapper from textwrap import TextWrapper
from jrnl.exception import JrnlException from jrnl.exception import JrnlException
@ -36,7 +38,22 @@ class FancyExporter(TextExporter):
def export_entry(cls, entry): def export_entry(cls, entry):
"""Returns a fancy unicode representation of a single entry.""" """Returns a fancy unicode representation of a single entry."""
date_str = entry.date.strftime(entry.journal.config["timeformat"]) 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)) initial_linewrap = max((1, linewrap - len(date_str) - 2))
body_linewrap = linewrap - 2 body_linewrap = linewrap - 2
card = [ card = [