IngoMeyer441 / simple-term-menu

A Python package which creates simple interactive menus on the command line.
MIT License
492 stars 43 forks source link

Add home/end key support #57

Closed ScoreUnder closed 2 years ago

ScoreUnder commented 2 years ago

This makes the home key (or the emacs/bash-like ctrl+a) scroll to the top of the list, and the end key (or ctrl+e) scroll to the bottom.

ScoreUnder commented 2 years ago

The active_menu_index change was opportunistic:

IngoMeyer441 commented 2 years ago

Thanks for your contribution! The code changes look good to me and the emacs bindings do not clash with vim bindings, so this is definitely a good addition. Probably, most users are used to Emacs bindings from the Bash defaults.

The active_menu_index change was opportunistic:

  • _selected_index was never mentioned anywhere else, so I removed it
  • we had duplicated effort with a loop whose results had already been cached in _menu_index_to_displayed_index
  • since I added a setter for active_displayed_index, I used that instead of repeating the viewport update code

Thanks for your fix. This was old code that unintentionally survived code restructuring. Earlier versions did not have the dict _menu_index_to_displayed_index.