Show prompt when listing tags.

This commit is contained in:
Arun Prakash Jana 2016-11-20 23:50:23 +05:30
parent b4fe5c5fd7
commit b82b2194bf
No known key found for this signature in database
GPG Key ID: A75979F35C080412

51
buku.py
View File

@ -1685,6 +1685,7 @@ def taglist_subprompt(obj):
for tag in unique_tags: for tag in unique_tags:
print('%6d. %s (%d)' % (count, tag, dic[tag])) print('%6d. %s (%d)' % (count, tag, dic[tag]))
count += 1 count += 1
print()
try: try:
nav = input(msg) nav = input(msg)
@ -1717,13 +1718,14 @@ def taglist_subprompt(obj):
new_results = False new_results = False
def prompt(obj, results, noninteractive=False, deep=False): def prompt(obj, results, noninteractive=False, deep=False, subprompt=False):
'''Show each matching result from a search and prompt '''Show each matching result from a search and prompt
:param obj: a valid instance of BukuDb class :param obj: a valid instance of BukuDb class
:param results: result set from a DB query :param results: result set from a DB query
:param noninteractive: do not seek user input :param noninteractive: do not seek user input
:param deep: use deep search :param deep: use deep search
:param subprompt: jump directly to sub prompt
''' '''
if not type(obj) is BukuDb: if not type(obj) is BukuDb:
@ -1734,29 +1736,33 @@ def prompt(obj, results, noninteractive=False, deep=False):
msg = '\x1b[7mbuku (? for help)\x1b[0m ' msg = '\x1b[7mbuku (? for help)\x1b[0m '
while True: while True:
if new_results: if not subprompt:
if results: if new_results:
count = 0 if results:
count = 0
for row in results: for row in results:
count += 1 count += 1
print_record(row, count) print_record(row, count)
else: else:
print('0 results') print('0 results')
if noninteractive: if noninteractive:
return return
try: try:
nav = input(msg)
if not nav:
nav = input(msg) nav = input(msg)
if not nav: if not nav:
# Quit on double enter nav = input(msg)
break if not nav:
nav = nav.strip() # Quit on double enter
except EOFError: break
return nav = nav.strip()
except EOFError:
return
else:
nav = 't'
subprompt = False
# list tags with 't' # list tags with 't'
if nav == 't': if nav == 't':
@ -2427,11 +2433,8 @@ def main():
if len(args.stag) > 0: if len(args.stag) > 0:
search_results = bdb.search_by_tag(' '.join(args.stag)) search_results = bdb.search_by_tag(' '.join(args.stag))
else: else:
unique_tags, dic = bdb.get_all_tags() # Use sub prompt to list all tags
count = 1 prompt(bdb, None, subprompt=True)
for tag in unique_tags:
print('%6d. %s (%d)' % (count, tag, dic[tag]))
count += 1
if search_results: if search_results:
oneshot = args.noprompt oneshot = args.noprompt