Still experementing
This commit is contained in:
70
main.py
70
main.py
@@ -1,36 +1,48 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import sys
|
from blessed import Terminal
|
||||||
import pytermgui as ptg
|
|
||||||
|
|
||||||
# Define empty config as the base
|
menu = [["login to system"], ["create account"], ["disconnect"]]
|
||||||
#
|
|
||||||
# Note that we define markup tags as empty.
|
|
||||||
# markup tags **need** to be defined for program
|
|
||||||
# execution.
|
|
||||||
PTG_CONFIG = """\
|
|
||||||
config: {}
|
|
||||||
|
|
||||||
markup:
|
|
||||||
title: 210 bold
|
|
||||||
body: 245 italic
|
|
||||||
"""
|
|
||||||
|
|
||||||
with ptg.WindowManager() as manager:
|
def display_screen(selection):
|
||||||
# Initialize a loader, and load our config
|
term = Terminal()
|
||||||
loader = ptg.YamlLoader()
|
term.clear()
|
||||||
loader.load(PTG_CONFIG)
|
|
||||||
|
|
||||||
# Create a test window
|
for (idx, m) in enumerate(menu):
|
||||||
manager.add(
|
if idx == selection:
|
||||||
ptg.Window()
|
print('{t.bold_red_reverse}{title}'.format(t=term, title=m[0]))
|
||||||
+ "[title]This is our title"
|
else:
|
||||||
+ ""
|
print('{t.normal}{title}'.format(t=term, title=m[0]))
|
||||||
+ {"[body]First key": ['First button']}
|
|
||||||
+ {"[body]Second key": ['Second button']}
|
|
||||||
+ {"[body]Third key": ['Third button']}
|
|
||||||
+ ""
|
|
||||||
+ ["Exit", lambda *_: manager.exit()]
|
|
||||||
)
|
|
||||||
|
|
||||||
manager.run()
|
|
||||||
|
def run_selection(selection):
|
||||||
|
term.green_reverse('Running {}'.format(menu[selection][0]))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
term = Terminal()
|
||||||
|
with term.fullscreen():
|
||||||
|
selection = 0
|
||||||
|
display_screen(selection)
|
||||||
|
selection_inprogress = True
|
||||||
|
with term.cbreak():
|
||||||
|
while selection_inprogress:
|
||||||
|
key = term.inkey()
|
||||||
|
if key.is_sequence:
|
||||||
|
if key.name == 'KEY_TAB':
|
||||||
|
selection += 1
|
||||||
|
if key.name == 'KEY_DOWN':
|
||||||
|
selection += 1
|
||||||
|
if key.name == 'KEY_UP':
|
||||||
|
selection -= 1
|
||||||
|
if key.name == 'KEY_ENTER':
|
||||||
|
selection_inprogress = False
|
||||||
|
elif key:
|
||||||
|
print("got {0}.".format(key))
|
||||||
|
|
||||||
|
selection = selection % len(menu)
|
||||||
|
|
||||||
|
display_screen(selection)
|
||||||
|
|
||||||
|
run_selection(selection)
|
||||||
|
Reference in New Issue
Block a user