Adds word wrap support.

This commit is contained in:
Manuel Ebert 2012-05-30 17:43:55 +02:00
parent 22b3da5f89
commit 7ae9f2bed2
3 changed files with 8 additions and 1 deletions

View file

@ -1,6 +1,8 @@
Changelog Changelog
========= =========
* [Improved] Supports a config option for setting word wrap.
### 0.3.0 (May 24, 2012) ### 0.3.0 (May 24, 2012)
* [Fixed] Dates such as "May 3" will now be interpreted as being in the past if the current day is at least 28 days in the future * [Fixed] Dates such as "May 3" will now be interpreted as being in the past if the current day is at least 28 days in the future

View file

@ -2,6 +2,7 @@
# encoding: utf-8 # encoding: utf-8
import re import re
import textwrap
class Entry: class Entry:
def __init__(self, journal, date=None, title="", body=""): def __init__(self, journal, date=None, title="", body=""):
@ -19,7 +20,10 @@ class Entry:
def __str__(self): def __str__(self):
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 "" body_wrapper = "\n" if self.body else ""
body = body_wrapper + self.body.strip() 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" space = "\n"
return "%(date)s %(title)s %(body)s %(space)s" % { return "%(date)s %(title)s %(body)s %(space)s" % {

View file

@ -26,6 +26,7 @@ default_config = {
'timeformat': "%Y-%m-%d %H:%M", 'timeformat': "%Y-%m-%d %H:%M",
'tagsymbols': '@', 'tagsymbols': '@',
'highlight': True, 'highlight': True,
'linewrap': 80,
} }