refactor: Improve main loop to provide real-time UI updates during mouse interactions

This commit is contained in:
n loewen (aider) 2025-06-07 21:54:16 +01:00
parent 67e2375acb
commit e663e3b417
1 changed files with 9 additions and 5 deletions

14
gtm2.py
View File

@ -524,23 +524,27 @@ def main(stdscr, filename, show_diff, show_add, show_del, mouse):
state.load_commit_content() state.load_commit_content()
while not state.should_exit: # Initial draw before the main loop starts
draw_ui(stdscr, state) draw_ui(stdscr, state)
while not state.should_exit:
key = stdscr.getch() key = stdscr.getch()
if key == -1: if key == -1:
continue continue
# Process input and update the application state
if key == curses.KEY_RESIZE: if key == curses.KEY_RESIZE:
h, w = stdscr.getmaxyx() h, w = stdscr.getmaxyx()
state.update_dimensions(h, w) state.update_dimensions(h, w)
continue elif state.enable_mouse and key == curses.KEY_MOUSE:
if state.enable_mouse and key == curses.KEY_MOUSE:
handle_mouse_input(stdscr, state) handle_mouse_input(stdscr, state)
else: else:
handle_keyboard_input(key, state) handle_keyboard_input(key, state)
# After every action, redraw the UI to reflect changes immediately.
# This is crucial for real-time feedback during mouse drags.
draw_ui(stdscr, state)
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(description="A \"Git Time Machine\" for viewing file history") parser = argparse.ArgumentParser(description="A \"Git Time Machine\" for viewing file history")
parser.add_argument("-d", "--diff", action="store_true", help="Highlight newly added and deleted lines") parser.add_argument("-d", "--diff", action="store_true", help="Highlight newly added and deleted lines")