mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-17 03:28:31 +02:00
Merge branch 'develop' into update-tzlocal-1528
Conflicts: poetry.lock
This commit is contained in:
commit
2432a408fc
6 changed files with 75 additions and 8 deletions
|
@ -8,10 +8,18 @@
|
|||
|
||||
- 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))
|
||||
- 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)
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 = [
|
||||
|
@ -50,7 +67,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
|
||||
|
|
|
@ -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"
|
||||
Then the output should not contain "There is at least one duplicate key in your configuration file"
|
||||
|
|
17
tests/data/configs/linewrap_auto.yaml
Normal file
17
tests/data/configs/linewrap_auto.yaml
Normal file
|
@ -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
|
Loading…
Add table
Reference in a new issue