So, I'm basically trying to make a logging function that just saves what I see in the buffer currently to a file with color formatting. Here is what I have so far:
function logScreen(logname)
if logname == nil then
cecho("\n<red>Error:<white> You must sepecify a logname!")
return false
end
local logdir = getMudletHomeDir() .. "\\log\\" .. logname .. ".html"
file_output = io.open(logdir, "w")
local line_count = getLineCount()
local cur_buffer = getLines(1, line_count-1)
local curcolor = ""
local index = 0
file_output:write("<body bgcolor='black'><span>")
for line_num,cur_line in pairs(cur_buffer) do
index = 0
while index < #cur_line do
index = index + 1
moveCursor("main", index, line_num)
selectString(cur_line:sub(index), 1)
r,g,b = getFgColor()
if curcolor ~= (r .. "," .. g .. "," .. b) then
curcolor = r .. "," .. g .. "," .. b
file_output:write("</span><span style=\'color: rgb(" .. curcolor .. ");'>" .. cur_line:sub(index, index))
else
file_output:write(cur_line:sub(index, index))
end
cur_line:sub(index, index)
deselect()
end
file_output:write("<br>\n")
end
file_output:write("</body>")
file_output:close()
cecho("\n<cyan>Current buffer saved to: <white>" .. logdir)
end
The main issue I run into at the moment is as the buffer gets longer, it takes a decent bit of time. I essentially am running line by line, and within each line going character by character to get the color code so i can output a fully color coded HTML file.
Does anyone have any advice on how to improve the function/speed it up a bit? I could limit the amount I save from the buffer (IE the last 1000 lines) but my logs that I want to save can be quite long and would still lock up Mudlet for a bit.