Skip to content

Instantly share code, notes, and snippets.

@Zzz9194
Created August 17, 2020 13:36
Show Gist options
  • Save Zzz9194/a29e2743a8f4da9e85fb894645a8e820 to your computer and use it in GitHub Desktop.
Save Zzz9194/a29e2743a8f4da9e85fb894645a8e820 to your computer and use it in GitHub Desktop.
Basic terminal selection menu for my own use
from pynput.keyboard import Listener, Key
import os
current: int = 1
select = None
options = [
"Start",
"Help",
"Exit"
]
def menu():
global current
global select
try:
select = options[current]
except:
select = options[1]
os.system('clear')
for entry in options:
if entry == select:
print(" > " + entry)
else:
print(" " + entry)
def down():
global current
current += 1
menu()
def up():
global current
current -= 1
menu()
def enter():
global select
if select == "Start":
print("Going to Start")
if select == "Help":
print("Going to Help")
if select == "Exit":
print("Exiting...")
def on_press(key: Key):
if key == key.down:
down()
elif key == key.up:
up()
elif key == key.enter:
enter()
else:
pass
if __name__ == "__main__":
menu()
with Listener(on_press=on_press) as listener:
listener.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment