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 ➜ How to get the colorized text in a trigger

How to get the colorized text in a trigger

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


Posted by godefroi   (17 posts)  Bio
Date Tue 27 Jul 2004 10:06 PM (UTC)

Amended on Tue 27 Jul 2004 11:17 PM (UTC) by godefroi

Message
I have a trigger that matches a line, and I want to add some text to the line for output.

For example, say the text that comes in is:
A janitor barely clings to life.

I want to replace it with:
A janitor barely clings to life. (1%-7%)


I can do that with a omit_from_output trigger and a world.note(), but that way I loose all color information associated with the line.

I found a post that described a method for reconstructing a line using world.GetStyleInfo() and others, but that depends on the line being in the window. If I omit_from_output, it isn't.

I had had high hopes for GetRecentLines(), because it includes lines even if they have been omitted from output by a trigger, but, alas, they don't contain the ANSI codes.

the OnPluginPacketReceived() callback seems to give me color information, but that's not much use, because I'd have to regexp match every packet and save the matches to use later in the trigger, hoping everything lined up right.

Is there any way to get color information for a line that was omitted from output?

Mark
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #1 on Wed 28 Jul 2004 06:03 AM (UTC)
Message
It can be done but it is slightly fiddly. There are a couple of problems:

If you do a script in "send to script" the line hasn't been omitted yet, but if you do a colournote to redisplay the line, notes done in "send to script" for omitted lines, are also omitted.

If you do it in a script in the script file, the line has already been omitted, so GetLineInfo and GetStyleInfo won't work.

However what *would* work would be this:


  1. In the "send" box put some scripting, and make it "send to script".

  2. The scripting would call GetLineInfo and GetStyleInfo to remember the styles on the line, and their colours. These would be saved in a variable somewhere, eg. a VBscript variable. You would probably need a variable per style run. Another approach would be to use the MUSHclient "array" script calls to put each style run's info into an array.

  3. The trigger is omitted from output

  4. The trigger also calls a script (put a script name in the script box). This is called after the earlier scripting, and recalls the style information from the variable you set a moment ago, and uses that to redraw the line the way you want.


- Nick Gammon

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

Posted by godefroi   (17 posts)  Bio
Date Reply #2 on Wed 28 Jul 2004 03:43 PM (UTC)
Message
Here's what I ended up with:

one trigger, that looks like this:

<trigger
  enabled="y"
  omit_from_output="y"
  sequence="100"
  regexp="n"
  send_to="12"
  match="abc"
  script="write_line">
    <send>save_style();</send>
</trigger>


and scripts that look like this:

<script><![CDATA[
var line = null;

function save_style()
{
	line = "";
	
	var lcount = world.GetLinesInBufferCount();
	var scount = world.GetLineInfo(lcount, 11);

	for( var i = 1; i <= scount; i++ )
		line = line + get_ansi_for_rgb_fg(world.GetStyleInfo(lcount, i, 14)) + world.GetStyleInfo(lcount, i, 1);
	
	line += " (1% - 7%)";
}


function write_line()
{
	if( line )
	{
		world.AnsiNote(line);
		line = null;
	}
}


function get_ansi_for_rgb_fg(rgb)
{
	for( var i = 1; i <= 8; i++ )
	{
		if( world.NormalColour(i) == rgb )
			return ANSI(0) + ANSI(i + 29);
	}

	for( var i = 1; i <= 8; i++ )
	{
		if( world.BoldColour(i) == rgb )
			return ANSI(1) + ANSI(i + 29);
	}

	return null;
}
]]></script>

Top

Posted by godefroi   (17 posts)  Bio
Date Reply #3 on Wed 28 Jul 2004 03:47 PM (UTC)
Message
One final thing, though.

I wish there was an easy, efficient way for a trigger to get the line it matched on INCLUDING the ANSI codes.

There's several requests for the ability to do this kind of thing in the forum, so I'm wondering if there's plans to implement this kind of thing?

Mark
Top

Posted by Jeffrey F. Pia   (49 posts)  Bio
Date Reply #4 on Wed 28 Jul 2004 04:33 PM (UTC)
Message
I second this motion. Colors are being used more and more often to distinguish whether things are on/off, active/not, etc. Being able to easily detect and use them would be a great asset. Since there's already a function to log sessions as HTML colour, would this enhancement be feasible?
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #5 on Wed 28 Jul 2004 10:08 PM (UTC)
Message
This request has been added as suggestion #522.

The problem with it is that, using MXP, colour in lines is not necessarily an ANSI code. The HTML logging uses HTML colour codes (eg. <font color="#123456"> ) which can represent *any* RGB colour, not just the 16 ANSI colours.

However I agree that the above method is fiddly, and it would be nice if there was an easier work-around.

- Nick Gammon

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

Posted by godefroi   (17 posts)  Bio
Date Reply #6 on Wed 28 Jul 2004 10:48 PM (UTC)
Message
How about a way to get just a raw line?

For those MUDs with MXP the MXP codes will be there, and for those with ANSI, the ANSI codes will be there, and if they're mixed, then it's the scripter who has to figure it out.

Mark
Top

Posted by Shadowfyr   USA  (1,791 posts)  Bio
Date Reply #7 on Thu 29 Jul 2004 02:00 AM (UTC)
Message
Just return all HTML style colors. If its is ansi, then return the 'string' version instead, that way even if the script coder uses different definitions for say red, all they have to do is see <font color=red> and look up the color that actually refers to in their ansi settings. Trying to deal with the raw data, which in the case of ansi would contain non-printables is a much bigger deal, especially if you also include something like 'world.HTMLNote', in order to simplify outputing the modified (or your own) lines. I mean the existing colournote system works nicely for complex things that are built on the fly, but it is really clunky and silly for simple content when the client already understands HTML color tags. But that is just my opinion.
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #8 on Sat 27 Nov 2004 03:16 AM (UTC)
Message
Quote:

I wish there was an easy, efficient way for a trigger to get the line it matched on INCLUDING the ANSI codes


See the new feature in version 3.54 of MUSHclient. In particular this post:

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=4912&page=2


- 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.


30,191 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.