1 # Display card output and retreive input
5 from random import shuffle
8 def disp_bar(stdscr, stack, headers, obj):
9 (mlines, mcols) = stdscr.getmaxyx()
13 percent = str(round(obj.getIdx() / (len(stack) - 1) * 100)).zfill(3)
15 stdscr.insstr(mlines - 1, 0,
17 stack[obj.getIdx()].printStar() +
21 str(obj.getIdx() + 1) +
26 headers[obj.getSide()] +
30 def disp_menu(stdscr, stack, headers, idx):
31 stdscr.addstr("Good job, you've completed a round!\n\n" +
32 "Choose one of the following options:\n" +
34 "[s]: restart with starred only\n" +
35 "[u]: restart and unstar all\n" +
36 "[z]: restart and shuffle cards\n" +
44 get_key(stdscr, stack, headers, idx)
49 get_key(stdscr, stack, headers, idx)
58 stack = [x for x in stack if x.getStar()]
59 get_key(stdscr, stack, headers, idx)
62 stdscr.addstr("ERR: Stack empty. Choose another option\n\n")
63 disp_menu(stdscr, stack, headers, idx)
67 get_key(stdscr, stack, headers, idx)
70 def disp_card(stdscr, stack, headers, obj):
72 if obj.getIdx() == len(stack):
73 disp_menu(stdscr, stack, headers, obj)
75 if obj.getSide() == 0:
76 top = headers[obj.getSide()] + " " + str(obj.getIdx() + 1) + "\n"
78 top = headers[obj.getSide()] + " " + str(obj.getIdx() + 1) + \
79 "; " + str(stack[obj.getIdx()][0]) + "\n"
82 for i in range(len(top)):
84 stdscr.addstr("\n" + str(stack[obj.getIdx()][obj.getSide()]))
85 disp_bar(stdscr, stack, headers, obj)
88 def get_key(stdscr, stack, headers, idx):
90 disp_card(stdscr, stack, headers, idx)
96 elif key in ["l", "KEY_LEFT"]:
99 disp_card(stdscr, stack, headers, idx)
100 elif key in ["h", "KEY_RIGHT"]:
103 disp_card(stdscr, stack, headers, idx)
104 elif key in ["j", "k", "KEY_UP", "KEY_DOWN"]:
106 disp_card(stdscr, stack, headers, idx)
107 elif key in ["i", "/"]:
108 stack[idx.getIdx()].toggleStar()
109 disp_card(stdscr, stack, headers, idx)
110 elif key in ["0", "^", "KEY_HOME"]:
112 disp_card(stdscr, stack, headers, idx)
113 elif key in ["$", "KEY_END"]:
114 idx.setIdx(len(stack) - 1)
115 disp_card(stdscr, stack, headers, idx)