added test options

This commit is contained in:
Nicholas Dyer 2023-12-21 10:18:38 -05:00
parent a35ee174fc
commit 4661239a67
Signed by: ndyer
GPG Key ID: E5426C53DE17E1B2

View File

@ -1,12 +1,60 @@
import keyboard
import time
import os
def put_cursor(line, col):
return f'\033[{int(line)};{int(col)}f'
class Menu:
def __init__(self, start_line):
self.start_line = start_line
self.options = [
'test 1',
'test 2',
'test 3'
]
self.selected = 0
self.highlight = '\033[2;30;42m'
self.regular = '\033[1;32m'
def next(self):
self.selected += 1
if self.selected > len(self.options) - 1:
self.selected = 0
def prev(self):
self.selected -= 1
if self.selected < 0:
self.selected = len(self.options) - 1
def draw(self):
term_size = os.get_terminal_size()
current_line = self.start_line
for i, option in enumerate(self.options):
print(f'{put_cursor(self.start_line + i, 0)}\033[2;0;0m', end='')
print(' ' * term_size.columns, end='\r')
if i == self.selected:
print(f'{self.highlight}{option}')
else:
print(f'{self.regular}{option}')
def main():
selected_item = 0
menu = Menu(10)
menu.draw()
while True:
pressed_key = keyboard.read_event()
if pressed_key.event_type == 'down':
print(pressed_key.name.upper(), end='')
if pressed_key.name == 'j':
menu.next()
elif pressed_key.name == 'k':
menu.prev()
menu.draw()
if __name__ == '__main__':