Updated screendump +mpackage

Share your scripts and packages with other Mudlet users.
User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Updated screendump +mpackage

Post by Vadi »

An updated screendump script that'll generate nicer html, work faster, and look nicer in the browser.

Aliases
screendump logname - saves your buffer with the current log name. Warning, a huge buffer might take a while - do it in a safe place.

If you're on Mudlet2.0-rc6+, then you can just import the .mpackage, otherwise import the two xmls.
Attachments
screendump.mpackage
(1.9 KiB) Downloaded 751 times
screendump-buffer.xml
(3.12 KiB) Downloaded 781 times
screendump-alias.xml
(574 Bytes) Downloaded 705 times

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Updated screendump +mpackage

Post by Vadi »

This is an update to the script and it adds background colors. Replace your script with the one below:
Code: [show] | [select all] lua
function logScreen(logdir, logfile)
if logfile == nil then
        cecho("\n<red>Error:<white> You must sepecify a logname!")
        return false
end

if string.char(getMudletHomeDir():byte()) == "/" then _sep = "/" else  _sep = "\\" end
local logdir = logdir .. _sep .. logfile .. ".html"
local file_output = io.open(logdir, "w")
local fo = {}
local line_count = getLineCount()
local cur_buffer = getLines(1, line_count-1)
local curcolor = ""
local index = 0
local r,g,b = 0,0,0
local br,bg,bb = 0,0,0
local cbr,cbg,cbb --last bg colors
local cr,cg,cb -- last colors
local tc = 1 -- table count
local perf = createStopWatch()
startStopWatch(perf)

local conversions = {
	["¦"] = "&brvbar;",
	["×"] = "&times;",
	["«"] = "&#171;",
	["»"] = "&raquo;"
}

fo[tc] = [[  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
      <html>
                <head>
                        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
                        <link href='http://fonts.googleapis.com/css?family=Droid+Sans+Mono' rel='stylesheet' type='text/css'>
<style type="text/css">
body {
  background-color: black;
  font-family: 'Droid Sans Mono';
  white-space: pre; 
  font-size: 12px;
}
</style>
                </head>
                <body><span>]]
tc = tc + 1

for line_num,cur_line in ipairs(cur_buffer) do
  index = 0
 	fo[tc] = string.format([[<span style="color: rgb(192,192,192);background: rgb(0,0,0);">%s</span>]], getTimestamp(line_num))
    tc = tc +1
  while index < #cur_line do
    index = index + 1
    moveCursor("main", index, line_num)
    selectString(cur_line:sub(index), 1)
    r,g,b = getFgColor()
	 br,bg,bb = getBgColor()
    if cr ~= r or cg ~= g or cb ~= b or cbr ~= br or cbg ~= bg or cbb ~= bb then
      cr,cg,cb = r,g,b
		cbr,cbg,cbb = br,bg,bb
      fo[tc] = string.format("</span><span style=\'color: rgb(%d,%d,%d);background: rgb(%d,%d,%d);'>%s", r,g,b,br,bg,bb, cur_line:sub(index, index))
      tc = tc +1
    else
      fo[tc] = cur_line:sub(index, index)
      tc = tc +1
    end
    cur_line:sub(index, index)
  end
  fo[tc] = "\n"
  tc = tc +1
end

