Page 1 of 1
An Easier Way to Make Colored Links
Posted: Thu Oct 25, 2018 8:16 pm
by Jor'Mox
I wrote a function that uses cecho to write out text, with the added ability to put links in the middle of it (via cinsertLink), using a <link> tag. Just put the tags around whatever you want to make a link (as described in the comments at the top), and it will do it all the rest of the work for you.
-- colorLinks function provides an easy way to intersperse links into colored text
-- Link tag format: <link: code here ; hint here ; color>text of link</link>
function colorLinks(win, str)
if not str then
str, win = win, "main"
end
str = str:split("</link>")
for _, w in ipairs(str) do
local before, info, link = w:match("(.*)<link: ([^>]+)>(.*)")
if before then
cecho(win, before)
info = info:split(" ; ")
if info[3] then
if color_table[info[3]] then
link = string.format("<%s>%s<reset>", info[3], link)
else
info[3] = nil
end
end
cechoLink(win, link, info[1], info[2] or "", info[3] and true)
else
cecho(win, w)
end
end
end