fixed navigation and input bugs

This commit is contained in:
asdf 2021-08-09 20:26:50 +10:00
parent 33e8eca10c
commit aea4572121
1 changed files with 16 additions and 11 deletions

View File

@ -351,7 +351,10 @@ class Output:
self.scrollminy = 0
self.viewslice = None
def Calc_Dimensions(self):
def reset(self):
self.scrollminy = 0
def calc_dimensions(self):
if not self.content:
raise ValueError("Can't calculate nonexistant data")
self.length = len(self.content)
@ -473,14 +476,14 @@ def menu_system(stdscr):
"""main loop of program, prints data and takes action based on user input"""
locale.setlocale(locale.LC_ALL, "")
code = locale.getpreferredencoding()
# curses.use_default_colors()
# curses.curs_set(0)
curses.use_default_colors()
curses.curs_set(0)
title = "Linkulator".encode(code)
menus = MenuHierarchy()
menus.set_active_menu_data(LinkData)
menus.active.output.Calc_Dimensions()
menus.active.output.calc_dimensions()
status = Status()
status.message = ""
@ -507,7 +510,7 @@ def menu_system(stdscr):
stdscr.clrtoeol()
# print body
menus.active.output.Calc_Dimensions()
menus.active.output.calc_dimensions()
count = 0
for i, line in enumerate(
@ -550,15 +553,16 @@ def menu_system(stdscr):
if k == "KEY_RESIZE":
term_resize(stdscr)
elif k in [":", " "]:
iwin = curses.newwin(1, curses.COLS, curses.LINES - 1, 0)
iwin.addch(0, 0, ":")
stdscr.addch(curses.LINES - 1, 0, ":")
stdscr.clrtoeol()
stdscr.refresh()
iwin = curses.newwin(1, curses.COLS, curses.LINES - 1, 1)
itxt = textpad.Textbox(iwin)
itxt.stripspaces = True
curses.curs_set(1)
itxt.edit()
action = itxt.gather()
# action slice to remove : at the start
# TODO: can this be avoided?
handle_action(menus, action[1:], status)
handle_action(menus, action, status)
curses.curs_set(0)
del itxt
del iwin
@ -610,7 +614,8 @@ def navigate(menus, int_action):
menus.active = menus.primary_hierarchy[menus.primary_index]
menus.active.selected_key = key
menus.set_active_menu_data(LinkData)
menus.active.output.Calc_Dimensions()
menus.active.output.reset()
menus.active.output.calc_dimensions()
def do_command(menus, action):