This commit is contained in:
Ursine Asylum 2017-03-09 22:55:55 +00:00 committed by GitHub
commit 46f78f11a8
2 changed files with 14 additions and 3 deletions

View file

@ -194,7 +194,7 @@ class Journal(object):
if n:
self.entries = self.entries[-n:]
def filter(self, tags=[], start_date=None, end_date=None, starred=False, strict=False, short=False):
def filter(self, tags=[], start_date=None, end_date=None, starred=False, strict=False, short=False, head=None):
"""Removes all entries from the journal that don't match the filter.
tags is a list of tags, each being a string that starts with one of the
@ -233,6 +233,15 @@ class Journal(object):
else:
for e in self.entries:
e.body = ''
elif head is not None:
try:
head = int(head)
for e in self.entries:
e.body = "\n".join(e.body.split('\n')[:head])
except ValueError:
pass
self.entries = result
def new_entry(self, raw, date=None, sort=True):

View file

@ -41,6 +41,7 @@ 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. '-n 3' and '-3' have the same effect.", nargs="?", type=int)
reading.add_argument('-t', '--top', dest='head', action="store", default=None, help="Clips the first N lines of each journal entry.")
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')
@ -61,7 +62,7 @@ def guess_mode(args, config):
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.edit)):
compose = False
export = True
elif any((args.start_date, args.end_date, args.on_date, args.limit, args.strict, args.starred)):
elif any((args.start_date, args.end_date, args.on_date, args.limit, args.head, 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()):
@ -233,7 +234,8 @@ def run(manual_args=None):
start_date=args.start_date, end_date=args.end_date,
strict=args.strict,
short=args.short,
starred=args.starred)
starred=args.starred,
head=args.head)
journal.limit(args.limit)
# Reading mode