1 # Display card output and retreive input
5 from random import shuffle
10 def disp_bar(stdscr, stack, headers, obj):
11 (mlines, mcols) = stdscr.getmaxyx()
15 percent = str(round(obj.getIdx() / (len(stack) - 1) * 100)).zfill(3)
17 curses.init_pair(1, curses.COLOR_CYAN, 0)
18 stdscr.insstr(mlines - 1, 0,
20 stack[obj.getIdx()].printStar() +
24 str(obj.getIdx() + 1) +
29 headers[obj.getSide()] +
31 str(obj.getSide() + 1) +
32 ")]", curses.color_pair(1))
35 def disp_menu(stdscr, stack, headers, idx):
36 curses.init_pair(1, curses.COLOR_CYAN, 0)
37 curses.init_pair(2, curses.COLOR_RED, 0)
38 stdscr.addstr("Good job, you've completed a round!\n\n",
40 stdscr.addstr("Choose one of the following options:\n" +
42 "[s]: restart with starred only\n" +
43 "[u]: restart and unstar all\n" +
44 "[z]: restart and shuffle cards\n" +
52 get_key(stdscr, stack, headers, idx)
57 get_key(stdscr, stack, headers, idx)
66 stack = [x for x in stack if x.getStar()]
67 get_key(stdscr, stack, headers, idx)
70 stdscr.addstr("ERR: Stack empty. Choose another option\n\n",
72 disp_menu(stdscr, stack, headers, idx)
76 get_key(stdscr, stack, headers, idx)
79 def disp_card(stdscr, stack, headers, obj):
81 (mlines, mcols) = stdscr.getmaxyx()
82 if obj.getIdx() == len(stack):
83 disp_menu(stdscr, stack, headers, obj)
85 if obj.getSide() == 0:
86 top = headers[obj.getSide()] + "; " + str(obj.getIdx() + 1)
88 top = headers[obj.getSide()] + "; " + str(obj.getIdx() + 1) + \
89 "; " + str(stack[obj.getIdx()][0])
95 stdscr.addstr(textwrap.shorten(top, width=header_width,
96 placeholder="…"), curses.A_BOLD)
102 stdscr.hline(1, 0, curses.ACS_HLINE, lin_width)
108 stdscr.hline(curses.ACS_HLINE, lin_width)
109 stdscr.addstr(2, 0, textwrap.fill(stack[obj.getIdx()][obj.getSide()],
111 disp_bar(stdscr, stack, headers, obj)
114 def get_key(stdscr, stack, headers, idx):
116 disp_card(stdscr, stack, headers, idx)
119 key = stdscr.getkey()
122 elif key in ["l", "KEY_LEFT"]:
125 disp_card(stdscr, stack, headers, idx)
126 elif key in ["h", "KEY_RIGHT"]:
129 disp_card(stdscr, stack, headers, idx)
130 elif key in ["j", "k", "KEY_UP", "KEY_DOWN"]:
132 disp_card(stdscr, stack, headers, idx)
133 elif key in ["i", "/"]:
134 stack[idx.getIdx()].toggleStar()
135 disp_card(stdscr, stack, headers, idx)
136 elif key in ["0", "^", "KEY_HOME"]:
139 disp_card(stdscr, stack, headers, idx)
140 elif key in ["$", "KEY_END"]:
141 idx.setIdx(len(stack) - 1)
143 disp_card(stdscr, stack, headers, idx)