Still experementing
This commit is contained in:
70
main.py
70
main.py
@@ -1,36 +1,48 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import pytermgui as ptg
|
||||
from blessed import Terminal
|
||||
|
||||
# Define empty config as the base
|
||||
#
|
||||
# Note that we define markup tags as empty.
|
||||
# markup tags **need** to be defined for program
|
||||
# execution.
|
||||
PTG_CONFIG = """\
|
||||
config: {}
|
||||
menu = [["login to system"], ["create account"], ["disconnect"]]
|
||||
|
||||
markup:
|
||||
title: 210 bold
|
||||
body: 245 italic
|
||||
"""
|
||||
|
||||
with ptg.WindowManager() as manager:
|
||||
# Initialize a loader, and load our config
|
||||
loader = ptg.YamlLoader()
|
||||
loader.load(PTG_CONFIG)
|
||||
def display_screen(selection):
|
||||
term = Terminal()
|
||||
term.clear()
|
||||
|
||||
# Create a test window
|
||||
manager.add(
|
||||
ptg.Window()
|
||||
+ "[title]This is our title"
|
||||
+ ""
|
||||
+ {"[body]First key": ['First button']}
|
||||
+ {"[body]Second key": ['Second button']}
|
||||
+ {"[body]Third key": ['Third button']}
|
||||
+ ""
|
||||
+ ["Exit", lambda *_: manager.exit()]
|
||||
)
|
||||
for (idx, m) in enumerate(menu):
|
||||
if idx == selection:
|
||||
print('{t.bold_red_reverse}{title}'.format(t=term, title=m[0]))
|
||||
else:
|
||||
print('{t.normal}{title}'.format(t=term, title=m[0]))
|
||||
|
||||
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