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 curses.init_pair(1, curses.COLOR_CYAN, 0)
16 stdscr.insstr(mlines - 1, 0,
18 stack[obj.getIdx()].printStar() +
22 str(obj.getIdx() + 1) +
27 headers[obj.getSide()] +
28 "]", curses.color_pair(1))
31 def disp_menu(stdscr, stack, headers, idx):
32 curses.init_pair(1, curses.COLOR_CYAN, 0)
33 curses.init_pair(2, curses.COLOR_RED, 0)
34 stdscr.addstr("Good job, you've completed a round!\n\n",
36 stdscr.addstr("Choose one of the following options:\n" +
38 "[s]: restart with starred only\n" +
39 "[u]: restart and unstar all\n" +
40 "[z]: restart and shuffle cards\n" +
48 get_key(stdscr, stack, headers, idx)
53 get_key(stdscr, stack, headers, idx)
62 stack = [x for x in stack if x.getStar()]
63 get_key(stdscr, stack, headers, idx)
66 stdscr.addstr("ERR: Stack empty. Choose another option\n\n",
68 disp_menu(stdscr, stack, headers, idx)
72 get_key(stdscr, stack, headers, idx)
75 def disp_card(stdscr, stack, headers, obj):
77 if obj.getIdx() == len(stack):
78 disp_menu(stdscr, stack, headers, obj)
80 if obj.getSide() == 0:
81 top = headers[obj.getSide()] + " " + str(obj.getIdx() + 1) + "\n"
83 top = headers[obj.getSide()] + " " + str(obj.getIdx() + 1) + \
84 "; " + str(stack[obj.getIdx()][0]) + "\n"
86 stdscr.addstr(top, curses.A_BOLD)
87 (mlines, mcols) = stdscr.getmaxyx()
90 for i in range(mcols):
93 stdscr.addstr("\n" + str(stack[obj.getIdx()][obj.getSide()]))
94 disp_bar(stdscr, stack, headers, obj)
97 def get_key(stdscr, stack, headers, idx):
99 disp_card(stdscr, stack, headers, idx)
102 key = stdscr.getkey()
105 elif key in ["l", "KEY_LEFT"]:
108 disp_card(stdscr, stack, headers, idx)
109 elif key in ["h", "KEY_RIGHT"]:
112 disp_card(stdscr, stack, headers, idx)
113 elif key in ["j", "k", "KEY_UP", "KEY_DOWN"]:
115 disp_card(stdscr, stack, headers, idx)
116 elif key in ["i", "/"]:
117 stack[idx.getIdx()].toggleStar()
118 disp_card(stdscr, stack, headers, idx)
119 elif key in ["0", "^", "KEY_HOME"]:
121 disp_card(stdscr, stack, headers, idx)
122 elif key in ["$", "KEY_END"]:
123 idx.setIdx(len(stack) - 1)
124 disp_card(stdscr, stack, headers, idx)