Improve bolding/display in reviews
John Smith

John Smith commited on 2022-311 21:12:09
Showing 1 changed files, with 9 additions and 2 deletions.


Fixed the procedure to bold the context prefix on a prompt to handle
the previously-unencountered case in which the prompt has
no such prefix, and replaced the duplicate prompt display
(first to challenge the user, then to reveal the answer)
with a single display, overwritten to include the answer
when appropriate.
... ...
@@ -32,15 +32,17 @@ end
32 32
     implementation may be platform-specific
33 33
     `basepath` points to the base directory of the images
34 34
 ]]
35
-local function imgify(text, basepath, conf)
35
+local function imgify(text, basepath, conf, boldable)
36 36
     if conf:get("BoldContext") then
37 37
         local csi, cei = text:find("^[^:]+:")
38
+        if csi then
38 39
             local cpt = text:sub(csi, cei)
39 40
             io.write("\x1b[1m")
40 41
             io.write(cpt)
41 42
             io.write("\x1b[0m")
42 43
             text = text:sub(cei + 1)
43 44
         end
45
+    end
44 46
     -- adapted from https://stackoverflow.com/a/1579673
45 47
     local IMG_PATTERN = "IMG%[([^%]]+)%]"
46 48
     local PATTERN = "(.-)" .. IMG_PATTERN
... ...
@@ -273,7 +275,12 @@ local actions = {
273 275
                 imgify(pst:gsub("%%A", "___"), deckfname:match(".*/") or "", config)
274 276
                 io.write("\n")
275 277
                 io.read("l")
276
-                imgify(pst:gsub("%%A", (pr.ans:gsub("%%", "%%%%"))), deckfname:match(".*/") or "", config)
278
+                clear()
279
+                imgify(
280
+                    pst:gsub("%%A", "\x1b[1m" .. (pr.ans:gsub("%%", "%%%%")) .. "\x1b[0m"),
281
+                    deckfname:match(".*/") or "",
282
+                    config
283
+                )
277 284
                 io.write(string.format(
278 285
                     "\nAgain / Hard (%s) / Good (%s) / Easy (%s) / Correction ",
279 286
                     disptime(review.schedule(pr, st, 0.5, config)),
280 287