mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-17 03:28:31 +02:00
Add linewrap option 'auto'
This commit is contained in:
parent
9639c5386f
commit
272d586e06
2 changed files with 19 additions and 3 deletions
|
@ -96,7 +96,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.
|
||||
|
|
|
@ -7,6 +7,9 @@ import re
|
|||
|
||||
import ansiwrap
|
||||
|
||||
import os
|
||||
import logging
|
||||
|
||||
from .color import colorize
|
||||
from .color import highlight_tags_with_background_color
|
||||
|
||||
|
@ -105,6 +108,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()[0]
|
||||
except: # noqa: E722
|
||||
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
|
||||
|
@ -115,7 +130,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"]
|
||||
|
@ -124,7 +139,7 @@ class Entry:
|
|||
colorize(
|
||||
ansiwrap.fill(
|
||||
line,
|
||||
self.journal.config["linewrap"],
|
||||
columns,
|
||||
initial_indent=indent,
|
||||
subsequent_indent=indent,
|
||||
drop_whitespace=True,
|
||||
|
|
Loading…
Add table
Reference in a new issue