get("#388") -- rect functions get("#348") -- rgb functions get("#356") -- num2hex get("#430") -- makeIcon get("#428") -- findContents get("#431") -- LXTerminal character reference get("#433") -- iconDiff function getIconSize(icon) local i = 1 while string.sub(icon, i, i) ~= '.' do i = i+1 end local w = i-1 -- #icon+1 = (w+1)*h -- => h = (#icon+1)/(w+1) local h = (#icon+1)/(w+1) return w, h end local fw_, fh_ = getIconSize(characterReference[1][2]) print("fw/fh", fw_, fh_) function recognizeChar(icon, verbose) local best, min if verbose then print("icon", icon) end local first = true for _, ic in ipairs(characterReference) do local c, reficon = unpack(ic) local diff if min ~= nil then if verbose then print("iconDiffWithLimit min", min, "fw", fw_, "fh", fh_) end diff = iconDiffWithLimit(icon, reficon, min, fw_, fh_, verbose and first) first = false else diff = iconDiff(icon, reficon) end if diff ~= nil and (min == nil or diff < min) then best, min = c, diff end if verbose then print("best", best, "min", min, "c", c, "diff", diff, "reficon", reficon) end end return best, min end return function() --[[local i = 0 for _, ic in ipairs(characterReference) do print(unpack(ic)) i=i+1 if i > 4 then goto out end end ::out::]] local cursor = otherresults["#434"] or error("Need result of #434") local _, _, cx, cy = cursor:find("Cursor position: (%d+)/(%d+)") if cx == nil then print("Cursor not found") return end cx, cy = tonumber(cx), tonumber(cy) print("Cursor position: "..cx..", "..cy) local problem = findContents() if problem then return problem end print("Contents: "..contents_x1..", "..contents_y1..", "..contents_x2..", "..contents_y2) local fw, fh = 8, 17 -- font width/height local tw = math.floor((contents_x2-contents_x1)/fw+0.5) local th = math.floor((contents_y2-contents_y1)/fh+0.5) print("Terminal size: "..tw.."*"..th) local y = cy-1 -- cursor line local line = {} for x = 0, tw-1 do local xx, yy = contents_x1+x*fw+1, contents_y1+y*fh local cropped = {width=fw-1, height=fh-1, getInt = function(x, y) return img.getInt(xx+x, yy+y) end} local icon = makeIcon(cropped) local c, diff = recognizeChar(icon) --print("c: "..tostring(c)..", diff: "..tostring(diff)..", icon: "..icon) table.insert(line, c or "?") end local text = table.concat(line) return "Screen text on cursor line:\n"..text end