Another Logging Plugin & html colours

Posted by Gore on Sun 19 Dec 2004 10:22 PM — 7 posts, 27,559 views.

#0
Heya,

I'm trying to figure out how I can write a logging plugint that doesn't just log the straight up text, but the colours as well in html format.

Any ideas on how I could start this project?
Australia Forum Administrator #1
Go to the plugins page and look at the ANSI_Log plugin.

That does a similar thing. Rather than outputting ANSI codes, generate the appropriate HTML <font color=blah> stuff.
#2
Problem is, I need to detect what colours are being used on the output, I.E.

You have recovered balance on all limbs.

is shown as green on black..

How would I see that via scripting?
Australia Forum Administrator #3
That's why I suggested that plugin. Did you look at it?

Around here:


for line = firstline to lastline

  styles = GetLineInfo (line, 11)   ' how many styles

  '
  '  process all styles runs in this line
  ' 

  for style = 1 to styles
 
  '
  '  find text style (ANSI code)
  '
    
  fgcolour = GetStyleInfo (line, style, 14) ' RGB colour of style text

 '
 '  now do background
 '
 bgcolour = GetStyleInfo (line, style, 15) ' RGB colour of style background
   
'  ... and so on

  next
next


That gives you the RGB colours. Then simply use RGBColourToName to convert that to an HTML colour.
Poland #4
Erm, can't you just use the MC auto-html-logging feature?
USA #5
Hah. Yep.

Sometimes we get into the 'working with what we have' aspect of the plugins that we forget that we actually do have this stuff already.

Unless he wants multiple logs, in which case he'll have to script it a bit.
Australia Forum Administrator #6
Assuming for some reason the HTML logging doesn't work for you, another simpler approach these days it to write a plugin using Lua, that has a trigger. In Lua you can get a fourth argument to triggers that is a style list for the matching line. Then simply go through the style list and output the HTML. Pretty easy, and you can make the trigger include/exclude the lines you want.

This sort of thing would do the job, roughly:


function html_log (name, line, wildcards, styles)
  for _, v in styles do
    AppendToNotepad ("log", 
      '<span style="color: ',
      RGBColourToName (v.textcolour),
      '"; background: ',
      RGBColourToName (v.backcolour),
      '">',
      FixupHTML (v.text),
      '</span>');
  end -- for
  AppendToNotepad ("log", "\r\n");
end  -- function  html_log



Example output:


<span style="color: silver"; background: black">&lt;1000/1000hp 100/100m 110/110mv 2000/315816750xp&gt; </span>
<span style="color: red"; background: black">A Marble Corridor</span>
<span style="color: silver"; background: black">Congratulations! You have come far in your training. Your next step is</span>
<span style="color: silver"; background: black">getting your equipment from the cage mobs for your chosen class. North</span>
<span style="color: silver"; background: black">of here is the Academy Healer, Lord Toric. He will cast spells on you,</span>
<span style="color: silver"; background: black">to help with your fights. Sit with him until you are ready to proceed in</span>
<span style="color: silver"; background: black">your training.</span>
<span style="color: lime"; background: black">Exits: north south.</span>