dumb cmatrix test
This commit is contained in:
parent
3cfb002b1e
commit
a52254ef57
@ -6,6 +6,10 @@ TEXT_HIGHLIGHTED = '\033[38;5;0m\033[48;5;2m'
|
|||||||
RESET_CODE = '\033[2;0;0m'
|
RESET_CODE = '\033[2;0;0m'
|
||||||
|
|
||||||
|
|
||||||
|
def matrix():
|
||||||
|
os.system('cmatrix')
|
||||||
|
|
||||||
|
|
||||||
class Text:
|
class Text:
|
||||||
def __init__(self, text: str):
|
def __init__(self, text: str):
|
||||||
self.text = text
|
self.text = text
|
||||||
@ -29,17 +33,21 @@ class Menu:
|
|||||||
def __init__(self, title: str, options: dict):
|
def __init__(self, title: str, options: dict):
|
||||||
self.title = f'[{title}]'
|
self.title = f'[{title}]'
|
||||||
self.options = options
|
self.options = options
|
||||||
self.selected = 0
|
self.cursor_pos = 0
|
||||||
|
self.selected = None
|
||||||
|
|
||||||
def next(self):
|
def next(self):
|
||||||
self.selected += 1
|
self.cursor_pos += 1
|
||||||
if self.selected > len(self.options) - 1:
|
if self.cursor_pos > len(self.options) - 1:
|
||||||
self.selected = 0
|
self.cursor_pos = 0
|
||||||
|
|
||||||
def prev(self):
|
def prev(self):
|
||||||
self.selected -= 1
|
self.cursor_pos -= 1
|
||||||
if self.selected < 0:
|
if self.cursor_pos < 0:
|
||||||
self.selected = len(self.options) - 1
|
self.cursor_pos = len(self.options) - 1
|
||||||
|
|
||||||
|
def execute(self):
|
||||||
|
globals()[self.selected]()
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
term_dims = os.get_terminal_size()
|
term_dims = os.get_terminal_size()
|
||||||
@ -47,10 +55,11 @@ class Menu:
|
|||||||
Text(self.title).draw_at(1, title_start)
|
Text(self.title).draw_at(1, title_start)
|
||||||
|
|
||||||
for i, k in enumerate(self.options):
|
for i, k in enumerate(self.options):
|
||||||
if i == self.selected:
|
if i == self.cursor_pos:
|
||||||
Text(k).highlight().draw_at(i + 2, 1)
|
Text(k).highlight().draw_at(i + 2, 1)
|
||||||
else:
|
else:
|
||||||
Text(k).draw_at(i + 2, 1)
|
Text(k).draw_at(i + 2, 1)
|
||||||
|
self.selected = self.options.get(k)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -61,7 +70,8 @@ def main():
|
|||||||
menu = Menu('Test Menu', {
|
menu = Menu('Test Menu', {
|
||||||
'Option 1:': 'opt',
|
'Option 1:': 'opt',
|
||||||
'Option 2:': 'opt2',
|
'Option 2:': 'opt2',
|
||||||
'Option 3:': 'opt3'
|
'Option 3:': 'opt3',
|
||||||
|
'Enter the Matrix': 'matrix'
|
||||||
})
|
})
|
||||||
menu.draw()
|
menu.draw()
|
||||||
while True:
|
while True:
|
||||||
@ -71,6 +81,8 @@ def main():
|
|||||||
menu.next()
|
menu.next()
|
||||||
elif pressed_key.name == 'k':
|
elif pressed_key.name == 'k':
|
||||||
menu.prev()
|
menu.prev()
|
||||||
|
elif pressed_key.name == 'enter':
|
||||||
|
menu.execute()
|
||||||
menu.draw()
|
menu.draw()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user