John Smith commited on 2022-232 01:08:41
Showing 1 changed files, with 9 additions and 5 deletions.
Since the filename of an image often (reasonably) describes the image, "identify-thing-from-image"-type prompts are accidentally sabotaged by the image viewer showing the filename in the window title, removing the challenge (the reviewing user could glance at the title bar). As facilitated by a Very Convenient and Recent iv update, Memoire can now force a more pragmatically relevant alternative title format when displaying images.
| ... | ... |
@@ -46,22 +46,26 @@ end |
| 46 | 46 |
]] |
| 47 | 47 |
local function imgify(text, basepath) |
| 48 | 48 |
-- adapted from https://stackoverflow.com/a/1579673 |
| 49 |
- local PATTERN = "(.-)IMG%[([^%]]+)%]" |
|
| 49 |
+ local IMG_PATTERN = "IMG%[([^%]]+)%]" |
|
| 50 |
+ local PATTERN = "(.-)" .. IMG_PATTERN |
|
| 50 | 51 |
-- Linux/dwm |
| 51 |
- local DISPIMG = function(path) |
|
| 52 |
+ local DISPIMG = function(path, st) |
|
| 52 | 53 |
if path and #path > 0 then |
| 53 |
- os.execute(string.format("/usr/local/bin/iv %s%s &", basepath, path))
|
|
| 54 |
+ os.execute(string.format( |
|
| 55 |
+ "/usr/local/bin/iv -t '%s' %s%s &", |
|
| 56 |
+ st:gsub("'", "\""):gsub(IMG_PATTERN, ""), basepath, path
|
|
| 57 |
+ )) |
|
| 54 | 58 |
end |
| 55 | 59 |
end |
| 56 | 60 |
local le = 1 |
| 57 | 61 |
local s, e, pt, ip = text:find(PATTERN) |
| 58 | 62 |
while s do |
| 59 | 63 |
io.write(pt) |
| 60 |
- DISPIMG(ip) |
|
| 64 |
+ DISPIMG(ip, text) |
|
| 61 | 65 |
le = e + 1 |
| 62 | 66 |
s, e, pt, ip = text:find(PATTERN, le) |
| 63 | 67 |
io.write(pt or "") |
| 64 |
- DISPIMG(ip) |
|
| 68 |
+ DISPIMG(ip, text) |
|
| 65 | 69 |
end |
| 66 | 70 |
if le <= #text then |
| 67 | 71 |
io.write(text:sub(le)) |
| 68 | 72 |