[TF] Prompt Hook
Brought to you by:
kenkeys
|
From: david at nittanylink.c. (D. H. Clymer) - 2003-02-06 18:27:18
|
Here is my original post. It seems that it didnt make it to the list for some reason.
On Thu, 2003-02-06 at 11:23, Gary Jackson wrote:
>
> One caveat: hooks don't strip out ANSI codes like triggers, so if
> you've got a color prompt, you might have trouble.
>
My mud included color codes in its prompt, but I've created a macro to
parse it and extract the necessary information, perhaps you can modify
my code for your purposes.
the prompt string (including color codes) is passed to the macro using
the prompt hook.
; update prompt and char stats
/def -hPROMPT -wveeblefester veeblefester_prompt = \
/veeblefester_parse_prompt %{*} %;\
/test prompt({*})
because my prompt is so long, i split it up into 2 halves (you have a
maximum of 9 submatches, i believe). my prompt is in the following
format:
&z(&Y%h/%H&z) (&C%m/%M&z) (&G%v/%V&z) (&O%S&z) (&P%A&z) (&B%a&z)
(&W%X&z)&w
that will probably only make sense if this is a smaug mud that you are
playing (i've only ever done smaug). basically, its:
(currenthealth/maxhealth) (currentmana/maxmana) (currentmoves/maxmoves)
(stance) (visbility status) (alignment) (experience needed to reach next
level)
and fight prompt is the same, except that it has an extra field showing
my opponent's health.
; extract info from prompt
/def veeblefester_parse_prompt = \
; parse first half of prompt
/if (regmatch(".\[.*m\(.\[.*m([0-9]+)/([0-9]+).\[.*m\)
\(.\[.*m([0-9]+)/([0-9]+).\[.*m\) \(.\[.*m([0-9]+)/([0-9]+)", {*})) \
/set veeblefester_current_hp %{P1} %;\
/set veeblefester_max_hp %{P2} %;\
/set veeblefester_current_mana %{P3} %;\
/set veeblefester_max_mana %{P4} %;\
/set veeblefester_current_moves %{P5} %;\
/set veeblefester_max_moves %{P6} %;\
/endif %;\
; parse second half of prompt
/if (regmatch("\(.\[.*m([A-Z]).\[.*m\) \(.\[.*m([A-Z]*).\[.*m\)
\(.\[.*m([0-9a-z]+).\[.*m\) \(.\[.*m([0-9]+)",{PR})) \
/set veeblefester_stance %{P1} %;\
/set veeblefester_vis=$[{P2} =~ "" ? "V" : %{P2}] %;\
/set veeblefester_align %{P3} %;\
/set veeblefester_xp_to_level %{P4} %;\
/endif %;\
; only in fight prompt
/if (regmatch("\(.\[.*m([0-9]+)", {PR})) \
/set veeblefester_opponent_life %{P1} %;\
/if (!{veeblefester_is_fighting}) \
/veeblefester_fighting on %;\
/endif %;\
/else \
/if ({veeblefester_is_fighting}) \
/veeblefester_fighting off %;\
/endif %;\
/endif
basically ASCII color codes look like: ^[[30;47;0m
so to match them, you can do as I did: \[.*m
actually, i should be doing \033[.*m , i'm not sure why i'm not..\033 is
that funky ^[ escape character. remember, though that tf pattern matches
match the longest possible match. so if you have a color code at the
beginning of the prompt and at the end of the prompt and just do \033*m,
you will match the whole prompt.
anyway, hope that was helpful..
davidc
ps. the code contained here has no strings attached you can use it for
whatever you would like. with or without referencing me as the author.
|