Embedding a hyperlink into a matched line

Posted by Twisol on Tue 02 Sep 2008 08:46 AM — 4 posts, 15,610 views.

USA #0
Hi, I'm trying to embed a hyperlink into part of the Achaea prompt - for example, "3106h, 3710m, 14000e, 16040w ex Vote-" - specifically, the Vote, and make it link to the web page to vote for Achaea. I was at first trying to use lookbehind (and lookahead for the '-'), so I would only actually match the Vote, but acknowledge the existance of the rest of the prompt. That didn't work very well, mostly because I've never done any lookarounds before.

Also, apparently Hyperlink() only echoes the hyperlink to the output, it doesn't actually replace text with the hyperlink. I guess this means I would have to omit the prompt altogether, and re-echo it with the hyperlink, right? Seems kind of painful...

This is the trigger I'm using for the prompt. This works, at least. It's rather complex because I want to match any configuration of the prompt (it can be off, it can list only health and mana, etc)

^(?:\d+h, )?(?:\d+m,? )?(?:\d+e,? )?(?:\d+w,? )?c?e?x?k?d?b?@?\s?(?:Vote)?-\s?$

That Vote thing at the end is what I want to hyperlink. Help? :|
USA #1
Hmm If the prompt ends in a newline then this may work...
the general RegExp tho can be more succinctly:

^$(?P<Start>(?:\d++[hmew], )*[cexkdb@]* ?)(?P<Vote>)Vote)?-\s?$

Omit from Output
Send to: Script

Tell("%<Start>")
if "%<Vote>" ~= "false" then
HyperLink(....too lazy to doublecheck syntax)
end


So it's not really that painful to omit and re-echo.
Amended on Tue 02 Sep 2008 07:18 PM by WillFa
USA #2
OK, this is what I have so far. It works, but is there any way to re-print the prompt in exactly the same color(s) as it was before? I know I can use AnsiTell, but it would be nice to be able to "catch" the colors used in the prompt and re-use them in the script.

Trigger:
^(?P<Start>(?:\d+h, )?(?:\d+m,? )?(?:\d+e,? )?(?:\d+w,? )?c?e?x?k?d?b?@? ?)(?P<Vote>Vote)- ?$


Script (after omit):
if "%<Vote>" ~= "" then
Tell("%<Start>")
Hyperlink("http://www.achaea.com/vote/", "Vote", "Vote!", "green", "black", true)
Tell("-")
if ("%<Start>" == "") then
Tell(" ")
end
Note()
end
Amended on Tue 02 Sep 2008 11:31 PM by Twisol
Australia Forum Administrator #3
The general technique to keep the colours is described in http://mushclient.com/faq point 23. Although that mentions going to another world window, the same idea applies if omitting a line and redrawing it.

Also check out http://www.gammon.com.au/plugins/ and look for the Hyperlink_URL2 plugin, which probably does most of what you want.