- quit_text = "[q]: back"
- if quit:
- quit_text = "[q]: quit"
-
- self.win.addstr("LIGHTCARDS MENU", curses.color_pair(1) +
- curses.A_BOLD)
- self.win.hline(1, 0, curses.ACS_HLINE, 15)
- self.win.addstr(2, 0, "[y]: reset stack to original state\n" +
- "[a]: alphabetize stack\n" +
- "[z]: shuffle stack\n" +
- "[f]: flip all cards in stack\n" +
- "[t]: reverse stack order\n" +
- "[u]: unstar all\n" +
- "[d]: star all\n" +
- "[s]: update stack to include starred only\n\n" +
- "[r]: restart\n" +
- quit_text)
-
- if keygrab:
- self.menu_grab()
+
+class Display:
+ def __init__(self, stack, headers, obj, view):
+ self.stack = stack
+ self.headers = headers
+ self.obj = obj
+ self.view = view
+
+ def run(self, stdscr):
+ """Set important options that require stdscr before starting"""
+ self.win = stdscr
+ curses.curs_set(0) # Hide cursor
+ curses.use_default_colors() # Allow transparency
+ curses.init_pair(1, curses.COLOR_CYAN, -1)
+ curses.init_pair(2, curses.COLOR_RED, -1)
+ curses.init_pair(3, curses.COLOR_YELLOW, -1)
+
+ self.main_panel = curses.panel.new_panel(self.win)
+ self.menu_obj = Menu(self)
+ self.help_obj = Help(self)
+
+ self.get_key()
+
+ def check_size(self):
+ (mlines, mcols) = self.win.getmaxyx()
+
+ while mlines < 24 or mcols < 60:
+ self.win.clear()
+ self.win.addstr(
+ 0,
+ 0,
+ textwrap.fill(
+ "Terminal too small! Min size 60x24", width=mcols
+ ),
+ )
+ self.win.refresh()
+ (mlines, mcols) = self.win.getmaxyx()
+ time.sleep(0.1)
+ else:
+ self.disp_card()
+
+ def leave(self):
+ """Pickle stack before quitting"""
+ if self.obj.index + 1 == len(self.stack):
+ self.obj.index = 0
+
+ progress.dump(self.stack, runner.get_orig()[1])
+ sys.exit(0)
+
+ def nstarred(self):
+ """Get total number of starred cards"""
+ return [card for card in self.stack if card.starred]
+
+ def disp_bar(self):
+ """
+ Display the statusbar at the bottom of the screen with progress, star
+ status, and card side.
+ """
+ (mlines, mcols) = self.win.getmaxyx()
+ self.win.hline(mlines - 2, 0, 0, mcols)
+
+ # Calculate percent done
+ if len(self.stack) <= 1:
+ percent = "100"
+ else:
+ percent = str(
+ round(self.obj.index / (len(self.stack) - 1) * 100)
+ ).zfill(2)
+
+ # Print yellow if starred
+ if self.current_card().starred:
+ star_color = curses.color_pair(3)
+ else:
+ star_color = curses.color_pair(1)
+
+ # Compose bar text
+ bar_start = "["
+ bar_middle = self.current_card().printStar()
+ bar_end = (
+ f"] [{len(self.nstarred())}/{str(len(self.stack))} starred] "
+ f"[{percent}% ("
+ f"{str(self.obj.index).zfill(len(str(len(self.stack))))}"
+ f"/{str(len(self.stack))})]"
+ )
+ if self.view != 3:
+ bar_end += (
+ f" [{self.get_side()} ("
+ f"{str(int(self.current_card().side) + 1)})]"
+ )
+ bar_end += f" [View {str(self.view)}]"
+
+ # Put it all togethor
+ self.win.addstr(mlines - 1, 0, bar_start, curses.color_pair(1))
+ self.win.addstr(mlines - 1, len(bar_start), bar_middle, star_color)
+ self.win.addstr(
+ mlines - 1,
+ len(bar_start + bar_middle),
+ textwrap.shorten(bar_end, width=mcols - 20, placeholder="…"),
+ curses.color_pair(1),
+ )