Fixed error when there were no posts to manage.
This commit is contained in:
parent
8def32624b
commit
d749642608
35
gempost
35
gempost
|
@ -49,7 +49,7 @@ def menuFunction(menu = []):
|
||||||
|
|
||||||
if (menu == []): # do nothing if list is empty
|
if (menu == []): # do nothing if list is empty
|
||||||
curses.endwin()
|
curses.endwin()
|
||||||
print("There is nothing to manage.")
|
print("\nYou don't have any posts yet.")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
highlight, highlight_prev = 0, 0 # variable that controls which entry is selected, variable that stores its previous value
|
highlight, highlight_prev = 0, 0 # variable that controls which entry is selected, variable that stores its previous value
|
||||||
|
@ -84,7 +84,6 @@ def menuFunction(menu = []):
|
||||||
imenu = menu[((pageLength)*(pageIndex-1)):(pageLength*pageIndex)]
|
imenu = menu[((pageLength)*(pageIndex-1)):(pageLength*pageIndex)]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
#sno = pageLength*(pageIndex-1)
|
|
||||||
endOfPage = len(imenu)
|
endOfPage = len(imenu)
|
||||||
highlight = endOfPage - 1
|
highlight = endOfPage - 1
|
||||||
|
|
||||||
|
@ -102,11 +101,7 @@ def menuFunction(menu = []):
|
||||||
|
|
||||||
c = stdscr.getch()
|
c = stdscr.getch()
|
||||||
|
|
||||||
if (c == ord('c')): # None is returned so that no action is taken
|
if (c == curses.KEY_DOWN):
|
||||||
highlight = None
|
|
||||||
break
|
|
||||||
|
|
||||||
elif (c == curses.KEY_DOWN):
|
|
||||||
highlight_prev = highlight
|
highlight_prev = highlight
|
||||||
highlight += 1
|
highlight += 1
|
||||||
|
|
||||||
|
@ -117,6 +112,10 @@ def menuFunction(menu = []):
|
||||||
elif (c == curses.KEY_ENTER or c == 10 or c == 13):
|
elif (c == curses.KEY_ENTER or c == 10 or c == 13):
|
||||||
break
|
break
|
||||||
|
|
||||||
|
elif (c == ord('c')):
|
||||||
|
highlight = None
|
||||||
|
break
|
||||||
|
|
||||||
curses.endwin()
|
curses.endwin()
|
||||||
if (highlight != None):
|
if (highlight != None):
|
||||||
return (pageLength * (pageIndex-1)) + highlight
|
return (pageLength * (pageIndex-1)) + highlight
|
||||||
|
@ -265,8 +264,8 @@ def manage():
|
||||||
with open(f"{indexFile}",'r') as i:
|
with open(f"{indexFile}",'r') as i:
|
||||||
allposts = i.readlines()
|
allposts = i.readlines()
|
||||||
|
|
||||||
if (len(allposts) == 0): # exit function if no files in index
|
#if (len(allposts) == 0): # exit function if no files in index
|
||||||
return 0
|
#return 0
|
||||||
|
|
||||||
postsList = []
|
postsList = []
|
||||||
for i in allposts: # creating a list containing titles corresponding to filenames
|
for i in allposts: # creating a list containing titles corresponding to filenames
|
||||||
|
@ -276,21 +275,13 @@ def manage():
|
||||||
for i in postsList: # formatting it into a string list for the ncurses menu function
|
for i in postsList: # formatting it into a string list for the ncurses menu function
|
||||||
menuItems.append(f"{i[0]} | {i[1]}")
|
menuItems.append(f"{i[0]} | {i[1]}")
|
||||||
|
|
||||||
"""
|
|
||||||
print() # line break
|
|
||||||
try:
|
|
||||||
counter = 0
|
|
||||||
for i in postsList:
|
|
||||||
print(f"{counter}. {i[0]} | {i[1]}")
|
|
||||||
counter += 1
|
|
||||||
which = int(input("\nSelect which post to manage (any other key to cancel): ")) # getting the index of the menu entry the user wants to edit
|
|
||||||
temp = allposts[which]
|
|
||||||
except:
|
|
||||||
prRed("\n Invalid selection. Exiting...")
|
|
||||||
return 0
|
|
||||||
"""
|
|
||||||
|
|
||||||
which = menuFunction(menuItems)
|
which = menuFunction(menuItems)
|
||||||
|
|
||||||
|
if (which == None): # menuFunction returns None if the list supplied to it is empty
|
||||||
|
print("\nCancelled.")
|
||||||
|
return 0
|
||||||
|
|
||||||
print(f"\nYou have selected:\n\nTitle: {postsList[which][0]}\nFilename: {postsList[which][1]}.gmi")
|
print(f"\nYou have selected:\n\nTitle: {postsList[which][0]}\nFilename: {postsList[which][1]}.gmi")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user