]> git.armaanb.net Git - lightcards.git/commitdiff
Add preliminary views support
authorArmaan Bhojwani <me@armaanb.net>
Fri, 12 Feb 2021 16:16:14 +0000 (11:16 -0500)
committerArmaan Bhojwani <me@armaanb.net>
Fri, 12 Feb 2021 16:16:14 +0000 (11:16 -0500)
lightcards/display.py
man/lightcards.1
man/lightcards.1.md

index d0c24208b5fb11b19b73be81f15e9ede6fb776e6..0e07f9ded03d9cfa449f33664032ec3efdd06262 100644 (file)
@@ -20,7 +20,7 @@ def panel_create(x, y):
 
 
 class Help:
-    def __init__(self, outer, mlines=20, mcols=52):
+    def __init__(self, outer, mlines=21, mcols=52):
         """Initialize help screen"""
         self.outer = outer
         (self.win, self.panel) = panel_create(mlines, mcols)
@@ -40,6 +40,7 @@ class Help:
             "H, ?             open this screen",
             "e                open the input file in $EDITOR",
             "m                open the control menu",
+            "1, 2             switch views",
             "",
             "More information can be found in the man page, or",
             "by running `lightcards --help`.",
@@ -63,7 +64,7 @@ class Help:
     def disp(self):
         """Display help screen"""
         (mlines, mcols) = self.outer.win.getmaxyx()
-        self.win.mvwin(int(mlines / 2) - 10, int(mcols / 2) - 25)
+        self.win.mvwin(int(mlines / 2) - 11, int(mcols / 2) - 25)
         self.panel.show()
 
         while True:
@@ -116,9 +117,6 @@ class Menu:
         else:
             color = curses.color_pair(1)
 
-        for i in range(42):
-            self.win.addch(15, i + 1, " ")
-
         self.win.addstr(15, 1, string, color)
         self.menu_grab()
 
@@ -182,6 +180,9 @@ 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(15, i + 1, " ")
+
         (mlines, mcols) = self.outer.win.getmaxyx()
         self.win.mvwin(int(mlines / 2) - 9, int(mcols / 2) - 21)
         self.panel.show()
@@ -194,6 +195,7 @@ class Display:
         self.stack = stack
         self.headers = headers
         self.obj = obj
+        self.view = 1
 
     def run(self, stdscr):
         """Set important options that require stdscr before starting"""
@@ -262,17 +264,21 @@ class Display:
         else:
             star_color = curses.color_pair(1)
 
-        # Create bar component
+        # 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))})] ["
-            f"{self.headers[self.current_card().side]} ("
-            f"{str(int(self.current_card().side) + 1)})]"
+            f"/{str(len(self.stack))})]"
         )
+        if self.view == 1:
+            bar_end += (
+                f" [{self.headers[self.current_card().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))
@@ -293,54 +299,83 @@ class Display:
         return wrap_width
 
     def disp_card(self):
-        """
-        Display the contents of the card.
-        Shows a header, a horizontal line, and the contents of the current
-        side.
-        """
         (_, mcols) = self.win.getmaxyx()
         self.main_panel.bottom()
         self.win.clear()
-
-        # If on the back of the card, show the content of the front side in
-        # the header
         num_done = str(self.obj.index + 1).zfill(len(str(len(self.stack))))
-        if self.current_card().side == 0:
-            top = num_done + " | " + self.headers[self.current_card().side]
-        else:
-            top = (
-                num_done
-                + " | "
-                + self.headers[self.current_card().side]
-                + ' | "'
-                + str(self.current_card().front)
-                + '"'
+
+        if self.view == 1:
+            """
+            Display the contents of the card.
+            Shows a header, a horizontal line, and the contents of the current
+            side.
+            """
+            # If on the back of the card, show the content of the front side in
+            # the header
+            if self.current_card().side == 0:
+                top = num_done + " | " + self.headers[self.current_card().side]
+            else:
+                top = (
+                    num_done
+                    + " | "
+                    + self.headers[self.current_card().side]
+                    + ' | "'
+                    + str(self.current_card().front)
+                    + '"'
+                )
+
+            self.win.addstr(
+                0,
+                0,
+                textwrap.shorten(top, width=mcols - 20, placeholder="…"),
+                curses.A_BOLD,
             )
 
-        header_width = mcols
-        if mcols > 80:
-            header_width = 80
+            # Show current side
+            self.win.addstr(
+                2,
+                0,
+                textwrap.fill(
+                    self.current_card().get(),
+                    width=self.wrap_width(),
+                ),
+            )
 
-        self.win.addstr(
-            0,
-            0,
-            textwrap.shorten(top, width=header_width, placeholder="…"),
-            curses.A_BOLD,
-        )
+        elif self.view == 2:
+            """
+            Display the contents of the card with both the front and back sides.
+            """
+            (_, mcols) = self.win.getmaxyx()
+            self.main_panel.bottom()
+            self.win.clear()
 
-        # Add horizontal line
-        self.win.hline(1, 0, curses.ACS_HLINE, mcols)
+            self.win.addstr(
+                0,
+                0,
+                textwrap.shorten(
+                    num_done,
+                    width=mcols - 20,
+                    placeholder="…",
+                ),
+                curses.A_BOLD,
+            )
 
-        # Show current side
-        self.win.addstr(
-            2,
-            0,
-            textwrap.fill(
-                self.current_card().get(),
-                width=self.wrap_width(),
-            ),
-        )
+            # Show card content
+            self.win.addstr(
+                2,
+                0,
+                textwrap.fill(
+                    self.headers[0] + ": " + self.current_card().front,
+                    width=self.wrap_width(),
+                )
+                + "\n\n"
+                + textwrap.fill(
+                    self.headers[1] + ": " + self.current_card().back,
+                    width=self.wrap_width(),
+                ),
+            )
 
+        self.win.hline(1, 0, curses.ACS_HLINE, mcols)
         self.disp_bar()
         self.disp_sidebar()
 
@@ -369,7 +404,7 @@ class Display:
                     self.obj.forward(self.stack)
                     self.current_card().side = 0
                     self.disp_card()
-            elif key in ["j", "k", "KEY_UP", "KEY_DOWN"]:
+            elif key in ["j", "k", "KEY_UP", "KEY_DOWN"] and self.view == 1:
                 self.current_card().flip()
                 self.disp_card()
             elif key in ["i", "/"]:
@@ -390,6 +425,8 @@ class Display:
             elif key == "e":
                 (self.headers, self.stack) = runner.reparse()
                 self.get_key()
+            elif key in ["1", "2"]:
+                self.view = int(key)
 
     def disp_sidebar(self):
         """Display a sidebar with the starred terms"""
index ccbf2cde1aa984d599cb0fd551c0ad55b4a64e93..7bf1cc1b0c4bdf6e68ef19dde8cf74f7fb876e53 100644 (file)
@@ -65,6 +65,9 @@ Open input file in $EDITOR
 .TP
 \f[B]m\f[R]
 Open control menu
+.TP
+\f[B]1\f[R], \f[B]2\f[R]
+Switch views
 .SH INPUT FILE
 .PP
 Lightcards takes the first table from a valid Markdown or HTML file.
index 96b62ee0a7a5f94b1d3c3768d1d2c5d8adec63d7..3a0388b70a78892be2fe0032c318ad9f8935a776 100644 (file)
@@ -67,6 +67,9 @@ lightcards \[options\] \[input file\]
 **m**
 : Open control menu
 
+**1**, **2**
+: Switch views
+
 # INPUT FILE
 Lightcards takes the first table from a valid Markdown or HTML file. Each row is a card, and the two columns are the front and back.