X-Git-Url: https://git.armaanb.net/?p=lightcards.git;a=blobdiff_plain;f=lightcards%2Fdisplay.py;h=3931e3f84f574f520b9c272850e654ee1d07a25a;hp=e7ebb1fd004354bc9c8849a3ed84696ee18997d5;hb=b43e50be2267001cd085bc5cd1be01a59a5eddea;hpb=1c372ca43e37df3086fea5322aca3196bc3c325c diff --git a/lightcards/display.py b/lightcards/display.py index e7ebb1f..3931e3f 100644 --- a/lightcards/display.py +++ b/lightcards/display.py @@ -108,8 +108,8 @@ class Help(Panel): ) self.win.hline(2, 1, curses.ACS_HLINE, mcols) - for t in enumerate(text): - self.win.addstr(t[0] + 3, 1, t[1]) + for i, content in enumerate(text, 3): + self.win.addstr(i, 1, content) self.win.box() @@ -156,8 +156,8 @@ class Menu(Panel): f"{c('menu_disp')}: close menu", ] - for t in enumerate(text): - self.win.addstr(t[0] + 3, 1, t[1]) + for i, content in enumerate(text, 3): + self.win.addstr(i, 1, content) self.win.box() @@ -207,11 +207,12 @@ class Menu(Panel): shuffle(self.outer.stack) self.menu_print("Stack shuffled!") elif key in self.outer.config["menu_open_file"]: - self.outer.dump() curses.endwin() os.system(f"$EDITOR {self.outer.input_file}"), (self.outer.headers, self.outer.stack) = parse.parse_html( - parse.md2html(self.outer.input_file) + parse.md2html(self.outer.input_file), + self.outer.args, + self.outer.config, ) self.outer.get_key() elif key in self.outer.config["menu_stars_only"]: @@ -254,8 +255,9 @@ class Display: self.headers = headers self.obj = obj self.view = view - self.input_file = args.inp[0] + self.input_file = args.inp self.config = conf + self.args = args def run(self, stdscr): """Set important options that require stdscr before starting""" @@ -308,13 +310,8 @@ class Display: """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. - """ + def prep_bar(self): (mlines, mcols) = self.win.getmaxyx() - self.win.hline(mlines - 3, 0, 0, mcols) # Calculate percent done if len(self.stack) <= 1: @@ -322,46 +319,56 @@ class Display: else: percent = str( round(self.obj.index / (len(self.stack) - 1) * 100) - ).zfill(2) + ).zfill(3) # Print yellow if starred if self.current_card().starred: - star_color = curses.color_pair(3) + self.star_color = curses.color_pair(3) else: - star_color = curses.color_pair(1) + self.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] " + self.bar_start = "[" + self.bar_middle = self.current_card().printStar() + self.bar_end = ( + f"] [{len(self.nstarred())}/{str(len(self.stack))} starred] " + ) if self.view != 3: - bar_end += ( + self.bar_end += ( f" [{self.get_side()} (" f"{str(int(self.current_card().side) + 1)})]" ) - bar_end += f" [View {str(self.view)}]" + self.bar_end += f" [View {str(self.view)}]" + + self.progress = ( + f"[{percent}% (" + f"{str(self.obj.index + 1).zfill(len(str(len(self.stack))))}" + f"/{str(len(self.stack))})] " + ) + def disp_bar(self): + """ + Display the statusbar at the bottom of the screen with progress, star + status, and card side. + """ # Put it all togethor + (mlines, mcols) = self.win.getmaxyx() height = mlines - 2 - self.win.addstr(height, 0, bar_start, curses.color_pair(1)) - self.win.addstr(height, len(bar_start), bar_middle, star_color) + self.win.addstr(height, 0, self.bar_start, curses.color_pair(1)) + self.win.addstr( + height, len(self.bar_start), self.bar_middle, self.star_color + ) self.win.addstr( height, - len(bar_start + bar_middle), - textwrap.shorten(bar_end, width=mcols - 20, placeholder="…"), + len(self.bar_start + self.bar_middle), + textwrap.shorten(self.bar_end, width=mcols - 20, placeholder="…"), curses.color_pair(1), ) - progress = ( - f"[{percent}% (" - f"{str(self.obj.index + 1).zfill(len(str(len(self.stack))))}" - f"/{str(len(self.stack))})] " - ) - self.win.addstr( height + 1, 0, - progress, + self.progress, curses.color_pair(1), ) @@ -369,17 +376,19 @@ class Display: int( self.obj.index / (len(self.stack) - 1) - * (mcols - len(progress)) + * (mcols - len(self.progress)) - 1 ) ): self.win.addch( height + 1, - i + len(progress), + i + len(self.progress), self.config["progress_char"], curses.color_pair(1), ) + self.win.hline(mlines - 3, 0, 0, mcols) + def wrap_width(self): """Calculate the width at which the body text should wrap""" (_, mcols) = self.win.getmaxyx() @@ -397,7 +406,7 @@ class Display: def disp_card(self): (_, mcols) = self.win.getmaxyx() self.main_panel.bottom() - self.win.clear() + self.prep_bar() num_done = str(self.obj.index + 1).zfill(len(str(len(self.stack)))) if self.view in [1, 2, 4]: @@ -425,6 +434,7 @@ class Display: + '"' ) + self.win.clear() self.win.addstr( 0, 0, @@ -446,10 +456,7 @@ class Display: """ Display the contents of the card with both the front and back sides. """ - (_, mcols) = self.win.getmaxyx() - self.main_panel.bottom() self.win.clear() - self.win.addstr( 0, 0, @@ -477,8 +484,8 @@ class Display: ) self.win.hline(1, 0, curses.ACS_HLINE, mcols) - self.disp_bar() self.disp_sidebar() + self.disp_bar() def current_card(self): """Get current card object""" @@ -546,13 +553,13 @@ class Display: nstarred = self.nstarred() for i, card in enumerate(nstarred): - term = card.get()[self.obj.side] + term = card.get(smart=False)[0] if len(term) > 18: term = term[:18] + "…" if i > mlines - 6: for i in range(19): - self.win.addch(mlines - 3, left + i, " ") + self.win.addch(mlines - 4, left + i, " ") self.win.addstr( mlines - 4,