1 # Display card output and retreive input
5 from random import shuffle
9 def disp_bar(stdscr, stack, headers, obj):
10 (mlines, mcols) = stdscr.getmaxyx()
14 percent = str(round(obj.getIdx() / (len(stack) - 1) * 100)).zfill(3)
16 curses.init_pair(1, curses.COLOR_CYAN, 0)
17 stdscr.insstr(mlines - 1, 0,
19 stack[obj.getIdx()].printStar() +
23 str(obj.getIdx() + 1) +
28 headers[obj.getSide()] +
29 "]", curses.color_pair(1))
32 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 if obj.getIdx() == len(stack):
80 disp_menu(stdscr, stack, headers, obj)
82 if obj.getSide() == 0:
83 top = headers[obj.getSide()] + "; " + str(obj.getIdx() + 1) + "\n"
85 top = headers[obj.getSide()] + "; " + str(obj.getIdx() + 1) + \
86 "; " + str(stack[obj.getIdx()][0]) + "\n"
88 stdscr.addstr(top, curses.A_BOLD)
89 (mlines, mcols) = stdscr.getmaxyx()
92 for i in range(mcols):
95 stdscr.addstr("\n" + str(stack[obj.getIdx()][obj.getSide()]))
96 disp_bar(stdscr, stack, headers, obj)
99 def get_key(stdscr, stack, headers, idx):
101 disp_card(stdscr, stack, headers, idx)
104 key = stdscr.getkey()
107 elif key in ["l", "KEY_LEFT"]:
110 disp_card(stdscr, stack, headers, idx)
111 elif key in ["h", "KEY_RIGHT"]:
114 disp_card(stdscr, stack, headers, idx)
115 elif key in ["j", "k", "KEY_UP", "KEY_DOWN"]:
117 disp_card(stdscr, stack, headers, idx)
118 elif key in ["i", "/"]:
119 stack[idx.getIdx()].toggleStar()
120 disp_card(stdscr, stack, headers, idx)
121 elif key in ["0", "^", "KEY_HOME"]:
123 disp_card(stdscr, stack, headers, idx)
124 elif key in ["$", "KEY_END"]:
125 idx.setIdx(len(stack) - 1)
126 disp_card(stdscr, stack, headers, idx)