diff --git a/jrnl/Entry.py b/jrnl/Entry.py index c303b63c..4948cc1d 100644 --- a/jrnl/Entry.py +++ b/jrnl/Entry.py @@ -34,10 +34,11 @@ class Entry: body=body ) - def pprint(self): - """Returns a pretty-printed version of the entry.""" + def pprint(self, short=False): + """Returns a pretty-printed version of the entry. + If short is true, only print the title.""" date_str = self.date.strftime(self.journal.config['timeformat']) - if self.journal.config['linewrap']: + if not short and self.journal.config['linewrap']: title = textwrap.fill(date_str + " " + self.title, self.journal.config['linewrap']) body = "\n".join([ textwrap.fill(line+" ", @@ -54,11 +55,14 @@ class Entry: # 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 u"{title}{sep}{body}\n".format( - title=title, - sep="\n" if has_body else "", - body=body if has_body else "", - ) + if short: + return title + else: + return u"{title}{sep}{body}\n".format( + title=title, + sep="\n" if has_body else "", + body=body if has_body else "", + ) def __repr__(self): return "".format(self.title.strip(), self.date.strftime("%Y-%m-%d %H:%M")) diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 315919c0..ef493a0a 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -161,9 +161,12 @@ class Journal(object): return entries def __unicode__(self): + return self.pprint() + + def pprint(self, short=False): """Prettyprints the journal's entries""" sep = "\n" - pp = sep.join([e.pprint() for e in self.entries]) + pp = sep.join([e.pprint(short=short) for e in self.entries]) if self.config['highlight']: # highlight tags if self.search_tags: for tag in self.search_tags: @@ -177,9 +180,6 @@ class Journal(object): pp) return pp - def pprint(self): - return self.__unicode__() - def __repr__(self): return "".format(len(self.entries)) @@ -254,7 +254,13 @@ class Journal(object): date, flag = self.dateparse.parse(date) if not flag: # Oops, unparsable. - return None + try: # Try and parse this as a single year + year = int(date_str) + return datetime(year, 1, 1) + except ValueError: + return None + except TypeError: + return None if flag is 1: # Date found, but no time. Use the default time. date = datetime(*date[:3], hour=self.config['default_hour'], minute=self.config['default_minute']) diff --git a/jrnl/jrnl.py b/jrnl/jrnl.py index 07a2cce6..901507c2 100755 --- a/jrnl/jrnl.py +++ b/jrnl/jrnl.py @@ -39,12 +39,12 @@ def parse_args(args=None): reading.add_argument('-and', dest='strict', action="store_true", help='Filter by tags using AND (default: OR)') reading.add_argument('-starred', dest='starred', action="store_true", help='Show only starred entries') reading.add_argument('-n', dest='limit', default=None, metavar="N", help='Shows the last n entries matching the filter', nargs="?", type=int) - reading.add_argument('-short', dest='short', action="store_true", help='Show only titles or line containing the search tags') exporting = parser.add_argument_group('Export / Import', 'Options for transmogrifying your journal') + exporting.add_argument('--short', dest='short', action="store_true", help='Show only titles or line containing the search tags') exporting.add_argument('--tags', dest='tags', action="store_true", help='Returns a list of all tags and number of occurences') - exporting.add_argument('--export', metavar='TYPE', dest='export', help='Export your journal to Markdown, JSON or Text', nargs='?', default=False, const=None) - exporting.add_argument('-o', metavar='OUTPUT', dest='output', help='The output of the file can be provided when using with --export', nargs='?', default=False, const=None) + exporting.add_argument('--export', metavar='TYPE', dest='export', help='Export your journal to Markdown, JSON or Text', default=False, const=None) + exporting.add_argument('-o', metavar='OUTPUT', dest='output', help='The output of the file can be provided when using with --export', default=False, const=None) exporting.add_argument('--encrypt', metavar='FILENAME', dest='encrypt', help='Encrypts your existing journal with a new password', nargs='?', default=False, const=None) exporting.add_argument('--decrypt', metavar='FILENAME', dest='decrypt', help='Decrypts your journal and stores it in plain text', nargs='?', default=False, const=None) exporting.add_argument('--delete-last', dest='delete_last', help='Deletes the last entry from your journal file.', action="store_true") @@ -55,10 +55,10 @@ def guess_mode(args, config): """Guesses the mode (compose, read or export) from the given arguments""" compose = True export = False - if args.decrypt is not False or args.encrypt is not False or args.export is not False or args.tags or args.delete_last: + if args.decrypt is not False or args.encrypt is not False or args.export is not False or any((args.short, args.tags, args.delete_last)): compose = False export = True - elif any((args.start_date, args.end_date, args.limit, args.strict, args.short, args.starred)): + elif any((args.start_date, args.end_date, args.limit, args.strict, args.starred)): # Any sign of displaying stuff? compose = False elif args.text and all(word[0] in config['tagsymbols'] for word in " ".join(args.text).split()): @@ -187,6 +187,9 @@ def cli(manual_args=None): print(journal.pprint()) # Various export modes + elif args.short: + print(journal.pprint(short=True)) + elif args.tags: print(exporters.to_tag_list(journal))