Designed the windows and settled with ncurses

This commit is contained in:
Ricardo
2022-06-01 02:36:35 +00:00
parent b0a58c3a05
commit a228ccf608
2 changed files with 120 additions and 36 deletions

75
main.py
View File

@@ -1,48 +1,51 @@
#!/usr/bin/env python3
from blessed import Terminal
menu = [["login to system"], ["create account"], ["disconnect"]]
import curses
from curses import wrapper
def display_screen(selection):
term = Terminal()
term.clear()
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]))
class MyApp(object):
def __init__(self, screen):
curses.curs_set(0)
curses.init_color(0,0,0,0)
screen.box()
Cols22 = (curses.COLS - 2) * 0.22
Cols22 = int(Cols22)
Cols56 = (curses.COLS - 2) * 0.56
Cols56 = int(Cols56) + 1
Lines = (curses.LINES -2) * 0.95
Lines = int(Lines)
title = "Sparks-Skraps" + " COLS -> " + str(curses.COLS) + " LINES -> " + str(Cols56)
titlePos = (curses.COLS / 2) - (len(title) / 2)
screen.addstr(1, int(titlePos), title)
screen.refresh()
def run_selection(selection):
term.green_reverse('Running {}'.format(menu[selection][0]))
components = curses.newwin(Lines,Cols22,3,1)
components.box()
components.addstr(1, 1, "precious components")
components.refresh()
parts = curses.newwin(Lines, Cols22, 3, 1+Cols22)
parts.box()
parts.addstr(1, 1, "My precious parts")
parts.refresh()
info = curses.newwin(Lines, Cols56, 3, 1+Cols22*2)
info.box()
info.addstr(1, 1, "My precious info")
info.refresh()
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))
c = screen.getch()
selection = selection % len(menu)
display_screen(selection)
run_selection(selection)
if __name__ == "__main__":
curses.wrapper(MyApp)