mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-18 12:08:31 +02:00
Add order feature
Use -desc to order entries descendantly by date.
This commit is contained in:
parent
2732ae5419
commit
60ce0a03ea
4 changed files with 24 additions and 4 deletions
|
@ -77,6 +77,10 @@ everything that happened from the start of last year to the start of last march.
|
||||||
|
|
||||||
jrnl -starred
|
jrnl -starred
|
||||||
|
|
||||||
|
and to order them descendantly by date ::
|
||||||
|
|
||||||
|
jrnl -desc
|
||||||
|
|
||||||
Using Tags
|
Using Tags
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,18 @@ Feature: Basic reading and writing to a journal
|
||||||
When we run "jrnl -on 2013-06-10 --short"
|
When we run "jrnl -on 2013-06-10 --short"
|
||||||
Then the output should be "2013-06-10 15:40 Life is good."
|
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)
|
Scenario: -s displays the short version of entries (only the title)
|
||||||
Given we use the config "basic.yaml"
|
Given we use the config "basic.yaml"
|
||||||
When we run "jrnl -on 2013-06-10 -s"
|
When we run "jrnl -on 2013-06-10 -s"
|
||||||
|
|
|
@ -122,10 +122,11 @@ class Journal(object):
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.pprint()
|
return self.pprint()
|
||||||
|
|
||||||
def pprint(self, short=False):
|
def pprint(self, short=False, desc=False):
|
||||||
"""Prettyprints the journal's entries"""
|
"""Prettyprints the journal's entries"""
|
||||||
sep = "\n"
|
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.config['highlight']: # highlight tags
|
||||||
if self.search_tags:
|
if self.search_tags:
|
||||||
for tag in self.search_tags:
|
for tag in self.search_tags:
|
||||||
|
|
|
@ -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('-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('-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('-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)
|
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')
|
exporting = parser.add_argument_group('Export / Import', 'Options for transmogrifying your journal')
|
||||||
|
@ -238,13 +239,15 @@ def run(manual_args=None):
|
||||||
starred=args.starred)
|
starred=args.starred)
|
||||||
journal.limit(args.limit)
|
journal.limit(args.limit)
|
||||||
|
|
||||||
|
desc = args.desc if args.desc is not None else False
|
||||||
|
|
||||||
# Reading mode
|
# Reading mode
|
||||||
if not mode_compose and not mode_export and not mode_import:
|
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
|
# Various export modes
|
||||||
elif args.short:
|
elif args.short:
|
||||||
print(util.py2encode(journal.pprint(short=True)))
|
print(util.py2encode(journal.pprint(short=True, desc=desc)))
|
||||||
|
|
||||||
elif args.tags:
|
elif args.tags:
|
||||||
print(util.py2encode(plugins.get_exporter("tags").export(journal)))
|
print(util.py2encode(plugins.get_exporter("tags").export(journal)))
|
||||||
|
|
Loading…
Add table
Reference in a new issue