mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Merge pull request #34 from maebert/new-style-display
New style display of posts
This commit is contained in:
commit
c289aaeb8c
2 changed files with 35 additions and 13 deletions
|
@ -18,19 +18,41 @@ class Entry:
|
||||||
self.tags = set(tags)
|
self.tags = set(tags)
|
||||||
|
|
||||||
def __str__(self):
|
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'])
|
date_str = self.date.strftime(self.journal.config['timeformat'])
|
||||||
body_wrapper = "\n" if self.body else ""
|
title = date_str + " " + self.title
|
||||||
if self.journal.config['linewrap']:
|
body = self.body.strip()
|
||||||
body = body_wrapper + textwrap.fill(self.body, self.journal.config['linewrap'])
|
|
||||||
else:
|
|
||||||
body = body_wrapper + self.body.strip()
|
|
||||||
space = "\n"
|
|
||||||
|
|
||||||
return "{date} {title} {body} {space}".format(
|
return "{title}{sep}{body}\n".format(
|
||||||
date=date_str,
|
title=title,
|
||||||
title=self.title,
|
sep="\n" if self.body else "",
|
||||||
body=body,
|
body=body
|
||||||
space=space
|
)
|
||||||
|
|
||||||
|
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):
|
def __repr__(self):
|
||||||
|
|
|
@ -134,8 +134,8 @@ class Journal:
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Prettyprints the journal's entries"""
|
"""Prettyprints the journal's entries"""
|
||||||
sep = "-"*60+"\n"
|
sep = "\n"
|
||||||
pp = sep.join([str(e) for e in self.entries])
|
pp = sep.join([e.pprint() for e in self.entries])
|
||||||
if self.config['highlight']: # highlight tags
|
if self.config['highlight']: # highlight tags
|
||||||
if self.search_tags:
|
if self.search_tags:
|
||||||
for tag in self.search_tags:
|
for tag in self.search_tags:
|
||||||
|
|
Loading…
Add table
Reference in a new issue