Show review interface partway down the screen
John Smith

John Smith commited on 2023-28 11:53:39
Showing 1 changed files, with 18 additions and 14 deletions.


During a review session, spacing is added to ensure that text displayed
starts 40% of the way down the terminal.
... ...
@@ -27,12 +27,26 @@ local function clear()
27 27
     io.write("\x1b[H\x1b[J")
28 28
 end
29 29
 
30
+--[[
31
+    show progress thru a review session, conditioned on the user
32
+    configuring that to happen
33
+]]
34
+local function showprogress(k, n, conf)
35
+    if conf:get("ShowProgress") then
36
+        io.write(string.format("(%d/%d) ", k, n))
37
+    end
38
+end
39
+
30 40
 --[[
31 41
     display text with images, inserted with `IMG[path]`
32 42
     implementation may be platform-specific
33 43
     `basepath` points to the base directory of the images
34 44
 ]]
35
-local function imgify(text, basepath, conf, boldable)
45
+local function imgify(text, basepath, ind, climn, conf)
46
+    local fh = io.popen("tput lines")
47
+    local tl = tonumber(fh:read("a"))
48
+    io.write(("\n"):rep(math.floor(0.4 * tl)))
49
+    showprogress(ind, climn, conf)
36 50
     if conf:get("BoldContext") then
37 51
         local csi, cei = text:find("^[^:]+:")
38 52
         if csi then
... ...
@@ -141,16 +155,6 @@ local function showpctiles(list, pctiles, func, name)
141 155
     return s .. "\n"
142 156
 end
143 157
 
144
---[[
145
-    show progress thru a review session, conditioned on the user
146
-    configuring that to happen
147
-]]
148
-local function showprogress(k, n, conf)
149
-    if conf:get("ShowProgress") then
150
-        io.write(string.format("(%d/%d) ", k, n))
151
-    end
152
-end
153
-
154 158
 local actions = {
155 159
     a = {
156 160
         desc = "(a)dd card (from stdin)",
... ...
@@ -283,15 +287,15 @@ local actions = {
283 287
                 -- remove braces for display
284 288
                 local pst = pr.text:gsub("%{([^{}]+)%}", "%1")
285 289
                 local st = os.time()
286
-                showprogress(ind, climn, config)
287
-                imgify(pst:gsub("%%A", "___"), deckfname:match(".*/") or "", config)
290
+                imgify(pst:gsub("%%A", "___"), deckfname:match(".*/") or "", ind, climn, config)
288 291
                 io.write("\n")
289 292
                 io.read("l")
290 293
                 clear()
291
-                showprogress(ind, climn, config)
292 294
                 imgify(
293 295
                     pst:gsub("%%A", "\x1b[1m" .. (pr.ans:gsub("%%", "%%%%")) .. "\x1b[0m"),
294 296
                     deckfname:match(".*/") or "",
297
+                    ind,
298
+                    climn,
295 299
                     config
296 300
                 )
297 301
                 io.write(string.format(
298 302