Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
vey2000
Novice


Joined: 21 May 2004
Posts: 32

PostPosted: Mon Feb 12, 2007 3:33 am   

adding text to received lines without stripping colors
 
What's the best way to append, possibly colored, text to lines output from the mud without affecting any color that the line itself might already have?

Here's what I've already tried and their respective shortcomings:

trigger on ^(text)$ -> sub "%1 new text"
This causes the original text to lose all colors unless I make the trigger an ansi trigger; however, this would require me to handle ansi codes in the pattern which might not be at all trivial in cases where I don't know what colors to expect or even if there will be colors.

Same thing but using psub: this is much like the previous one except that it also seems to get rid of the new line codes.

trigger on ^text()$ -> psub "new text"
This leaves any color codes in text intact but still strips the new line codes at the end. Besides, even if this worked it seems like a huge kludge.

Here's one I've found that does actually work, but only if text ends in a period or some other character that I can rely on being there and isn't colored or anything like that:
trigger on ^text(.)$ -> psub ". new text" %x1
Like I said, this one works, it still feels like a kludge, but mainly it relies on there being something to "hook into."

It seems like () with nothing inside doesn't work, but ( ) with a space inside does.

Also, if I want to add it somewhere in the middle, for example:
trigger on ^ab cd( )ef$ -> psub " 12 " %x1
This seems to work, and I can even leave the color elsewhere, both before and after, intact if I use mxp for coloring the new text.

I guess what I'm looking for is an #insert command rather than a #(p)sub command as well as some way to identify the insertion position.

Ok, I've sort of figured it out while writing this post, but I'd still like to hear some input on whether there's a better way to do these things.

It seems that #psub text x x where both x's are the same number will insert text at position x and since %x1, 2, ... just returns a string with the start and ending positions it should be straightforward to get the position of just one of the parentheses. Although after a bit more testing it seems that #psub text 0 0 will still replace the first character no matter what, so I guess it's impossible prepend text while leaving the original intact.

Also, I think making a trigger-on-prompt trigger with pattern ^text that just #says something will also work for appending text while leaving the original intact. This actually seems to be the simplest way for this case.

So that leaves inserting text somewhere in the middle as being fairly doable and prepending text as impossible so far. Any better ideas?
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Mon Feb 12, 2007 3:59 am   
 
If you actually mean append, #sayprompt or #echoprompt will do it. If you mean prepend, that's a bit more difficult as you've noticed. You could try using %subregex on the ANSI colour string to convert the colour codes into %ansi functions.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net