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 stdscr.insstr(mlines - 1, 0,
19 stack[obj.getIdx()].printStar() +
23 str(obj.getIdx() + 1) +
28 headers[obj.getSide()] +
30 str(obj.getSide() + 1) +
31 ")]", curses.color_pair(1))
34 def disp_menu(stdscr, stack, headers, idx):
35 stdscr.addstr("Good job, you've completed a round!\n\n",
37 stdscr.addstr("Choose one of the following options:\n" +
39 "[s]: restart with starred only\n" +
40 "[u]: restart and unstar all\n" +
41 "[z]: restart and shuffle cards\n" +
49 get_key(stdscr, stack, headers, idx)
54 get_key(stdscr, stack, headers, idx)
63 stack = [x for x in stack if x.getStar()]
64 get_key(stdscr, stack, headers, idx)
67 stdscr.addstr("ERR: Stack empty. Choose another option\n\n",
69 disp_menu(stdscr, stack, headers, idx)
73 get_key(stdscr, stack, headers, idx)
76 def disp_card(stdscr, stack, headers, obj):
78 (mlines, mcols) = stdscr.getmaxyx()
79 if obj.getIdx() == len(stack):
80 disp_menu(stdscr, stack, headers, obj)
82 if obj.getSide() == 0:
83 top = str(obj.getIdx() + 1) + " | " + headers[obj.getSide()]
85 top = str(obj.getIdx() + 1) + " | " + headers[obj.getSide()] \
86 + " | \"" + str(stack[obj.getIdx()][0]) + "\""
91 stdscr.addstr(textwrap.shorten(top, width=header_width,
92 placeholder="…"), curses.A_BOLD)
95 lin_width = header_width
96 if len(top) < header_width:
98 stdscr.hline(1, 0, curses.ACS_HLINE, lin_width)
104 stdscr.addstr(2, 0, textwrap.fill(stack[obj.getIdx()][obj.getSide()],
106 disp_bar(stdscr, stack, headers, obj)
109 def disp_help(stdscr, stack, headers, idx):
111 stdscr.addstr("LIGHTCARDS HELP SCREEN", curses.color_pair(1))
112 stdscr.hline(1, 0, curses.ACS_HLINE, 23)
114 "Welcome to lightcards. Here are some keybindings to get\n" +
116 "h, left previous card\n" +
117 "l, right next card\n" +
118 "j, k, up, down flip card\n" +
120 "0, ^, home go to start of deck\n" +
121 "$, end go to end of deck\n" +
122 "H, ? open this screen\n\n" +
123 "More information can be found in the man page.\n" +
124 "Press [q], [H], or [?] to go back.")
126 key = stdscr.getkey()
127 if key in ["q", "H", "?"]:
128 get_key(stdscr, stack, headers, idx)
131 def init_disp(stdscr, stack, headers, idx):
133 curses.init_pair(1, curses.COLOR_CYAN, 0)
134 curses.init_pair(2, curses.COLOR_RED, 0)
135 get_key(stdscr, stack, headers, idx)
137 def get_key(stdscr, stack, headers, idx):
138 disp_card(stdscr, stack, headers, idx)
140 key = stdscr.getkey()
143 elif key in ["l", "KEY_LEFT"]:
146 disp_card(stdscr, stack, headers, idx)
147 elif key in ["h", "KEY_RIGHT"]:
150 disp_card(stdscr, stack, headers, idx)
151 elif key in ["j", "k", "KEY_UP", "KEY_DOWN"]:
153 disp_card(stdscr, stack, headers, idx)
154 elif key in ["i", "/"]:
155 stack[idx.getIdx()].toggleStar()
156 disp_card(stdscr, stack, headers, idx)
157 elif key in ["0", "^", "KEY_HOME"]:
160 disp_card(stdscr, stack, headers, idx)
161 elif key in ["$", "KEY_END"]:
162 idx.setIdx(len(stack) - 1)
164 disp_card(stdscr, stack, headers, idx)
165 elif key in ["H", "?"]:
166 disp_help(stdscr, stack, headers, idx)