From: Armaan Bhojwani Date: Mon, 1 Feb 2021 16:35:02 +0000 (-0500) Subject: Add sidebar of starred cards X-Git-Tag: v0.5.0~7 X-Git-Url: https://git.armaanb.net/?p=lightcards.git;a=commitdiff_plain;h=798c62fd2fd9e784a613894d3eb57148400e9b03 Add sidebar of starred cards --- diff --git a/lightcards/display.py b/lightcards/display.py index b4076e5..09f1e52 100644 --- a/lightcards/display.py +++ b/lightcards/display.py @@ -35,7 +35,7 @@ class Display(): Display the statusbar at the bottom of the screen with progress, star status, and card side. """ - (mlines, _) = self.win.getmaxyx() + (mlines, mcols) = self.win.getmaxyx() # Calculate percent done if len(self.stack) <= 1: @@ -60,6 +60,7 @@ class Display(): str(self.obj.getSide() + 1) + ")]" # Put it all togethor + self.win.hline(mlines - 2, 0, 0, mcols) self.win.addstr(mlines - 1, 0, bar_start, curses.color_pair(1)) self.win.addstr(bar_middle, star_color) self.win.insstr(bar_end, curses.color_pair(1)) @@ -154,8 +155,8 @@ class Display(): def wrap_width(self): (_, mcols) = self.win.getmaxyx() - wrap_width = mcols - if mcols > 80: + wrap_width = mcols - 20 + if wrap_width > 80: wrap_width = 80 return wrap_width @@ -197,6 +198,7 @@ class Display(): self.stack[self.obj.getIdx()][self.obj.getSide()], width=self.wrap_width())) self.disp_bar() + self.disp_sidebar() def disp_help(self): """Display help screen""" @@ -267,3 +269,31 @@ class Display(): elif key == "e": (self.headers, self.stack) = lightcards.reparse() self.get_key() + + def disp_sidebar(self): + (mlines, mcols) = self.win.getmaxyx() + self.win.addstr(0, mcols - 16, "STARRED CARDS", + curses.color_pair(3) + curses.A_BOLD) + self.win.vline(0, mcols - 20, 0, mlines) + self.win.hline(1, mcols - 19, 0, mlines) + + total = [card for card in self.stack if card.getStar()] + ntotal = len(total) + + i = 0 + for card in self.stack: + if i > mlines - 6: + self.win.addstr(2 + i, mcols - 19, f"... ({ntotal - i} more)") + break + elif card.getStar(): + term = card[0] + if len(card[0]) > 18: + term = card[0][:18] + "…" + self.win.addstr(2 + i, mcols - 19, term) + + i += 1 + + if i == 0: + self.win.addstr(2, mcols - 19, "None starred") + + self.win.addstr(mlines - 1, mcols - 19, f"{ntotal}/{str(len(self.stack))}")