Coloring Phrases

Posted by Krelm on Sun 09 Oct 2011 06:41 PM — 5 posts, 19,770 views.

#0
Is it possible to color phrases in MUSHClient, without coloring the entire line of text? Like, say I walk into a room, and I see:

A tall man stands here, playing a fiddle.

Is there a way to just color "a tall man," without using the highlight function to individually highlight the words "a," "tall," and "man?"

Is there a way to possibly expand this? Another example, I walk into a room...

A tall man stands here, playing the fiddle.
A short man stands here, playing the harmonica.
A fat man stands here, being lazy.

Is there a way to get the client to recognize "a * man" and highlight it, while leaving the rest of the line blank?
Australia Forum Administrator #1
Sure, something like this:


<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   keep_evaluating="y"
   match="a .*? man"
   regexp="y"
   sequence="100"
  >
  </trigger>
</triggers>


Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


If you make a regular expression, it only colours the matching part. Make sure it isn't "anchored" to the start and end of the line (with ^ and $) or you will get the whole line.

Inside a regular expression the sequence .* is a wildcard, and .*? is a non-greedy wildcard.

The difference between greedy and non-greedy will become obvious if your test line was:


You see a tall man stands here, playing a fiddle with a short man.


With greedy it matches:


You see a tall man stands here, playing a fiddle with a short man.


(Because "man" appears twice).




With non-greedy it matches:


You see a tall man stands here, playing a fiddle with a short man.
#2
I was trying this out, and it -mostly- worked, but I ran into a few snags.

For instance, I have two triggers:


  <trigger
   custom_colour="17"
   enabled="y"
   keep_evaluating="y"
   ignore_case="y"
   match="A figure .*?cloak"
   regexp="y"
   sequence="100"
   other_text_colour="purple"
  >
  </trigger>


For PC's wearing cloaks, which often show up as "a figure wearing a sandcloak" or somesuch.

And:


  <trigger
   custom_colour="17"
   enabled="y"
   keep_evaluating="y"
   ignore_case="y"
   match="a .*?cloak"
   regexp="y"
   sequence="100"
   other_text_colour="green"
  >
  </trigger>


For cloak objects, which show up as "a blah blah sandcloak."

From what I can tell, the client sort of chooses randomly where to stick colors, and it often leads to a mess, and I'll see...

a short man says to a short figure in a drab sandcloak

A toned man looks down at a short figure in a drab sandcloak.

Where the underlined text is purple and the italicized text is green.

Is there any easy way to get around this, or if my list of stuff to highlight gets too long, will it always do this?

(As a side note, I realize that the reason this is happening is because the client is just looking for everything between and including "a" and "cloak" and sticking a color to it. A fix I can think of would be to not include "a" at all, but the MUD in question uses a metric ton of adjectives in the desc of the objects, so it would take pretty much forever.)
#3
Hmm, I just realized that my PC trigger didn't include anything about a build (EG, short), and that could have been part of the problem. That said, I noticed that a lot of color mashing happened in other places, so I suppose the question is still valid-- unless I made the same simple mistake in lots of places elsewhere.
Australia Forum Administrator #4
Krelm said:

From what I can tell, the client sort of chooses randomly where to stick colors, and it often leads to a mess, and I'll see...


There's nothing random about it. The triggers match in evaluation order (lower first), so if there are two matches and they overlap, you may get what appear to be strange results.

Template:regexp
Regular expressions
  • Regular expressions (as used in triggers and aliases) are documented on the Regular expression tips forum page.
  • Also see how Lua string matching patterns work, as documented on the Lua string.find page.