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()] +
30 "]", curses.color_pair(1))
33 def disp_menu(stdscr, stack, headers, idx):
35 curses.init_pair(1, curses.COLOR_CYAN, 0)
36 curses.init_pair(2, curses.COLOR_RED, 0)
37 stdscr.addstr("Good job, you've completed a round!\n\n",
39 stdscr.addstr("Choose one of the following options:\n" +
41 "[s]: restart with starred only\n" +
42 "[u]: restart and unstar all\n" +
43 "[z]: restart and shuffle cards\n" +
51 get_key(stdscr, stack, headers, idx)
56 get_key(stdscr, stack, headers, idx)
65 stack = [x for x in stack if x.getStar()]
66 get_key(stdscr, stack, headers, idx)
69 stdscr.addstr("ERR: Stack empty. Choose another option\n\n",
71 disp_menu(stdscr, stack, headers, idx)
75 get_key(stdscr, stack, headers, idx)
78 def disp_card(stdscr, stack, headers, obj):
80 (mlines, mcols) = stdscr.getmaxyx()
81 if obj.getIdx() == len(stack):
82 disp_menu(stdscr, stack, headers, obj)
84 if obj.getSide() == 0:
85 top = headers[obj.getSide()] + "; " + str(obj.getIdx() + 1)
87 top = headers[obj.getSide()] + "; " + str(obj.getIdx() + 1) + \
88 "; " + str(stack[obj.getIdx()][0])
94 stdscr.addstr(textwrap.shorten(top, width=header_width,
95 placeholder="…"), curses.A_BOLD)
101 stdscr.hline(1, 0, curses.ACS_HLINE, lin_width)
107 stdscr.hline(curses.ACS_HLINE, lin_width)
108 stdscr.addstr(2, 0, textwrap.fill(stack[obj.getIdx()][obj.getSide()],
110 disp_bar(stdscr, stack, headers, obj)
113 def get_key(stdscr, stack, headers, idx):
115 disp_card(stdscr, stack, headers, idx)
118 key = stdscr.getkey()
121 elif key in ["l", "KEY_LEFT"]:
124 disp_card(stdscr, stack, headers, idx)
125 elif key in ["h", "KEY_RIGHT"]:
128 disp_card(stdscr, stack, headers, idx)
129 elif key in ["j", "k", "KEY_UP", "KEY_DOWN"]:
131 disp_card(stdscr, stack, headers, idx)
132 elif key in ["i", "/"]:
133 stack[idx.getIdx()].toggleStar()
134 disp_card(stdscr, stack, headers, idx)
135 elif key in ["0", "^", "KEY_HOME"]:
137 disp_card(stdscr, stack, headers, idx)
138 elif key in ["$", "KEY_END"]:
139 idx.setIdx(len(stack) - 1)
140 disp_card(stdscr, stack, headers, idx)