Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Capture ANSI Color code to string

Capture ANSI Color code to string

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Tkl1129   Hong Kong  (43 posts)  Bio
Date Fri 08 Jul 2011 03:43 AM (UTC)
Message
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?

Top

Posted by Tkl1129   Hong Kong  (43 posts)  Bio
Date Reply #1 on Sat 09 Jul 2011 02:26 AM (UTC)
Message
-__-!..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.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #2 on Sat 09 Jul 2011 07:11 AM (UTC)
Message
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.




- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Tkl1129   Hong Kong  (43 posts)  Bio
Date Reply #3 on Sat 09 Jul 2011 10:15 AM (UTC)
Message
yes..not I make it change color, is the default color come out from mud, I capture it and analysis it
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #4 on Sat 09 Jul 2011 10:21 AM (UTC)
Message
Template:faq=33 Please read the MUSHclient FAQ - point 33.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Tkl1129   Hong Kong  (43 posts)  Bio
Date Reply #5 on Mon 18 Jul 2011 06:32 AM (UTC)
Message
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.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #6 on Mon 18 Jul 2011 08:08 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Tkl1129   Hong Kong  (43 posts)  Bio
Date Reply #7 on Mon 18 Jul 2011 09:04 AM (UTC)
Message
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?
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #8 on Mon 18 Jul 2011 10:32 AM (UTC)
Message
Yes.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Tkl1129   Hong Kong  (43 posts)  Bio
Date Reply #9 on Wed 20 Jul 2011 01:53 AM (UTC)
Message
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?
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #10 on Wed 20 Jul 2011 02:14 AM (UTC)
Message
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.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


40,537 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.