From b63e04943a7211b2b78ea7f6b2f1095d13ba8f25 Mon Sep 17 00:00:00 2001 From: = <=> Date: Sun, 10 Jul 2022 21:38:16 +0530 Subject: [PATCH] ncurses menu adapts when window is resized --- gempost | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/gempost b/gempost index c632b95..556c04a 100755 --- a/gempost +++ b/gempost @@ -54,6 +54,7 @@ def menuFunction(menu = [], headerLine = "Use the arrow keys or j,k to make a se highlight, highlight_prev = 0, 0 # variable that controls which entry is selected, variable that stores its previous value while True: + sy, sx = stdscr.getmaxyx() # getting terminal dimensions again to adapt to window resize events while the menu is being displayed stdscr.clear() if (highlight >= endOfPage): # incrementing page number @@ -91,7 +92,13 @@ def menuFunction(menu = [], headerLine = "Use the arrow keys or j,k to make a se for sno in range(len(imenu)): if (sno == highlight): - entry = str(((pageLength)*(pageIndex-1)) + (sno+1)) + " - " + imenu[sno] + entry = str(((pageLength)*(pageIndex-1)) + (sno+1)) + " - " + imenu[sno] # the menu entry + + """ + TODO: + - exit displaying an error if terminal too small + """ + stdscr.addstr(f"\n{entry}{' '*(sx - len(entry) - 1)}", curses.A_STANDOUT) else: stdscr.addstr(f"\n{((pageLength)*(pageIndex-1)) + (sno+1)} - {imenu[sno]}") @@ -296,6 +303,11 @@ def manage(direct = ""): print("\nCancelled.") return 0 + """ + TODO: + - remove the following number input based interface with pressing keys for delete, edit and cancel + """ + print(f"\nYou have selected:\n\nTITLE: {postsList[which][1][:-1]}\nFILENAME: {postsList[which][0]}.gmi") try: