Capturing ANSI

Posted by DarkSlayer on Sat 11 Nov 2006 11:12 PM — 9 posts, 34,304 views.

#0
I was wondering if it is possible to capture only the ansified sections of a line and note/appendtonotepad them?

For example, (x) indicates x has ansi.

A (m)ulti(c)oloured li(n)e!

What I want to do is capture the m, c and n... possible?

Using JScript.
Australia Forum Administrator #1
You just want the letters? It is certainly possible, you can use GetStyleInfo to find where styles change in a line (that is, new colours).

http://www.gammon.com.au/scripts/doc.php?function=GetStyleInfo

You need to know the line number, in a trigger it is probably the last line, unless it was large enough to wrap around.

You can use GetLinesInBufferCount to find how many lines in the output window, and thus the line number of the last line:

http://www.gammon.com.au/scripts/doc.php?function=GetLinesInBufferCount
#2
Any chance you could give me an example?

Not sure how I could get the particular letters.
Australia Forum Administrator #3
It is easiest in Lua because that gives a trigger the style runs for the triggered line. I will show you the idea in Lua, you can adapt that to Jscript if you want.

The trigger (currently matches everything):


<triggers>
  <trigger
   enabled="y"
   match="*"
   script="my_trigger"
   sequence="100"
  >
  </trigger>
</triggers>


And in my script file I had this code:


function my_trigger (name, line, wildcards, styles)

  for k, v in ipairs (styles) do
     print ("Style ", k, 
            " contents = ", v.text,
            " colour = ", RGBColourToName (v.textcolour))
  end -- for loop

end -- my_trigger


Running this on my prompt line gives me this:


Style  1  contents =  <  colour =  silver
Style  2  contents =  100/100hp   colour =  yellow
Style  3  contents =  143/143m   colour =  cyan
Style  4  contents =  210/210mv   colour =  lime
Style  5  contents =  0/343xp  colour =  magenta
Style  6  contents =  >  colour =  silver


You can see from this that the contents (the text of the style) is shown individually for each one, followed by its colour.
Amended on Tue 14 Nov 2006 07:42 PM by Nick Gammon
#4
Thanks alot. :)
I'll see how I go making a jscript version.

Cheers
-DS
USA #5
Lots of luck to you in making the jscript version, but I don't think it will work, as the STYLES parameter that is passed into the function only exists in LUA.

In order to do it, you would have to get the number of the last line (the line that triggered the script to be called) and from there do a lot of mucking and tweaking of commands to parse it.

I suggest you start learning LUA, as it is the most powerful scripting language for plugin purposes, and it is not all that difficult, as if you know one language, you can easily transition its logic into LUA.

Again, good luck to you,

Laterzzz,
Onoitsu2
#6
Is it possible to use a LUA plugin while I use jscript for everything else? I've got way too much script to change to LUA...
Australia Forum Administrator #7
Yes, every plugin can be in a different language.
#8
Thanks a ton for the help guys. :)

DS