- stdscr.insch(mlines, mcols+2, '2')
- stdscr.insch(mlines, mcols+3, '/')
- stdscr.insch(mlines, mcols+4, str(len(stack)))
- except:
- pass
-
-def get_key(stdscr, stack, headers):
- idx = Status()
- curses.curs_set(0)
- disp_card(stdscr, stack, headers, idx)
-
- while True:
- key = stdscr.getkey()
- try:
- if key == "q" or key == os.linesep:
- exit(0)
- if key == "j":
- idx.forward(stack)
- idx.setSide(0)
- disp_card(stdscr, stack, headers, idx)
- if key == "k":
- idx.back()
- idx.setSide(0)
- disp_card(stdscr, stack, headers, idx)
- if key == "l" or key == "h":
- idx.flip()
- disp_card(stdscr, stack, headers, idx)
- except Exception:
- pass
+ top = (
+ num_done
+ + " | "
+ + self.headers[self.current_card().side]
+ + ' | "'
+ + str(self.current_card().front)
+ + '"'
+ )
+ header_width = mcols
+ if mcols > 80:
+ header_width = 80
+
+ self.main_win.addstr(
+ 0,
+ 0,
+ textwrap.shorten(top, width=header_width, placeholder="…"),
+ curses.A_BOLD,
+ )
+
+ # Add horizontal line
+ lin_width = header_width
+ if len(top) < header_width:
+ lin_width = len(top)
+ self.main_win.hline(1, 0, curses.ACS_HLINE, lin_width)
+
+ # Show current side
+ self.main_win.addstr(
+ 2,
+ 0,
+ textwrap.fill(
+ self.current_card().get(),
+ width=self.wrap_width(),
+ ),
+ )
+ self.update_panels()
+ self.disp_bar()
+ self.disp_sidebar()
+ self.win.hline(mlines - 2, 0, 0, mcols)
+
+ def current_card(self):
+ """Get current card object"""
+ return self.stack[self.obj.index]
+
+ def get_key(self):
+ """
+ Display a card and wait for the input.
+ Used as a general way of getting back into the card flow from a menu
+ """
+ self.disp_card()
+ while True:
+ key = self.win.getkey()
+ if key == "q":
+ self.leave()
+ elif key in ["h", "KEY_LEFT"]:
+ self.obj.back()
+ self.current_card().side = 0
+ self.disp_card()
+ elif key in ["l", "KEY_RIGHT"]:
+ if self.obj.index + 1 == len(self.stack):
+ self.menu_obj.disp()
+ else:
+ self.obj.forward(self.stack)
+ self.current_card().side = 0
+ self.disp_card()
+ elif key in ["j", "k", "KEY_UP", "KEY_DOWN"]:
+ self.current_card().flip()
+ self.disp_card()
+ elif key in ["i", "/"]:
+ self.current_card().toggleStar()
+ self.disp_card()
+ elif key in ["0", "^", "KEY_HOME"]:
+ self.obj.index = 0
+ self.current_card().side = 0
+ self.disp_card()
+ elif key in ["$", "KEY_END"]:
+ self.obj.index = len(self.stack) - 1
+ self.current_card().side = 0
+ self.disp_card()
+ elif key in ["H", "?"]:
+ self.help_obj.disp()
+ elif key == "m":
+ self.menu_obj.disp()
+ elif key == "e":
+ (self.headers, self.stack) = runner.reparse()
+ self.get_key()
+
+ def disp_sidebar(self):
+ """Display a sidebar with the starred terms"""
+ (mlines, mcols) = self.win.getmaxyx()
+ left = mcols - 19
+
+ self.win.addstr(
+ 0,
+ mcols - 16,
+ "STARRED CARDS",
+ curses.color_pair(3) + curses.A_BOLD,
+ )
+ self.win.vline(0, mcols - 20, 0, mlines - 2)
+ self.win.hline(1, left, 0, mlines)
+
+ nstarred = self.nstarred()
+ if mlines - 5 < len(self.nstarred()):
+ nstarred = self.nstarred()[: mlines - 4]
+ elif mlines - 5 == len(self.nstarred()):
+ nstarred = self.nstarred()[: mlines - 3]
+
+ for _ in nstarred:
+ for i, card in enumerate(nstarred):
+ term = card.front
+ if len(term) > 18:
+ term = term + "…"
+ self.win.addstr(2 + i, left, term)
+ if not nstarred == self.nstarred():
+ self.win.addstr(
+ mlines - 3,
+ left,
+ f"({len(self.nstarred()) - len(nstarred)} more)",
+ )
+ break
+
+ if len(self.nstarred()) == 0:
+ self.win.addstr(2, left, "None starred")