diff --git a/.gitignore b/.gitignore index 73aa79d1..374deb4b 100644 --- a/.gitignore +++ b/.gitignore @@ -61,6 +61,3 @@ coverage.xml .coverage .vscode/tasks.json todo.txt - -tags -.vimrc \ No newline at end of file diff --git a/jrnl/exception.py b/jrnl/exception.py index bc299306..ac7cd0b2 100644 --- a/jrnl/exception.py +++ b/jrnl/exception.py @@ -33,8 +33,10 @@ class JrnlError(Exception): ), "LineWrapTooSmallForDateFormat": textwrap.dedent( """ - The provided linewrap value of {config_linewrap} is too small - to display the timestamps in the configured time format. + The provided linewrap value of {config_linewrap} is too small by {columns} columns + to display the timestamps in the configured time format for journal {journal}. + + You can avoid this error by specifying a linewrap value that is larger by at least {columns} in the configuration file or by using --config-override at the command line """ ), } diff --git a/jrnl/plugins/fancy_exporter.py b/jrnl/plugins/fancy_exporter.py index af6c19da..aae51f46 100644 --- a/jrnl/plugins/fancy_exporter.py +++ b/jrnl/plugins/fancy_exporter.py @@ -41,7 +41,8 @@ class FancyExporter(TextExporter): card = [ cls.border_a + cls.border_b * (initial_linewrap) + cls.border_c + date_str ] - cls.check_linewrap(linewrap, card) + check_provided_linewrap_viability(linewrap, card, entry.journal) + w = TextWrapper( width=initial_linewrap, initial_indent=cls.border_g + " ", @@ -75,14 +76,20 @@ class FancyExporter(TextExporter): card.append(cls.border_l + cls.border_b * body_linewrap + cls.border_m) return "\n".join(card) - @classmethod - def check_linewrap(cls, linewrap, card): - if len(card[0]) > linewrap: - raise JrnlError("LineWrapTooSmallForDateFormat", config_linewrap=linewrap) - else: - pass - @classmethod def export_journal(cls, journal): """Returns a unicode representation of an entire journal.""" return "\n".join(cls.export_entry(entry) for entry in journal) + + +def check_provided_linewrap_viability(linewrap, card, journal): + if len(card[0]) > linewrap: + width_violation = len(card[0]) - linewrap + raise JrnlError( + "LineWrapTooSmallForDateFormat", + config_linewrap=linewrap, + columns=width_violation, + journal=journal, + ) + else: + pass diff --git a/tests/test_export.py b/tests/test_export.py index 6419acb8..6cd2db61 100644 --- a/tests/test_export.py +++ b/tests/test_export.py @@ -1,6 +1,5 @@ from jrnl.exception import JrnlError -from jrnl.plugins.fancy_exporter import FancyExporter - +from jrnl.plugins.fancy_exporter import check_provided_linewrap_viability import pytest @@ -30,10 +29,11 @@ def build_card_header(datestr): class TestFancy: def test_too_small_linewrap(self, datestr): + journal = "test_journal" content = build_card_header(datestr) total_linewrap = 12 with pytest.raises(JrnlError) as e: - FancyExporter.check_linewrap(total_linewrap, [content]) + check_provided_linewrap_viability(total_linewrap, [content], journal) assert e.value.error_type == "LineWrapTooSmallForDateFormat"