From fe2d4653c181ebb3a3157ae8d35c6eb30066ade1 Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Mon, 1 May 2017 21:46:37 +0530 Subject: [PATCH] Support browsing at prompt --- buku.1 | 3 +++ buku.py | 24 +++++++++++++++++++----- tests/test_ExtendedArgumentParser.py | 1 + 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/buku.1 b/buku.1 index 998a44d..f4993d6 100644 --- a/buku.1 +++ b/buku.1 @@ -271,6 +271,9 @@ Search bookmarks by a tag. List all tags alphabetically, if no arguments. The in .BI "g" " [...][>>|>|<<][...]" Append, remove tags to/from indices and/or ranges. .TP +.BI "o" " [...]" +Browse bookmarks by indices and/or ranges. +.TP .BI "p" " [...]" Print bookmarks by indices and/or ranges. .TP diff --git a/buku.py b/buku.py index 8b868c6..63a679f 100755 --- a/buku.py +++ b/buku.py @@ -1834,6 +1834,7 @@ keys: r expression run a regex search t [...] search bookmarks by a tag or show tag list g [...][>>|>|<<][...] append, remove tags to/from indices and/or ranges + o [...] browse bookmarks by indices and/or ranges p [...] print bookmarks by indices and/or ranges w [editor|index] edit and add or update a bookmark (tag list index fetches bookmarks by tag) @@ -2146,7 +2147,8 @@ def taglist_subprompt(obj, msg, noninteractive=False): elif (nav == 'q' or nav == 'd' or nav == '?' or nav.startswith('s ') or nav.startswith('S ') or nav.startswith('r ') or nav.startswith('t ') or - nav.startswith('g ') or nav.startswith('p ')): + nav.startswith('o ') or nav.startswith('p ') or + nav.startswith('g ')): return nav elif nav == 'w' or nav.startswith('w '): edit_at_prompt(obj, nav) @@ -2281,11 +2283,23 @@ def prompt(obj, results, noninteractive=False, deep=False, subprompt=False): obj.print_rec(int(id)) elif '-' in id: vals = [int(x) for x in id.split('-')] - if vals[0] > vals[-1]: - vals[0], vals[-1] = vals[-1], vals[0] + obj.print_rec(0, vals[0], vals[-1], True) + else: + print('Invalid input') + except ValueError: + print('Invalid input') + continue - for _id in range(vals[0], vals[-1] + 1): - obj.print_rec(_id) + # Browse bookmarks by DB index + if nav.startswith('o '): + id_list = nav[2:].split() + try: + for id in id_list: + if is_int(id): + obj.browse_by_index(int(id)) + elif '-' in id: + vals = [int(x) for x in id.split('-')] + obj.browse_by_index(0, vals[0], vals[-1], True) else: print('Invalid input') except ValueError: diff --git a/tests/test_ExtendedArgumentParser.py b/tests/test_ExtendedArgumentParser.py index 337eddc..3e5fa3e 100644 --- a/tests/test_ExtendedArgumentParser.py +++ b/tests/test_ExtendedArgumentParser.py @@ -47,6 +47,7 @@ keys: r expression run a regex search t [...] search bookmarks by a tag or show tag list g [...][>>|>|<<][...] append, remove tags to/from indices and/or ranges + o [...] browse bookmarks by indices and/or ranges p [...] print bookmarks by indices and/or ranges w [editor|index] edit and add or update a bookmark (tag list index fetches bookmarks by tag)