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):
34 curses.init_pair(1, curses.COLOR_CYAN, 0)
35 curses.init_pair(2, curses.COLOR_RED, 0)
36 stdscr.addstr("Good job, you've completed a round!\n\n",
38 stdscr.addstr("Choose one of the following options:\n" +
40 "[s]: restart with starred only\n" +
41 "[u]: restart and unstar all\n" +
42 "[z]: restart and shuffle cards\n" +
50 get_key(stdscr, stack, headers, idx)
55 get_key(stdscr, stack, headers, idx)
64 stack = [x for x in stack if x.getStar()]
65 get_key(stdscr, stack, headers, idx)
68 stdscr.addstr("ERR: Stack empty. Choose another option\n\n",
70 disp_menu(stdscr, stack, headers, idx)
74 get_key(stdscr, stack, headers, idx)
77 def disp_card(stdscr, stack, headers, obj):
79 (mlines, mcols) = stdscr.getmaxyx()
80 if obj.getIdx() == len(stack):
81 disp_menu(stdscr, stack, headers, obj)
83 if obj.getSide() == 0:
84 top = headers[obj.getSide()] + "; " + str(obj.getIdx() + 1)
86 top = headers[obj.getSide()] + "; " + str(obj.getIdx() + 1) + \
87 "; " + str(stack[obj.getIdx()][0])
93 stdscr.addstr(textwrap.shorten(top, width=header_width,
94 placeholder="…"), curses.A_BOLD)
100 stdscr.hline(1, 0, curses.ACS_HLINE, lin_width)
106 stdscr.hline(curses.ACS_HLINE, lin_width)
107 stdscr.addstr(2, 0, textwrap.fill(stack[obj.getIdx()][obj.getSide()],
109 disp_bar(stdscr, stack, headers, obj)
112 def get_key(stdscr, stack, headers, idx):
114 disp_card(stdscr, stack, headers, idx)
117 key = stdscr.getkey()
120 elif key in ["l", "KEY_LEFT"]:
123 disp_card(stdscr, stack, headers, idx)
124 elif key in ["h", "KEY_RIGHT"]:
127 disp_card(stdscr, stack, headers, idx)
128 elif key in ["j", "k", "KEY_UP", "KEY_DOWN"]:
130 disp_card(stdscr, stack, headers, idx)
131 elif key in ["i", "/"]:
132 stack[idx.getIdx()].toggleStar()
133 disp_card(stdscr, stack, headers, idx)
134 elif key in ["0", "^", "KEY_HOME"]:
136 disp_card(stdscr, stack, headers, idx)
137 elif key in ["$", "KEY_END"]:
138 idx.setIdx(len(stack) - 1)
139 disp_card(stdscr, stack, headers, idx)