diff --git a/docs/usage.rst b/docs/usage.rst index f9cdb60c..374f8262 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -77,6 +77,10 @@ everything that happened from the start of last year to the start of last march. jrnl -starred +and to order them descendantly by date :: + + jrnl -desc + Using Tags ---------- diff --git a/features/core.feature b/features/core.feature index ab86da42..8b3cb442 100644 --- a/features/core.feature +++ b/features/core.feature @@ -53,6 +53,18 @@ Feature: Basic reading and writing to a journal When we run "jrnl -on 2013-06-10 --short" Then the output should be "2013-06-10 15:40 Life is good." + Scenario: -desc displays the entries descendantly by date + Given we use the config "basic.yaml" + When we run "jrnl --desc" + Then the output should be + """ + 2013-06-10 15:40 Life is good. + | But I'm better. + + 2013-06-09 15:39 My first entry. + | Everything is alright + """ + Scenario: -s displays the short version of entries (only the title) Given we use the config "basic.yaml" When we run "jrnl -on 2013-06-10 -s" diff --git a/jrnl/Journal.py b/jrnl/Journal.py index c36b3760..7560b962 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -122,10 +122,11 @@ class Journal(object): def __unicode__(self): return self.pprint() - def pprint(self, short=False): + def pprint(self, short=False, desc=False): """Prettyprints the journal's entries""" sep = "\n" - pp = sep.join([e.pprint(short=short) for e in self.entries]) + sorted_entries = sorted(self.entries, key=lambda entry: entry.date, reverse=desc) + pp = sep.join([e.pprint(short=short) for e in sorted_entries]) if self.config['highlight']: # highlight tags if self.search_tags: for tag in self.search_tags: diff --git a/jrnl/cli.py b/jrnl/cli.py index 042e38e0..90088108 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -38,6 +38,7 @@ def parse_args(args=None): reading.add_argument('-on', dest='on_date', metavar="DATE", help='View entries on this date') 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('-desc', dest='desc', action="store_true", help='Order entries downwards') reading.add_argument('-n', dest='limit', default=None, metavar="N", help="Shows the last n entries matching the filter. '-n 3' and '-3' have the same effect.", nargs="?", type=int) exporting = parser.add_argument_group('Export / Import', 'Options for transmogrifying your journal') @@ -238,13 +239,15 @@ def run(manual_args=None): starred=args.starred) journal.limit(args.limit) + desc = args.desc if args.desc is not None else False + # Reading mode if not mode_compose and not mode_export and not mode_import: - print(util.py2encode(journal.pprint())) + print(util.py2encode(journal.pprint(desc=desc))) # Various export modes elif args.short: - print(util.py2encode(journal.pprint(short=True))) + print(util.py2encode(journal.pprint(short=True, desc=desc))) elif args.tags: print(util.py2encode(plugins.get_exporter("tags").export(journal)))