local function printWithFormat(...) local s = "&1" for k, v in ipairs(arg) do s = s .. v end s = s .. "&0" local fields = {} local lastcolor, lastpos = "0", 0 for pos, clr in s:gmatch"()&(%x)" do table.insert(fields, {s:sub(lastpos + 2, pos - 1), lastcolor}) lastcolor, lastpos = clr , pos end for i = 2, #fields do term.setTextColor(2 ^ (tonumber(fields[i][2], 16))) io.write(fields[i][1]) end end
You can do something like this:
printWithFormat("&7Hello, &aWorld!")
and it would print this:
Hello, World!
Pretty awesome, eh?