From 281d8cda06efb6397b3f8369c2dbe163f744fb25 Mon Sep 17 00:00:00 2001 From: endorphant Date: Thu, 6 Oct 2016 11:38:14 -0400 Subject: [PATCH] removed redundant sort on file listing; sort on file lists should now only be called on the specific incantation. wrote a preliminary list scroller on beta only. --- bin/_ttbp.py | 24 +++++++++++----- bin/config/banner-beta.txt | 2 +- bin/core.py | 4 +-- bin/ttbp.py | 2 ++ bin/util.py | 59 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 10 deletions(-) diff --git a/bin/_ttbp.py b/bin/_ttbp.py index 58a767d..9ca706c 100644 --- a/bin/_ttbp.py +++ b/bin/_ttbp.py @@ -45,7 +45,7 @@ import chatter import inflect import util -__version__ = "0.9.1b" +__version__ = "0.9.2b" __author__ = "endorphant 0: entries = [] @@ -699,9 +701,12 @@ def list_entries(metas, entries, prompt): displays a list of entries for reading selection ''' + ''' util.print_menu(entries, RAINBOW) - choice = util.list_select(entries, "pick an entry from the list, or type 'back' or 'q' to go back: ") + ''' + + choice = util.menu_handler(entries, "pick an entry from the list, or type 'q' to go back: ", 10, RAINBOW) if choice is not False: @@ -794,11 +799,7 @@ def select_editor(): ''' util.print_menu(EDITORS, RAINBOW) - choice = util.list_select(EDITORS, "pick your favorite text editor: ") - #choice = raw_input("\npick your favorite text editor: ") - #while choice not in ['0', '1', '2', '3', '4', '5']: - # choice = raw_input("\nplease pick a number from the list: ") if choice is False: redraw("please pick a text editor!") @@ -1059,6 +1060,15 @@ ver 0.9.1 features: * graffiti wall """) + if userVersion[0:5] < "0.9.2": + # version 0.9.2 patch notes + print(""" +ver 0.9.2 features: + * paginated entry view + * expanded menu for viewing your own feels (further + features to be implemented) + """) + ##### if __name__ == '__main__': diff --git a/bin/config/banner-beta.txt b/bin/config/banner-beta.txt index 4158528..d38790f 100644 --- a/bin/config/banner-beta.txt +++ b/bin/config/banner-beta.txt @@ -5,5 +5,5 @@ | |___ |___ |___ | [__ |___ |\ | | __ | |\ | |___ | | | |___ |___ |___ ___] |___ | \| |__] | | \| |___ | | | -| ver 0.9.1 (almost stable) | +| ver 0.9.2 (almost stable) | |__________________________________________________________| diff --git a/bin/core.py b/bin/core.py index 0e871fb..852883f 100644 --- a/bin/core.py +++ b/bin/core.py @@ -300,8 +300,8 @@ def meta(entries = FILES): meta.append([filename, mtime, wc, timestamp, date, author]) - meta.sort(key = lambda filename:filename[4]) - meta.reverse() + #meta.sort(key = lambda filename:filename[4]) + #meta.reverse() return meta diff --git a/bin/ttbp.py b/bin/ttbp.py index 9ba6c9b..05808dd 100644 --- a/bin/ttbp.py +++ b/bin/ttbp.py @@ -501,6 +501,8 @@ def view_feels(townie): for entry in os.listdir(entryDir): filenames.append(os.path.join(entryDir, entry)) metas = core.meta(filenames) + metas.sort(key = lambda entry:entry[4]) + metas.reverse() if len(filenames) > 0: entries = [] diff --git a/bin/util.py b/bin/util.py index e19b993..b9460f4 100644 --- a/bin/util.py +++ b/bin/util.py @@ -31,6 +31,7 @@ import colorama ## misc globals BACKS = ['back', 'b', 'q'] +NAVS = ['u', 'd'] ## color stuff colorama.init() @@ -146,6 +147,61 @@ def genID(digits=5): return id +def menu_handler(options, prompt, pagify=10, rainbow=False): + ''' + This menu handler takes an incoming list of options, pagifies to a + pre-set value, and queries via the prompt. Calls print_menu() and + list_select() as helpers. + ''' + + optCount = len(options) + page = 0 + total = optCount / pagify + + # don't display empty pages + if optCount % pagify == 0: + total = total - 1 + + if total < 2: + print_menu(options, rainbow) + return list_select(options, prompt) + + else: + return page_helper(options, prompt, pagify, rainbow, page, total) + + +def page_helper(options, prompt, pagify, rainbow, page, total): + ''' + A helper to process pagination. + ''' + + ## make short list + x = 0 + page * pagify + y = x + pagify + optPage = options[x:y] + + print_menu(optPage, prompt) + print("\n\t( page {page} of {total}; type 'u' or 'd' to scroll up and down )").format(page=page+1, total=total+1) + + ans = list_select(optPage, prompt) + + if ans in NAVS: + if ans == 'u': + if page == 0: + print("can't scroll up anymore!") + else: + page = page - 1 + else: + if page == total: + print("can't scroll down anymore!") + else: + page = page + 1 + + print("") + return page_helper(options, prompt, pagify, rainbow, page, total) + + return ans + def print_menu(menu, rainbow=False): ''' A pretty menu handler that takes an incoming lists of @@ -183,6 +239,9 @@ def list_select(options, prompt): if choice in BACKS: return False + if choice in NAVS: + return choice + try: ans = int(choice) except ValueError: