Prompt NewLine Plug-in

Posted by Hanaisse on Sun 22 Mar 2009 04:18 AM — 25 posts, 98,471 views.

Canada #0
I've been looking for this plug-in but can't find it in the plug-in list, so I searched these forums and found a very old thread that contained a 'simple version' (Nick's words) here;

http://www.gammon.com.au/forum/bbshowpost.php?id=7430

I copied it exactly into the plug-in wizard and installed but it's not acting in the way I expected.

I expected it to drop to a new line right after each prompt line like this;
<5000hp 5000m 4997mv>
You say 'hello'

Instead, I get, well, a space after the prompt like this;
<5000hp 5000m 4997mv> You say 'hello'

I have the latest version of MUSHclient installed with No Command Echo checked (because frankly command echo annoys me) on a SMAUG codebase.

Am I using the right plug-in for what I want? Is there a different one out there somewhere? Or perhaps I did something wrong?
Amended on Sun 22 Mar 2009 04:19 AM by Hanaisse
Australia Forum Administrator #1
That fairly lengthy thread discusses various similar issues. For it to work the string.gsub in the plugin must match what your prompt looks like. I am not sure which one you used, but one of the ones I did matched a prompt with current and max values, which your prompt doesn't have.

In particular, this part:


function OnPluginPacketReceived (s)
return (string.gsub (s, "\n<.+/.+hp .+/.+m .+/.+mv .+/.+xp.*> ", "%1\n"))
end -- function OnPluginPacketReceived


Now your prompt would be matched by something like this:


function OnPluginPacketReceived (s)
return (string.gsub (s, "\n<%d+hp %d+m %d+mv> ", "%1\n"))
end -- function OnPluginPacketReceived


Canada #2
Yes, I did replace the string.gsub with my prompt. Here is what it looks like.

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Saturday, March 21, 2009, 11:42 PM -->
<!-- MuClient version 4.37 -->

<!-- Plugin "Add_NewLine_To_Prompt" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Add_NewLine_To_Prompt"
   author="Nick Gammon"
   id="3862dd7f2ba50abfe50d4844"
   language="Lua"
   purpose="Forces a newline after a prompt line"
   date_written="2009-03-21 23:38:18"
   requires="4.37"
   version="1.0"
   >

</plugin>


<!--  Script  -->


<script>
<![CDATA[
function OnPluginPacketReceived (s)
  return (string.gsub (s, "\n<&r%r &Y%h &C%m &G%v> ", "%1\n"))
end -- function OnPluginPacketReceived
]]>
</script>


</muclient>



I'm sorry, I don't understand what the %d means in your example or if it even pertains to this?
USA #3
%d is the Lua string representation of a digit, meaning a number, I, probably as well as Nick are perplexed by the &X's ... as well as the fact that the example prompt you posted has 3 sections, and this appears to be attempting to match 4 items.

-Onoitsu2
Amended on Sun 22 Mar 2009 05:39 AM by Onoitsu2
Canada #4
Er, oops. Bad example, there are 4 things in my prompt. The first %r displays room vnums. The other &thingies are colour codes. Even if I take them out I'm still not getting what I want.

10300 5000 5000 5000You say 'hello' is the output of this in the plugin...

function OnPluginPacketReceived (s)
  return (string.gsub (s, "\n<%r %h %m %v> ", "%1\n"))
end -- function OnPluginPacketReceived

Australia Forum Administrator #5
The function in question is string.gsub:

http://www.gammon.com.au/scripts/doc.php?lua=string.gsub

That mentions that string.find explains Lua regular expressions:

http://www.gammon.com.au/scripts/doc.php?lua=string.find

Quote:

I, probably as well as Nick are perplexed by the &X


I think he has posted what he types into the MUD to get the prompt. Read up on regular expressions (see above link). The %d+ means one or more digits, which is what 5000 consists of. So %d+hp would match on some number of digits, followed by "hp". Try my example and see if it works.
Australia Forum Administrator #6
Quote:

Even if I take them out I'm still not getting what I want.

10300 5000 5000 5000You say 'hello' is the output of this in the plugin...


Don't change the prompt, change the plugin to match the prompt.

You are changing the rules as we go, now there is a room number. However following the regular expression shown above you should be able to allow for that.
Canada #7
Quote:
I think he has posted what he types into the MUD to get the prompt.


lol, I was (btw, she not he).

Ok, I've read up on the regular expressions and it's becoming a little more clear. The string.gsub needs to match on the output, what the display window shows, right?

The output of my prompt is: <1000hp 1000m 750mv> <#21000>

And following your example it makes sense to have %d+hp to match on 1000hp, etc.

So I corrected the plugin to be this;

(string.gsub (s, "\n<%d+hp %d+m %d+mv %d> ", "%1\n")


(the extra %d on the end is for the room vnum in the prompt - not sure if that's correct or not)

Anyway, it still doesn't work. I'm not getting a new line.
<1000hp 1000m 750mv> <#21000> You say 'hello'


Note: I'm (obviously) not a coder so I really need a "Lua for Dummies" explanation.
Australia Forum Administrator #8
Quote:

btw, she not he


My apologies. I normally type s/he but that day a wave of laziness overtook me. :)

Anyway, although you are getting closer, you put the room number in, in a way it wasn't going to match. I got it to work against your example prompt using:


function OnPluginPacketReceived (s)
  return (string.gsub (s, "\n<%d+hp %d+m %d+mv> <#%d+> ", "%1\n"))
end -- function OnPluginPacketReceived


Since the room number was in < ... > signs, the %d+ had to be inside them too.
Canada #9
Ok, I see what you did there. I copied that exactly into the plugin and it still doesn't work :(
Australia Forum Administrator #10
Did you reinstall the plugin after changing it?

If so, please copy and paste the entire modified plugin. Also copy and paste a few sample lines from the MUD, so I can see the exact context in which the prompts appear?
Canada #11
Reinstalled, enabled, removed, added, saved the world, logged out, logged back in, tried everything.

Here's the plugin;

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Sunday, March 22, 2009, 11:52 AM -->
<!-- MuClient version 4.37 -->

<!-- Plugin "NewLine" generated by Plugin Wizard -->

<muclient>
<plugin
   name="NewLine"
   author="Nick Gammon"
   id="1baba0fed265b8662b599a8f"
   language="Lua"
   purpose="Forces a newline after a prompt line"
   date_written="2009-03-22 11:50:02"
   requires="4.37"
   version="1.0"
   >

</plugin>


<!--  Get our standard constants -->

<include name="constants.lua"/>

<!--  Script  -->

<script>
<![CDATA[
function OnPluginPacketReceived (s)
  return (string.gsub (s, "\n<%d+hp %d+m %d+mv> <#%d+> ", "%1\n"))
end -- function OnPluginPacketReceived
]]>
</script>


</muclient>


And some samples of what I'm looking at;

<1000hp 1000m 742mv> <#21020> Inside the Southern Gate
You stand inside the southern gate of Darkhaven.  To the north is the
intersection of Vertic Avenue and Law Avenue.
Exits: north.
A guard of the city stands at the ready.

<1000hp 1000m 750mv> <#21074> You are carrying:
     Nothing.

<1000hp 1000m 750mv> <#21074> You say 'hello'

<1000hp 1000m 750mv> <#21074> 
The bells of the cathedral toll the passing of time.


Funny how the area reset message starts on a new line but that does that already without the plugin.
USA #12
Are there color codes involved, that is the only reason, I think that this might not be functioning properly is if there are multiple colors in the code, and it is not matching against the escape codes for the colors.

I had the same issue with several packet matches.

-Onoitsu2
Australia Forum Administrator #13
I think we need to see the raw packets - Onoitsu2 is right, colour codes would throw things out because we are matching the raw data.

Go to the Edit menu -> Debug Packets (check it).

Then grab a few prompts. Then turn Debug Packets off again or the packet debug window will get very large.

Then paste the results here, please.
Canada #14
Yes the prompt is coloured. It's the default in SmaugFUSS, I haven't changed it.
But now I'm totally confused as to how matching the prompt as it's seen is messed up by colour code that's not seen.

Hopefully you'll find the problem in here;

Sent  packet: 177 (5 bytes) at Sunday, March 22, 2009, 11:16:56 PM

inv..              69 6e 76 0d 0a

Incoming packet: 349 (123 bytes) at Sunday, March 22, 2009, 11:16:56 PM

.[1;31mYou are c   1b 5b 31 3b 33 31 6d 59 6f 75 20 61 72 65 20 63
arrying:..     .   61 72 72 79 69 6e 67 3a 0d 0a 20 20 20 20 20 1b
[1;32mNothing...   5b 31 3b 33 32 6d 4e 6f 74 68 69 6e 67 2e 0d 0a
...[0m.[0;37m<.[   0d 0a 1b 5b 30 6d 1b 5b 30 3b 33 37 6d 3c 1b 5b
1;33m1000hp .[1;   31 3b 33 33 6d 31 30 30 30 68 70 20 1b 5b 31 3b
36m1000m .[1;32m   33 36 6d 31 30 30 30 6d 20 1b 5b 31 3b 33 32 6d
748mv.[0;37m> <#   37 34 38 6d 76 1b 5b 30 3b 33 37 6d 3e 20 3c 23
21074> .[0m        32 31 30 37 34 3e 20 1b 5b 30 6d

Sent  packet: 178 (11 bytes) at Sunday, March 22, 2009, 11:17:07 PM

say hello..        73 61 79 20 68 65 6c 6c 6f 0d 0a

Incoming packet: 350 (99 bytes) at Sunday, March 22, 2009, 11:17:07 PM

.[1;36mYou say '   1b 5b 31 3b 33 36 6d 59 6f 75 20 73 61 79 20 27
hello'.....[0m.[   68 65 6c 6c 6f 27 0d 0a 0d 0a 1b 5b 30 6d 1b 5b
0;37m<.[1;33m100   30 3b 33 37 6d 3c 1b 5b 31 3b 33 33 6d 31 30 30
0hp .[1;36m1000m   30 68 70 20 1b 5b 31 3b 33 36 6d 31 30 30 30 6d
 .[1;32m748mv.[0   20 1b 5b 31 3b 33 32 6d 37 34 38 6d 76 1b 5b 30
;37m> <#21074> .   3b 33 37 6d 3e 20 3c 23 32 31 30 37 34 3e 20 1b
[0m                5b 30 6d

Australia Forum Administrator #15
Quote:

But now I'm totally confused as to how matching the prompt as it's seen is messed up by colour code that's not seen.


The plugin takes the raw packet of data as received by the MUD. Any colour codes need to be considered, because they are there, even if later on they are stripped out and turned into colours.

You can see that a test for "<1000hp" is not going to match:


0;37m<.[1;33m1000hp


My amended function is below. I tested it against the packet you supplied and it worked. :)

Basically I added in this sequence whereever I saw the colour codes:


\027[^m]+m


This is matching on:

  • <esc> (represented by \027)
  • Anything other than "m", one or more times (represented by [^m]+)
  • The "m" that terminates the colour code sequence


Just replace the OnPluginPacketReceived function with below:


function OnPluginPacketReceived (s)
  return (string.gsub (s, "\n\027[^m]+m\027[^m]+m<\027[^m]+m%d+hp \027[^m]+m%d+m \027[^m]+m%d+mv\027[^m]+m> <#%d+> ", "%1\n"))
end -- function OnPluginPacketReceived

Australia Forum Administrator #16
Quote:

aka: Hana
Owner in Training of: Fury of the Gods


If you have the power to change the MUD, it might simplify things to give players the ability to put the newline into their prompt, thus saving all this messing about. You could add a new token (eg. where %h is hitpoints) like %n to be a newline.
Canada #17
Ahh, success!! :)

Thank you so much for bearing with me.

Yes I have the power but unfortunately my coder has gone AWOL. I will definitely keep this on a to-do list.

Shame the SmaugFUSS guys haven't added this in. Surely I can't be the only one who was annoyed by this, lol.

Many thanks again. Now on to try adding the new Icon Bar plug-in ;)
#18
I've got the same very problem which Hanaisse got with the commands/statements continuing after the prompt. I've tried to do the same thing he did, like copy the Prompt_Newline code into the Plugin Wizard, but I got an error when I tried creating the Plugin, saying:

script may not contain the sequence "]]>"

And then I'm stumped. I'm not sure how to amend it because MUSHclient's really new to me. Could someone help me with this?
Australia Forum Administrator #19
The wizard automatically puts:


<![CDATA[

... your script here ...

]]>


So, don't copy in the ]]> yourself, assuming that is what you did.
#20
Thanks! Ok, so I've copied the script and created a plugin just like Hanaisse, plus added the amendments that were made:

<script>
<![CDATA[

partial = "" -- partial line from last time through


function OnPluginPacketReceived (s)
return (string.gsub (s, "\n\027[^m]+m\027[^m]+m<\027[^m]+m%d+hp \027[^m]+m%d+m \027[^m]+m%d+mv\027[^m]+m> <#%d+> ", "%1\n"))
end -- function OnPluginPacketReceived

]]>
</script>

However, even after reinstalling the plugin, I'm still getting a result as shown below"

H:141 M:1128 E:3330 W:4770 B:100% XP:34% [eb]You bare your teeth and your claws lash out at a tiny pincher.

I wonder what I did wrong.
Australia Forum Administrator #21
I would have to see the raw prompt as it arrives from the MUD. Please turn on Edit menu -> Packet Debug, bring up a prompt like you showed, and then copy and paste the packet debug information here (then turn the packet debug off again).
Australia Forum Administrator #22
OK, so a prompt looks like:


\1b[37mH:0 \1b[32mM:1174 \1b[37m\1b[32mE:3846 \1b[37m\1b[32mW:5249 \1b[37m\1b[1;31mB:100% \1b[0;37mXP:40% [eb]\ff\f9


First thing I notice is the \ff\f9 at the end of the prompt. That is IAC/GA, so you simply need to go to the output window configuration and check "Convert IAC EOR/GA to new line". Then you shouldn't need the plugin at all.
Australia Forum Administrator #23
My reply doesn't make as much sense as you deleted your message, but my suggestion still stands.
#24
So very sorry, I deleted the post because I realized that when I copied the Packet Debug, I deleted the plugin away before copying it to you. But I guess the plugin doesn't effect the debug from what you were saying in the last post.

I've checked the "Convert IAC EOR/GA to new line" in the output configuration, and it worked! Thank you so very much! Thank you for your patience with me as well!