From 08c366d95073c6aa232fe5287316ea64a305e23a Mon Sep 17 00:00:00 2001 From: Kevin Date: Sat, 30 Jul 2022 12:16:56 -0700 Subject: [PATCH 1/7] Fixed index out of range error in fancy exporter (#1522) --- jrnl/plugins/fancy_exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jrnl/plugins/fancy_exporter.py b/jrnl/plugins/fancy_exporter.py index b9567bfd..a1e31869 100644 --- a/jrnl/plugins/fancy_exporter.py +++ b/jrnl/plugins/fancy_exporter.py @@ -50,7 +50,7 @@ class FancyExporter(TextExporter): subsequent_indent=cls.border_g + " ", ) - title_lines = w.wrap(entry.title) + title_lines = w.wrap(entry.title) or [""] card.append( title_lines[0].ljust(initial_linewrap + 1) + cls.border_d From 252c63f4dd4ffc1a79d4c8d2507064a0b2cf180b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 30 Jul 2022 12:20:50 -0700 Subject: [PATCH 2/7] Bump yq from 3.0.2 to 3.1.0 (#1546) Bumps [yq](https://github.com/kislyuk/yq) from 3.0.2 to 3.1.0. - [Release notes](https://github.com/kislyuk/yq/releases) - [Changelog](https://github.com/kislyuk/yq/blob/develop/Changes.rst) - [Commits](https://github.com/kislyuk/yq/compare/v3.0.2...v3.1.0) --- updated-dependencies: - dependency-name: yq dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- poetry.lock | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/poetry.lock b/poetry.lock index 64985299..8adad950 100644 --- a/poetry.lock +++ b/poetry.lock @@ -26,7 +26,7 @@ optional = false python-versions = ">=3.6" [package.extras] -test = ["coverage", "flake8", "pexpect", "wheel"] +test = ["wheel", "pexpect", "flake8", "coverage"] [[package]] name = "asttokens" @@ -133,7 +133,7 @@ optional = false python-versions = "*" [package.extras] -test = ["flake8 (==3.7.8)", "hypothesis (==3.55.3)"] +test = ["hypothesis (==3.55.3)", "flake8 (==3.7.8)"] [[package]] name = "cryptography" @@ -226,7 +226,7 @@ python-versions = "*" python-dateutil = ">=2.8.1" [package.extras] -dev = ["twine", "markdown", "flake8", "wheel"] +dev = ["wheel", "flake8", "markdown", "twine"] [[package]] name = "glob2" @@ -346,8 +346,8 @@ optional = false python-versions = ">=3.7" [package.extras] -test = ["pytest", "pytest-trio", "pytest-asyncio (>=0.17)", "testpath", "trio", "async-timeout"] -trio = ["trio", "async-generator"] +trio = ["async-generator", "trio"] +test = ["async-timeout", "trio", "testpath", "pytest-asyncio (>=0.17)", "pytest-trio", "pytest"] [[package]] name = "jinja2" @@ -509,8 +509,8 @@ parse = {version = ">=1.18.0", markers = "python_version >= \"3.0\""} six = ">=1.11" [package.extras] -develop = ["coverage (>=4.4)", "pytest-html (>=1.19.0)", "pytest-cov", "tox (>=2.8)", "pytest (<5.0)", "pytest (>=5.0)"] docs = ["sphinx (>=1.2)"] +develop = ["pytest (>=5.0)", "pytest (<5.0)", "tox (>=2.8)", "pytest-cov", "pytest-html (>=1.19.0)", "coverage (>=4.4)"] [[package]] name = "parsedatetime" @@ -588,8 +588,8 @@ optional = false python-versions = ">=3.6" [package.extras] -dev = ["pre-commit", "tox"] -testing = ["pytest", "pytest-benchmark"] +testing = ["pytest-benchmark", "pytest"] +dev = ["tox", "pre-commit"] [[package]] name = "poethepoet" @@ -913,7 +913,7 @@ executing = "*" pure-eval = "*" [package.extras] -tests = ["pytest", "typeguard", "pygments", "littleutils", "cython"] +tests = ["cython", "littleutils", "pygments", "typeguard", "pytest"] [[package]] name = "textwrap3" @@ -1038,7 +1038,7 @@ python-versions = ">=3.4" [[package]] name = "yq" -version = "3.0.2" +version = "3.1.0" description = "Command-line YAML/XML processor - jq wrapper for YAML/XML documents" category = "dev" optional = false @@ -1641,8 +1641,8 @@ xmltodict = [ {file = "xmltodict-0.13.0.tar.gz", hash = "sha256:341595a488e3e01a85a9d8911d8912fd922ede5fecc4dce437eb4b6c8d037e56"}, ] yq = [ - {file = "yq-3.0.2-py3-none-any.whl", hash = "sha256:ec58e003c3b5f1d03702b3c56a2bc81ac9cb400567e0e53f5bf82eae3bcff755"}, - {file = "yq-3.0.2.tar.gz", hash = "sha256:e47ff2479a3746f90bdbb77f84e3ebdb789ce46a092b1c261ae5b1f5f914f8e8"}, + {file = "yq-3.1.0-py3-none-any.whl", hash = "sha256:a1acffd3257a0b8e460f1a7ec1ae5af4646944e810f7d7099084b3104aa05769"}, + {file = "yq-3.1.0.tar.gz", hash = "sha256:30a84aa22486c749ba269256bd586c0bcd370b7e2a71e76c3924ead4867e74f2"}, ] zipp = [ {file = "zipp-3.8.0-py3-none-any.whl", hash = "sha256:c4f6e5bbf48e74f7a38e7cc5b0480ff42b0ae5178957d564d18932525d5cf099"}, From 80bfff384e7d17c0a6530791d5ee2d4f858ebf68 Mon Sep 17 00:00:00 2001 From: Jonathan van der Steege Date: Sat, 30 Jul 2022 21:22:04 +0200 Subject: [PATCH 3/7] 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 --- docs/reference-config-file.md | 3 ++- jrnl/Entry.py | 22 ++++++++++++++++++---- jrnl/plugins/fancy_exporter.py | 19 ++++++++++++++++++- tests/bdd/features/config_file.feature | 12 +++++++++++- tests/data/configs/linewrap_auto.yaml | 17 +++++++++++++++++ 5 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 tests/data/configs/linewrap_auto.yaml diff --git a/docs/reference-config-file.md b/docs/reference-config-file.md index 03454c05..80949156 100644 --- a/docs/reference-config-file.md +++ b/docs/reference-config-file.md @@ -101,7 +101,8 @@ If `true`, tags will be highlighted in cyan. ### linewrap Controls the width of the output. Set to `false` if you don't want to -wrap long lines. +wrap long lines. Set to `auto` to let `jrnl` automatically determine +the terminal width. ### colors A dictionary that controls the colors used to display journal entries. diff --git a/jrnl/Entry.py b/jrnl/Entry.py index 73f26190..6754072f 100644 --- a/jrnl/Entry.py +++ b/jrnl/Entry.py @@ -2,12 +2,14 @@ # License: https://www.gnu.org/licenses/gpl-3.0.html import datetime +import logging +import os import re import ansiwrap -from jrnl.color import colorize -from jrnl.color import highlight_tags_with_background_color +from .color import colorize +from .color import highlight_tags_with_background_color class Entry: @@ -104,6 +106,18 @@ class Entry: ) if not short and self.journal.config["linewrap"]: + columns = self.journal.config["linewrap"] + + if columns == "auto": + try: + columns = os.get_terminal_size().columns + except OSError: + logging.debug( + "Can't determine terminal size automatically 'linewrap': '%s'", + self.journal.config["linewrap"], + ) + columns = 79 + # Color date / title and bold title title = ansiwrap.fill( date_str @@ -114,7 +128,7 @@ class Entry: self.journal.config["colors"]["title"], is_title=True, ), - self.journal.config["linewrap"], + columns, ) body = highlight_tags_with_background_color( self, self.body.rstrip(" \n"), self.journal.config["colors"]["body"] @@ -123,7 +137,7 @@ class Entry: colorize( ansiwrap.fill( line, - self.journal.config["linewrap"], + columns, initial_indent=indent, subsequent_indent=indent, drop_whitespace=True, diff --git a/jrnl/plugins/fancy_exporter.py b/jrnl/plugins/fancy_exporter.py index a1e31869..2ce39ae0 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 = [ diff --git a/tests/bdd/features/config_file.feature b/tests/bdd/features/config_file.feature index d6b6121f..5cd3a6c5 100644 --- a/tests/bdd/features/config_file.feature +++ b/tests/bdd/features/config_file.feature @@ -107,6 +107,16 @@ Feature: Multiple journals When we run "jrnl --cf empty_file.yaml" Then the error output should contain "Unable to parse config file" + Scenario: Use a config file with linewrap set to 'auto' + Given we use the config "linewrap_auto.yaml" + When we run "jrnl -1" + Then the output should contain "Life is good." + + Scenario: Use a config file with linewrap set to 'auto' and use format 'fancy' + Given we use the config "linewrap_auto.yaml" + When we run "jrnl -1 --format fancy" + Then the output should contain "Life is good." + Scenario: Show a warning message when the config file contains duplicate keys at the same level Given the config "duplicate_keys.yaml" exists And we use the config "duplicate_keys.yaml" @@ -122,4 +132,4 @@ Feature: Multiple journals Scenario: Don't show a duplicate keys warning message when using --config-override on an existing value Given we use the config "multiple.yaml" When we run "jrnl --config-override highlight false" - Then the output should not contain "There is at least one duplicate key in your configuration file" \ No newline at end of file + Then the output should not contain "There is at least one duplicate key in your configuration file" diff --git a/tests/data/configs/linewrap_auto.yaml b/tests/data/configs/linewrap_auto.yaml new file mode 100644 index 00000000..69188710 --- /dev/null +++ b/tests/data/configs/linewrap_auto.yaml @@ -0,0 +1,17 @@ +default_hour: 9 +default_minute: 0 +editor: "" +encrypt: false +highlight: true +journals: + default: features/journals/simple.journal +linewrap: auto +tagsymbols: "@" +template: false +timeformat: "%Y-%m-%d %H:%M" +indent_character: "|" +colors: + date: none + title: none + body: none + tags: none From 2d15a7a5cf5cca337ff0dfed22e6e247d5d3faf6 Mon Sep 17 00:00:00 2001 From: Jrnl Bot Date: Sat, 30 Jul 2022 19:23:51 +0000 Subject: [PATCH 4/7] Update changelog [ci skip] --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a99cb1d1..9781e00c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,16 @@ - Create an environment variable when jrnl is called [\#1537](https://github.com/jrnl-org/jrnl/issues/1537) - Warn user when there are duplicate keys in the config file [\#1415](https://github.com/jrnl-org/jrnl/issues/1415) +- Add linewrap option 'auto' [\#1507](https://github.com/jrnl-org/jrnl/pull/1507) ([jonakeys](https://github.com/jonakeys)) + +**Fixed bugs:** + +- Update formatting function to better account for indentation [\#1541](https://github.com/jrnl-org/jrnl/pull/1541) ([wren](https://github.com/wren)) +- Fixed index out of range error in fancy exporter [\#1522](https://github.com/jrnl-org/jrnl/pull/1522) ([apainintheneck](https://github.com/apainintheneck)) **Packaging:** +- Bump yq from 3.0.2 to 3.1.0 [\#1546](https://github.com/jrnl-org/jrnl/pull/1546) ([dependabot[bot]](https://github.com/apps/dependabot)) - Bump keyring from 23.6.0 to 23.7.0 [\#1539](https://github.com/jrnl-org/jrnl/pull/1539) ([dependabot[bot]](https://github.com/apps/dependabot)) ## [v3.0](https://pypi.org/project/jrnl/v3.0/) (2022-07-09) From 506cc664b2f6752dbe85679c73eeba91c436feb3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 30 Jul 2022 12:34:09 -0700 Subject: [PATCH 5/7] Bump rich from 12.4.4 to 12.5.1 (#1538) Bumps [rich](https://github.com/willmcgugan/rich) from 12.4.4 to 12.5.1. - [Release notes](https://github.com/willmcgugan/rich/releases) - [Changelog](https://github.com/Textualize/rich/blob/master/CHANGELOG.md) - [Commits](https://github.com/willmcgugan/rich/compare/v12.4.4...v12.5.1) --- updated-dependencies: - dependency-name: rich dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- poetry.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/poetry.lock b/poetry.lock index 8adad950..db59d64c 100644 --- a/poetry.lock +++ b/poetry.lock @@ -843,7 +843,7 @@ pyyaml = "*" [[package]] name = "rich" -version = "12.4.4" +version = "12.5.1" description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal" category = "main" optional = false @@ -1527,8 +1527,8 @@ pyyaml-env-tag = [ {file = "pyyaml_env_tag-0.1.tar.gz", hash = "sha256:70092675bda14fdec33b31ba77e7543de9ddc88f2e5b99160396572d11525bdb"}, ] rich = [ - {file = "rich-12.4.4-py3-none-any.whl", hash = "sha256:d2bbd99c320a2532ac71ff6a3164867884357da3e3301f0240090c5d2fdac7ec"}, - {file = "rich-12.4.4.tar.gz", hash = "sha256:4c586de507202505346f3e32d1363eb9ed6932f0c2f63184dea88983ff4971e2"}, + {file = "rich-12.5.1-py3-none-any.whl", hash = "sha256:2eb4e6894cde1e017976d2975ac210ef515d7548bc595ba20e195fb9628acdeb"}, + {file = "rich-12.5.1.tar.gz", hash = "sha256:63a5c5ce3673d3d5fbbf23cd87e11ab84b6b451436f1b7f19ec54b6bc36ed7ca"}, ] "ruamel.yaml" = [ {file = "ruamel.yaml-0.17.21-py3-none-any.whl", hash = "sha256:742b35d3d665023981bd6d16b3d24248ce5df75fdb4e2924e93a05c1f8b61ca7"}, From e233ab4a742fcbe3b143799653894bf57a8a120f Mon Sep 17 00:00:00 2001 From: Jrnl Bot Date: Sat, 30 Jul 2022 19:35:48 +0000 Subject: [PATCH 6/7] Update changelog [ci skip] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9781e00c..64fe2094 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - Bump yq from 3.0.2 to 3.1.0 [\#1546](https://github.com/jrnl-org/jrnl/pull/1546) ([dependabot[bot]](https://github.com/apps/dependabot)) - Bump keyring from 23.6.0 to 23.7.0 [\#1539](https://github.com/jrnl-org/jrnl/pull/1539) ([dependabot[bot]](https://github.com/apps/dependabot)) +- Bump rich from 12.4.4 to 12.5.1 [\#1538](https://github.com/jrnl-org/jrnl/pull/1538) ([dependabot[bot]](https://github.com/apps/dependabot)) ## [v3.0](https://pypi.org/project/jrnl/v3.0/) (2022-07-09) From 94d126b0c88d132c2e88d80ccf87cd68712dc13f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 30 Jul 2022 12:43:57 -0700 Subject: [PATCH 7/7] Bump poethepoet from 0.15.0 to 0.16.0 (#1542) Bumps [poethepoet](https://github.com/nat-n/poethepoet) from 0.15.0 to 0.16.0. - [Release notes](https://github.com/nat-n/poethepoet/releases) - [Commits](https://github.com/nat-n/poethepoet/compare/v0.15.0...v0.16.0) --- updated-dependencies: - dependency-name: poethepoet dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- poetry.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/poetry.lock b/poetry.lock index db59d64c..fd01fde0 100644 --- a/poetry.lock +++ b/poetry.lock @@ -593,7 +593,7 @@ dev = ["tox", "pre-commit"] [[package]] name = "poethepoet" -version = "0.15.0" +version = "0.16.0" description = "A task runner that works well with poetry." category = "dev" optional = false @@ -1405,8 +1405,8 @@ pluggy = [ {file = "pluggy-1.0.0.tar.gz", hash = "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159"}, ] poethepoet = [ - {file = "poethepoet-0.15.0-py3-none-any.whl", hash = "sha256:8ca49d8a9928a3ce1753315d6df0866888557eccb0fe37a8c88fea47454cfe12"}, - {file = "poethepoet-0.15.0.tar.gz", hash = "sha256:5843260c9074b6c42bf2e51f21107efe37e230cf75da3dd3f4b43904f365b26c"}, + {file = "poethepoet-0.16.0-py3-none-any.whl", hash = "sha256:87482ea8bba4e5db4abbd8e6360baee73b2ce0f3d5f5e99e81cdfa39d72d118f"}, + {file = "poethepoet-0.16.0.tar.gz", hash = "sha256:6455aec39f198be92dbf210a4416e1635119e967204c092b431c8b10024db1d1"}, ] pprintpp = [ {file = "pprintpp-0.4.0-py2.py3-none-any.whl", hash = "sha256:b6b4dcdd0c0c0d75e4d7b2f21a9e933e5b2ce62b26e1a54537f9651ae5a5c01d"},