how to checking contents of next line received

Posted by Jing Wu on Tue 20 May 2008 08:02 PM — 4 posts, 20,448 views.

Australia #0
Hi,

Im look for a way to check the next line recevied after a trigger executed.

For example:
here is a trigger: ^Andy says xxx
and it is triggered.
i need to check the next line after this trigger to decide what commands will be sent.
so i got two questions:
1. how to obtain current line num. of this trigger?
2. how to check the next line of this trigger?

if I am able to get the line num.(lineNum) and use
GetLineInfo(lineNum + 1, 3). In this time, the new line might not be recevied from the server, will it return nil?
Or I can set a callback function which will be executed once (lineNum + 1) line is recevied?

Thanks!

#1
Instead of this (rather complicated-sounding) method, you could make a catch-all trigger that is enabled by the first trigger and which disables itself.
Australia Forum Administrator #2
You certainly can't obtain the contents of line+1 because it hasn't arrived yet. Triggers fire as soon as a line arrives.

However one solution is a multi-line trigger, see example below. It depends a bit on what is in the second line, I have assumed anything as you didn't say.

This trigger will fire after the second line arrives, and will check that the first line is "Andy says <something>".


<triggers>
  <trigger
   enabled="y"
   lines_to_match="2"
   match="^Andy says (.+)\n(.+)\Z"
   multi_line="y"
   regexp="y"
   send_to="2"
   sequence="100"
  >
  <send>
%%1 is %1
%%2 is %2
</send>
  </trigger>
</triggers>


See http://mushclient.com/pasting for how to copy that into the client.

As Beale says, another approach is for the first trigger to enable a "catch-all" trigger (ie. matching "*") which is initially disabled. This second trigger then knows that it must have followed the "Andy says" line. The second trigger then disables itself. The FAQ at http://mushclient.com/faq has an example of this sort of thing in point 37.
Australia #3
Thanks Nick.
It's a good idea to use multi-line trigger, which is an easy way to reach my purpse.
Originally, i was thinking about using plugin with "OnPluginLineReceived" callback, but it seems i need to write lots of codes.