1 # Display card output and retreive input
7 from .deck import Status
10 def disp_bar(stdscr, stack, headers, obj):
11 (mlines, mcols) = stdscr.getmaxyx()
15 percent = str(round(obj.getIdx() / (len(stack)) * 100)).zfill(3)
17 stdscr.insstr(mlines - 1, 0,
19 stack[obj.getIdx()].printStar() +
23 str(obj.getIdx() + 1) +
28 headers[obj.getSide()] +
32 def disp_menu(stdscr, stack, headers, idx):
33 stdscr.addstr("Good job, you've completed a round!\n\n" +
34 "Choose one of the following options:\n" +
35 "[r]estart, [s]tarred only, [u]nstar all and restart, [q]uit")
38 if key == "q" or key == os.linesep:
42 get_key(stdscr, stack, headers, idx)
47 get_key(stdscr, stack, headers, idx)
56 stack = [x for x in stack if x.getStar()]
57 get_key(stdscr, stack, headers, idx)
60 stdscr.addstr("ERR: Stack empty. Choose another option\n\n")
61 disp_menu(stdscr, stack, headers, idx)
64 def disp_card(stdscr, stack, headers, obj):
66 if obj.getIdx() == len(stack):
67 disp_menu(stdscr, stack, headers, obj)
69 side_title = headers[obj.getSide()]
70 stdscr.addstr(side_title + "\n")
71 for i in range(len(side_title)):
73 stdscr.addstr("\n" + str(stack[obj.getIdx()][obj.getSide()]))
74 disp_bar(stdscr, stack, headers, obj)
77 def get_key(stdscr, stack, headers, idx):
79 disp_card(stdscr, stack, headers, idx)
83 if key == "q" or key == os.linesep:
85 elif key in ["l", "KEY_LEFT"]:
88 disp_card(stdscr, stack, headers, idx)
89 elif key in ["h", "KEY_RIGHT"]:
92 disp_card(stdscr, stack, headers, idx)
93 elif key in ["j", "k", "KEY_UP", "KEY_DOWN"]:
95 disp_card(stdscr, stack, headers, idx)
96 elif key in ["i", "/"]:
97 stack[idx.getIdx()].toggleStar()
98 disp_card(stdscr, stack, headers, idx)