Capture ANSI Color code to string

Posted by Tkl1129 on Fri 08 Jul 2011 03:43 AM — 11 posts, 42,468 views.

Hong Kong #0
How to capture ANSI color pattern to string ?

Case: I have a pattern is "OOOOO" which 5 "O"s are in different color, how do I capture it's ANSI code to string?

Hong Kong #1
-__-!..no one reply? or mush cannot do this


Output -> "OOOOO" 5 Os..but in different color
-> O(Blue)O(Red)OO(Yellow)O(white)


Any method can only capture the ANSI color code of these 5 Os ?

The final purpose of that I want to make the string like below

--> Color = {"blue","red","yellow","yellow","white"}

Any Idea?
Thanks.
Australia Forum Administrator #2
Are you reading the documentation?

http://www.gammon.com.au/forum/?bbtopic_id=120

Of course you can output things in different colours, look at this to show what can be done with miniwindows:

http://www.gammon.com.au/forum/?id=10346

But you initially said "capture" which is not the same as "output".

Also:

Template:function=ColourNote
ColourNote

The documentation for the ColourNote script function is available online. It is also in the MUSHclient help file.



Hong Kong #3
yes..not I make it change color, is the default color come out from mud, I capture it and analysis it
Australia Forum Administrator #4
Template:faq=33
Please read the MUSHclient FAQ - point 33.
Hong Kong #5
Hi all, as I'm very stupid that even read the post
"http://gammon.com.au/forum/?id=7818";

Now still don't know how t execute the "Getstyle" function

Can give me more advice by using this?
my purpose:

1. Output from mud "OOOOO" 5 Os, but all in different Color
2. Capture the color of each words and saved in string / table
3. after got those data I may analysis.

How ever, I read this post serveral times still don't know how to get start do testing and learning -.-"

Can give me an example? Thanks.
Australia Forum Administrator #6
Well perhaps I didn't explain myself very well. :P

First let's set up a test. Press Ctrl+Shift+F12 (Game menu -> Test Trigger) and enter this:



Nick says B\1B[34mO\1B[31mO\1B[33mOO\1B[37mO !



Press Ctrl+Enter to get the blank lines.

Now when you hit OK you should see this in the output window:


Nick says BOOOOO !


(With the O's in different colours).

Now let's make a trigger to match that:


<triggers>
  <trigger
   enabled="y"
   match="Nick says BOOOOO !"
   script="my_trigger"
   sequence="100"
  >
  </trigger>
</triggers>


Now we need a script to handle my_trigger, which you can put in your script file:



require "getstyle"

function my_trigger (name, line, wildcards, styles)


  -- find location of word
  col = string.find (line, "OOOOO")
  if not col then
    return
  end -- word not found


  for i = col, col + 4 do
    -- get style at that location
    style = GetStyle (styles, i)
    -- display it
    print ("column", i, "is in colour", RGBColourToName (style.textcolour))
  end -- for
  
end -- my_trigger


When you hit Ctrl+Shift+F12 again and send the test data you should now see:


Nick says BOOOOO !
column 12 is in colour navy
column 13 is in colour maroon
column 14 is in colour olive
column 15 is in colour olive
column 16 is in colour silver


That is the basic idea.
Hong Kong #7
Oh, I've got it, thanks.

And about the test trigger window
we cannot put code inside except the ANSI or \n sth like that, how about Simulate? Can I generate a random color pattern?
Australia Forum Administrator #8
Yes.
Hong Kong #9
I read via the help files...

if I want to get the 4th arguement, the only method is use Lua and use trigger -> script file to call out?
can I capture the style in the send box?
Australia Forum Administrator #10
See help for trigger:

http://www.gammon.com.au/scripts/doc.php?dialog=IDD_EDIT_TRIGGER


Near the bottom:

Quote:

If you use "send to script (after omit)" then the style runs are also available from the global variable: TriggerStyleRuns.