Skip to content
Snippets Groups Projects
Commit 21724e17 authored by Jan Frieder Milke's avatar Jan Frieder Milke
Browse files

menu.py now recognizes MacOS arrow keys and will exit with [Q] or 2x[Esc] on MacOS

parent 21f45ed1
Branches
No related tags found
No related merge requests found
...@@ -74,17 +74,20 @@ def get_key(): ...@@ -74,17 +74,20 @@ def get_key():
while True: while True:
k = inkey() k = inkey()
value = value + k value = value + k
if k == '\x00' or k == '\xe0': pass # 1st check if Esc was hit twice: then only return 1x Esc
if (value == '\x1b\x1b'):return k
# Else read until no special characters are found anymore
elif k == '\x00' or k == '\xe0' or k == '\x1b' or k == '[': pass
elif k != '':break elif k != '':break
return value return value
# Different platforms have different escape keys # Different platforms have different escape keys
arrow_up = ['\x00H', '\xe0H'] arrow_up = ['\x00H', '\xe0H', '\x1b[A']
arrow_down = ['\x00P', '\xe0P'] arrow_down = ['\x00P', '\xe0P', '\x1b[B']
arrow_right = ['\x00M', '\xe0M'] arrow_right = ['\x00M', '\xe0M', '\x1b[C']
arrow_left = ['\x00K', '\xe0K'] arrow_left = ['\x00K', '\xe0K', '\x1b[D']
enter = '\x0d' enter = '\x0d'
escape = '\x1b' escape = ['\x1b', 'q', 'Q']
class Terminal: class Terminal:
REVERSE = '\u001b[7m' REVERSE = '\u001b[7m'
...@@ -121,7 +124,7 @@ class Terminal: ...@@ -121,7 +124,7 @@ class Terminal:
DEFAULT_BOTTOM_TEXT = '[Arrow Up/Down] Change Selection\n' + \ DEFAULT_BOTTOM_TEXT = '[Arrow Up/Down] Change Selection\n' + \
'[Enter] Confirm Selection\n' + \ '[Enter] Confirm Selection\n' + \
'[Esc] Abort' '[Esc]/[Q] Abort'
def showmenu(menu_items, top_text=None, bottom_text=DEFAULT_BOTTOM_TEXT, default_selection=0): def showmenu(menu_items, top_text=None, bottom_text=DEFAULT_BOTTOM_TEXT, default_selection=0):
"""Displays a menu. """Displays a menu.
...@@ -161,7 +164,7 @@ def showmenu(menu_items, top_text=None, bottom_text=DEFAULT_BOTTOM_TEXT, default ...@@ -161,7 +164,7 @@ def showmenu(menu_items, top_text=None, bottom_text=DEFAULT_BOTTOM_TEXT, default
elif k == enter: elif k == enter:
Terminal.clear_screen() Terminal.clear_screen()
return current_selection return current_selection
elif k == escape: elif k in escape:
Terminal.clear_screen() Terminal.clear_screen()
return None return None
......
...@@ -100,7 +100,7 @@ def manage_plugins(): ...@@ -100,7 +100,7 @@ def manage_plugins():
menu_items = [get_plugin_string(plugin_id) for plugin_id in plugin_ids] menu_items = [get_plugin_string(plugin_id) for plugin_id in plugin_ids]
BOTTOM_TEXT = '[Arrow Up/Down] Select Plugin\n' + \ BOTTOM_TEXT = '[Arrow Up/Down] Select Plugin\n' + \
'[Enter] Select Plugin branch\n' + \ '[Enter] Select Plugin branch\n' + \
'[Esc] Confirm selection' '[Esc]/[Q] Confirm selection'
plugin_selection = menu.showmenu(menu_items, bottom_text = BOTTOM_TEXT) plugin_selection = menu.showmenu(menu_items, bottom_text = BOTTOM_TEXT)
if plugin_selection == None: if plugin_selection == None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment