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 cursor = otherresults["#434"] or error("Need result of #434") _, _, cx, cy = cursor:find("Cursor position: (%d+)/(%d+)") if cx == nil then print("Cursor not found") return end cx, cy = tonumber(cx), tonumber(cy) 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 fw_, fh_ = getIconSize(characterReference[1][2]) print("fw/fh", fw_, fh_) function recognizeChar(icon) local best, min for _, ic in ipairs(characterReference) do local c, reficon = unpack(ic) local diff if min ~= nil then diff = iconDiffWithLimit(icon, reficon, min, fw_, fh_) else diff = iconDiff(icon, reficon) end --print("c", c, "diff", diff, "reficon", reficon) if diff ~= nil and (min == nil or diff < min) then best, min = c, diff end end return best, min end problem = findContents() if problem then return problem end fw, fh = 8, 17 -- font width/height tw = math.floor((contents_x2-contents_x1)/fw+0.5) th = math.floor((contents_y2-contents_y1)/fh+0.5) print("Terminal size: "..tw.."*"..th) y = cy-1 -- cursor line line = {} for x = 0, tw-1 do xx, yy = contents_x1+x*fw+1, contents_y1+y*fh 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 text = table.concat(line) return "Screen text on cursor line:\n"..text