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)
"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`.",
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:
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()
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()
self.stack = stack
self.headers = headers
self.obj = obj
+ self.view = 1
def run(self, stdscr):
"""Set important options that require stdscr before starting"""
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))
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()
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", "/"]:
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"""