Code: Select all
-- pecho() allows easy use of insertText()
function pecho( mess, pos, col, line_offset, writeover)
local linenum = getLineCount()
if line_offset ~= nil then
linenum = linenum + line_offset
end
moveCursor("main", pos, linenum)
if writeover ~= nil then
selectString( mess, 1)
replace("")
end
fg(col) bg("black")
insertText(mess)
resetFormat()
moveCursorEnd("main")
end
For example:
pecho( "Column 1", 5, "sea_green")
pecho("Column 2, 20, "red")
pecho("Column 3, 35, "yellow")
The optional line offset could be used when looping through an ordered table with ipairs, listing the values, across multiple columns. Eg, keys 1-20 in column 1, followed by 21-40 in column 2 etc.
I want to add an argument for directing to another window/console, but I'm not sure whether to put that optional argument before or after the line offset. I think the best way to have two optional arguments is to use type() to differentiate between them (since line offset will always be an integer, while windowname will be a string). I'll think about it - it shouldn't be difficult at any rate.
Code: Select all
function cecho(mess, fgcol, bgcol)
if fgcol ~= nil then fg(fgcol) end
if bgcol ~= nil then bg(bgcol) end
echo(mess)
resetFormat()
end
Edit: function updated with "writeover". Explanation in reply to this post.