Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Python ➜ Python style runs

Python style runs

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Grek   Sweden  (12 posts)  Bio
Date Sat 09 Aug 2008 09:05 AM (UTC)
Message
Does anyone have any ideas on how to grab the style run from the line(s) that triggered a trigger? The problem I run into is that I don't know how many lines the triggering line resulted in, nor which line it was.

I think the problem could be circumvented if styleruns and trigger scripts were available like it is in lua.

Currently trying to redirect output to miniwindows while keeping the original style.
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #1 on Sat 09 Aug 2008 09:43 PM (UTC)
Message
It can be done fairly simply:


  • Use GetLinesInBufferCount to find the last line in the output buffer. This will be the one that triggered the trigger.

  • However if there might have been multiple lines (without a newline) you need to work backwards to find the start of the "real" line, not the physical one on the screen. To do this:


    • Subtract 1 from the line count, and check (with GetLineInfo (line, 3)) if that line ended with a newline. If not, keep going backwards until it does.

    • You have now found the end of the *previous* line.

    • Add 1 - this is now the start of the current group of lines


  • For the line number you just found, to the end of the output buffer (GetLinesInBufferCount) is the current "real" line. Just use GetStyleInfo on each of those lines in sequence to get their styles.



- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Worstje   Netherlands  (899 posts)  Bio
Date Reply #2 on Sat 18 Oct 2008 09:26 PM (UTC)

Amended on Sat 18 Oct 2008 09:29 PM (UTC) by Worstje

Message
Okay, resurrecting an old thread, but I think it needs doing. Lua has a nice styles variable, which corresponds to the current trigger - which is nice. I thought there was a function that returned the exact same flag through a method call, like GetTriggerWildcard, but it seems there isn't.

The above method, however, is not a foolproof fix. I was just searching on how to do it since I had someone ask who prefers to code in Python, and this simply won't do - the fact it is based on lines -displayed- means other triggers can interfere: omit from output flags and extra notes come to mind while the data as it comes in is generally just what you want.

I'll be fair I am not needing it, and that I assume the above band-aid would do for most situations, but now that I see it I rather see the possibility for a thorough fix rather than a band-aid that will end up blowing up at some point in the future. That and it is still convoluted compared to the Lua styles parameter.

So, as a solution... I think it wouldn't be too hard to make a GetTriggerStyles() function to mirror GetTriggerWildcard() so other languages have the same ease of use that Lua does. (And using Lua isn't always an option, heh.)

(I'm not being too troublesome, am I Nick? ^_^)

Edit: Or, get rid of the problem alltogether once MUSHclient v5.0 comes in. Make the styles parameter standard on v5+ and make the non-styles version standard for v2-v4.x. You can decide what calling convention you should use in a plugin based on the minimum-version information noted in the plugin. Although the above function still has its charms as a complement to GTW.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


12,383 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.