]> git.armaanb.net Git - lightcards.git/blobdiff - lightcards/display.py
Replace $EDITOR in menu with actual editor
[lightcards.git] / lightcards / display.py
index 386058f474bdd50eb6df755aacb235c2c17cb2ac..e91fed1a302db23d1626464d44c869df0c0194b9 100644 (file)
@@ -132,6 +132,7 @@ class Menu:
             curses.color_pair(1) + curses.A_BOLD,
         )
         self.win.hline(2, 1, curses.ACS_HLINE, mcols)
+        env = os.environ.get("EDITOR", "$EDITOR")[:15]
         text = [
             "[y]: reset stack to original state",
             "[a]: alphabetize stack",
@@ -140,8 +141,7 @@ class Menu:
             "[u]: unstar all",
             "[d]: star all",
             "[s]: update stack to include starred only",
-            "[e]: open the input file in $EDITOR",
-            "",
+            f"[e]: open the input file in {env}" "",
             "[r]: restart",
             "[m]: close menu",
         ]
@@ -151,6 +151,10 @@ class Menu:
 
         self.win.box()
 
+    def clear_msg(self):
+        for i in range(42):
+            self.win.addch(15, i + 1, " ")
+
     def menu_print(self, string, err=False):
         """Print messages on the menu screen"""
         if err:
@@ -189,6 +193,7 @@ class Menu:
                 shuffle(self.outer.stack)
                 self.menu_print("Stack shuffled!")
             elif key == "e":
+                progress.dump(self.outer.stack, runner.get_orig()[1])
                 curses.endwin()
                 os.system(f"$EDITOR {self.outer.input_file}"),
                 (self.outer.headers, self.outer.stack) = parse.parse_html(
@@ -220,8 +225,7 @@ class Menu:
         Display a menu offering multiple options on how to manipulate the deck
         and to continue
         """
-        for i in range(42):
-            self.win.addch(14, i + 1, " ")
+        self.clear_msg()
 
         (mlines, mcols) = self.outer.win.getmaxyx()
         self.win.mvwin(int(mlines / 2) - 8, int(mcols / 2) - 22)
@@ -244,9 +248,9 @@ class Display:
         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)
+        curses.init_pair(1, self.config["highlight_color"], -1)
+        curses.init_pair(2, self.config["error_color"], -1)
+        curses.init_pair(3, self.config["starred_color"], -1)
 
         self.main_panel = curses.panel.new_panel(self.win)
         self.menu_obj = Menu(self)
@@ -351,10 +355,11 @@ class Display:
                 - 1
             )
         ):
-            # TODO: Use the variying width unicode block characters to make a
-            # super accurate bar
             self.win.addch(
-                height + 1, i + len(progress), "ยป", curses.color_pair(1)
+                height + 1,
+                i + len(progress),
+                self.config["progress_char"],
+                curses.color_pair(1),
             )
 
     def wrap_width(self):
@@ -477,7 +482,8 @@ class Display:
                 self.disp_card()
             elif key in self.config["card_next"]:
                 if self.obj.index + 1 == len(self.stack):
-                    self.menu_obj.disp()
+                    if self.config["show_menu_at_end"]:
+                        self.menu_obj.disp()
                 else:
                     self.obj.forward(self.stack)
                     self.current_card().side = 0