get("#137") -- string split

suggestions = {}
suggestions["ls- ltr"] = "Did you mean: \"ls -ltr\" instead of $cmd? Then click here."
suggestions["hello"] = "Did you mean: \"echo hello\" instead of $cmd? Then click here."
suggestions["that was good aibo"] = "Thank you :)"

function suggest(cmd)
  local s = suggestions[cmd]
  return s and s:gsub("%$cmd", '"'..cmd..'"') or nil
end

return function()
  cursor = otherresults["#434"] or error("Need result of #434, please recalc")
  screentext = otherresults["#437"] or error("Need result of #437, please recalc")
  
  _, _, text = screentext:find("^Screen text on cursor line:\n(.*)")
  if text == nil then print("Screen text not found") return end
  
  _, _, cx, cy = cursor:find("Cursor position: (%d+)/(%d+)")
  if cx == nil then print("Cursor not found") return end
  cx, cy = tonumber(cx), tonumber(cy)
  
  --lines = split(text, "\n")
  --print("cy", cy, "lines", #lines)
  --line = lines[cy]
  line = text
  --print("line", line, "cx", cx)
  
  leftOfCursor = line:sub(1, cx-1)
  print("leftOfCursor", leftOfCursor)
  _, _, cmd = leftOfCursor:find("[#$] *(.*)")
  
  if cmd == nil then return end
  
  print("Command found: "..cmd)
  
  local suggestion = suggest(cmd)
  if suggestion ~= nil and suggestion ~= "" then
    return "Suggestion: "..suggestion
  end
end