ncurses menu adapts when window is resized

This commit is contained in:
= 2022-07-10 21:38:16 +05:30
parent aad657b76b
commit b63e04943a
1 changed files with 13 additions and 1 deletions

14
gempost
View File

@ -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: