Load images relative to repository independent of working directory
John Smith

John Smith commited on 2022-30 21:52:21
Showing 1 changed files, with 6 additions and 5 deletions.

... ...
@@ -39,17 +39,18 @@ local function clear()
39 39
 end
40 40
 
41 41
 --[[
42
-    display text with images, inserted with `IMG:path`
42
+    display text with images, inserted with `IMG[path]`
43 43
     implementation may be platform-specific
44
+    `basepath` points to the base directory of the images
44 45
 ]]
45
-local function imgify(text)
46
+local function imgify(text, basepath)
46 47
     -- adapted from https://stackoverflow.com/a/1579673
47 48
     local PATTERN = "(.-)IMG%[([^%]]+)%]"
48 49
     -- Cygwin/Mintty
49 50
     local DISPIMG = function(path)
50 51
         if path and #path > 0 then
51 52
             io.write("\n")
52
-            os.execute(string.format("imgcat %s", path))
53
+            os.execute(string.format("imgcat %s%s", basepath, path))
53 54
         end
54 55
     end
55 56
     local le = 1
... ...
@@ -191,10 +192,10 @@ elseif action == "r" then
191 192
                 -- remove braces for display
192 193
                 local pst = pr.text:gsub("%{([^{}]+)%}", "%1")
193 194
                 local st = os.time()
194
-                imgify(pst:gsub("%%A", "___"))
195
+                imgify(pst:gsub("%%A", "___"), deckfname:match(".*/") or "")
195 196
                 io.write("\n")
196 197
                 io.read("l")
197
-                imgify(pst:gsub("%%A", (pr.ans:gsub("%%", "%%%%"))))
198
+                imgify(pst:gsub("%%A", (pr.ans:gsub("%%", "%%%%"))), deckfname:match(".*/") or "")
198 199
                 io.write(string.format(
199 200
                     "\nAgain / Hard (%s) / Good (%s) / Easy (%s) / Correction ",
200 201
                     disptime(review.schedule(pr, st, 0.5)),
201 202