mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Merge 2f8a95f553
into 4cca754ba5
This commit is contained in:
commit
4727204b12
2 changed files with 35 additions and 13 deletions
|
@ -18,19 +18,41 @@ class Entry:
|
|||
self.tags = set(tags)
|
||||
|
||||
def __str__(self):
|
||||
"""Returns a string representation of the entry to be written into a journal file."""
|
||||
date_str = self.date.strftime(self.journal.config['timeformat'])
|
||||
body_wrapper = "\n" if self.body else ""
|
||||
if self.journal.config['linewrap']:
|
||||
body = body_wrapper + textwrap.fill(self.body, self.journal.config['linewrap'])
|
||||
else:
|
||||
body = body_wrapper + self.body.strip()
|
||||
space = "\n"
|
||||
title = date_str + " " + self.title
|
||||
body = self.body.strip()
|
||||
|
||||
return "{date} {title} {body} {space}".format(
|
||||
date=date_str,
|
||||
title=self.title,
|
||||
body=body,
|
||||
space=space
|
||||
return "{title}{sep}{body}\n".format(
|
||||
title=title,
|
||||
sep="\n" if self.body else "",
|
||||
body=body
|
||||
)
|
||||
|
||||
def pprint(self):
|
||||
"""Returns a pretty-printed version of the entry."""
|
||||
date_str = self.date.strftime(self.journal.config['timeformat'])
|
||||
if self.journal.config['linewrap']:
|
||||
title = textwrap.fill(date_str + " " + self.title, self.journal.config['linewrap'])
|
||||
body = "\n".join([
|
||||
textwrap.fill(line+" ",
|
||||
self.journal.config['linewrap'],
|
||||
initial_indent="| ",
|
||||
subsequent_indent="| ",
|
||||
drop_whitespace=False)
|
||||
for line in self.body.strip().splitlines()
|
||||
])
|
||||
else:
|
||||
title = date_str + " " + self.title
|
||||
body = self.body.strip()
|
||||
|
||||
# Suppress bodies that are just blanks and new lines.
|
||||
has_body = len(self.body) > 20 or not all(char in (" ", "\n") for char in self.body)
|
||||
|
||||
return "{title}{sep}{body}\n".format(
|
||||
title=title,
|
||||
sep="\n" if has_body else "",
|
||||
body=body if has_body else "",
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
|
|
|
@ -134,8 +134,8 @@ class Journal:
|
|||
|
||||
def __str__(self):
|
||||
"""Prettyprints the journal's entries"""
|
||||
sep = "-"*60+"\n"
|
||||
pp = sep.join([str(e) for e in self.entries])
|
||||
sep = "\n"
|
||||
pp = sep.join([e.pprint() for e in self.entries])
|
||||
if self.config['highlight']: # highlight tags
|
||||
if self.search_tags:
|
||||
for tag in self.search_tags:
|
||||
|
|
Loading…
Add table
Reference in a new issue