fo[#fo+1] = "</span></body></html>"
local s = table.concat(fo)

for from, to in pairs(conversions) do
	s = string.gsub(s, from, to)
end

file_output:write(s)
file_output:close()

-- this can use quite a bit of memory on a large buffer, so free it up right away
collectgarbage("collect")
cecho("\n<cyan>Current buffer saved to: <white>" .. logdir .. "<cyan>, took <white>" .. stopStopWatch(perf) .. "ms<cyan>.")
end
If you've got a min, options to select what to save (instead of the whole buffer) would be desired additions.

User avatar
Rakon
Posts: 350
Joined: Tue Feb 16, 2010 7:41 pm
Contact:

Re: Updated screendump +mpackage

Post by Rakon »

Vadi wrote: If you've got a min, options to select what to save (instead of the whole buffer) would be desired additions.
When I've tried to do this (make the screendump function log between certain lines), for some reason, the output I get is ... very very screwy. The colours are all wrong and off. The changes I made where the following :
Code: [show] | [select all] lua
function logScreen(logdir, logfile, sline)
....
local sline = sline or 1
local cur_buffer = getLines(sline, line_count-1)
....
With only those changes made, the log file I get looks like this. Have you run into this issue as well?

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Updated screendump +mpackage

Post by Vadi »

Nope, didn't try doing it - but there seems to be a bug in how it does </span>s, so that could be it

User avatar
Rakon
Posts: 350
Joined: Tue Feb 16, 2010 7:41 pm
Contact:

Re: Updated screendump +mpackage

Post by Rakon »

Yes, using those changes there appears to be a bug in the for loop of going over the line/index of characters. I cannot see how just changing the line start number of getLines() introduces this behaviour though... it is baffling.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Updated screendump +mpackage

Post by Vadi »

Nah it's therr all along, just the browsers were managing to deal with it

User avatar
Rakon
Posts: 350
Joined: Tue Feb 16, 2010 7:41 pm
Contact:

Re: Updated screendump +mpackage

Post by Rakon »

Vadi wrote:Nah it's therr all along, just the browsers were managing to deal with it
Would you be able to take a look and try to fix that particular bug?

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Updated screendump +mpackage

Post by Vadi »

Fair enough, I've fixed it and it validates as HTML now. I also added generation time and log size optimizations.

There is a slight optimization bug in the sense that it makes stuff like this:

Code: Select all

<span style="color:rgb(73,149,0);">m</span>
<span style="color:rgb(73,149,0);background:rgb(0,0,0);">apper</span>
Which should be optimized out. Further optimizations would be generating classes as necessary for new color combos and reusing them (currently, timestamp colors are optimized very well using this).

Still though, a usability improvement that allows the user to select where to dump from, not just the whole buffer, would be a very welcome addition.
Code: [show] | [select all] lua
function logScreen(logdir, logfile)
if logfile == nil then
        cecho("\n<red>Error:<white> You must sepecify a logname!")
        return false
end

if string.char(getMudletHomeDir():byte()) == "/" then _sep = "/" else  _sep = "\\" end
local logdir = logdir .. _sep .. logfile .. ".html"
local file_output = io.open(logdir, "w")
local fo = {}
local line_count = getLineCount()
local cur_buffer = getLines(1, line_count-1)
local curcolor = ""
local index = 0
local r,g,b = 0,0,0
local br,bg,bb = 0,0,0
local cbr,cbg,cbb --last bg colors
local cr,cg,cb -- last colors
local tc = 1 -- table count

local started_similar

local moveCursor = moveCursor
local selectString = selectString
local sformat = string.format
local getFgColor = getFgColor
local getBgColor = getBgColor

local perf = createStopWatch()
startStopWatch(perf)

local conversions = {
        ["¦"] = "&brvbar;",
        ["×"] = "&times;",
        ["«"] = "&#171;",
        ["»"] = "&raquo;",
}

fo[tc] = [[<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
  <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
      <link href='http://fonts.googleapis.com/css?family=Droid+Sans+Mono' rel='stylesheet' type='text/css'>
      <title>]]..logfile..[[</title>
      <style type="text/css">
        body {
          color: silver;
          background-color: black;
          font-family: 'Droid Sans Mono';
          white-space: pre;
          font-size: 12px;
        }
        span.t {
          color: silver;
          background-color: black;
        }
      </style>
    </head>
    <body>]]
tc = tc + 1

for line_num,cur_line in ipairs(cur_buffer) do
  index = 0

  -- add in the timestamp!
  fo[tc] = sformat([[<span class="t">%s</span>]], getTimestamp(line_num))
  tc = tc +1

  -- process the line
  while index < #cur_line do
    index = index + 1
    moveCursor("main", index, line_num)
    selectString(cur_line:sub(index), 1)
    r,g,b = getFgColor()
    br,bg,bb = getBgColor()

    -- if the color is any different for this character, add in spans
    if cr ~= r or cg ~= g or cb ~= b or cbr ~= br or cbg ~= bg or cbb ~= bb then
      cr,cg,cb = r,g,b
      cbr,cbg,cbb = br,bg,bb

      if started_similar then
        fo[tc] = "</span>"
        tc = tc + 1
        started_similar = false
      end

      -- log file size spacer saver: only change fg or bg
      if cbr == br and cbg == bg and cbb == bb then
        fo[tc] = sformat("<span style=\'color:rgb(%d,%d,%d)'>%s</span>", r,g,b, cur_line:sub(index, index):gsub("&", "&"):gsub("<", "<"):gsub(">", ">"))
      else
        fo[tc] = sformat("<span style=\'color:rgb(%d,%d,%d);background:rgb(%d,%d,%d)'>%s</span>", r,g,b,br,bg,bb, cur_line:sub(index, index):gsub("&", "&"):gsub("<", "<"):gsub(">", ">"))
      end
      tc = tc +1
    else -- if it's the same, then just stuff them into the line
      if not started_similar then fo[tc] = sformat("<span style=\'color:rgb(%d,%d,%d);background:rgb(%d,%d,%d)'>", r,g,b,br,bg,bb); tc = tc + 1 end
      fo[tc] = cur_line:sub(index, index):gsub("&", "&"):gsub("<", "<"):gsub(">", ">")
      tc = tc +1
      started_similar = true
    end
    cur_line:sub(index, index)
  end
  fo[tc] = "\n"
  tc = tc +1
end

fo[#fo+1] = "</span></body></html>"
local s = table.concat(fo)

for from, to in pairs(conversions) do
  s = string.gsub(s,  from, to)
end

file_output:write(s)
file_output:close()

-- this can use quite a bit of memory on a large buffer, so free it up right away
collectgarbage("collect")
cecho("\n<cyan>Current buffer saved to: <white>" .. logdir .. "<cyan>, took <white>" .. stopStopWatch(perf) .. "ms<cyan>.")
end



User avatar
Rakon
Posts: 350
Joined: Tue Feb 16, 2010 7:41 pm
Contact:

Re: Updated screendump +mpackage

Post by Rakon »

Vadi wrote:
Still though, a usability improvement that allows the user to select where to dump from, not just the whole buffer, would be a very welcome addition.
I will work on this addition, as it is something I would an will make quite a lot of use of.

Thank you.

User avatar
Rakon
Posts: 350
Joined: Tue Feb 16, 2010 7:41 pm
Contact:

Re: Updated screendump +mpackage

Post by Rakon »

Same HTML color writing error as the first time, when I attempt to give the function getLines() a start line.

http://pastehtml.com/view/b9suhcwo1.html

Post Reply