Posted by
| Nick Gammon
Australia (23,140 posts) Bio
Forum Administrator |
Message
| Hmm - this raises some complex questions, and it is hard to debug with world.Note because obviously doing that adds stuff to line count as you are doing it.
First you use GetLinesInBufferCount to find the last line, the example under GetLineInfo makes that pretty clear. The GetLinesInBufferCount returns the number of lines currently in the buffer, and GetLineInfo gets information about the lines presently in the buffer.
However there is another problem, and that is that there are two sorts of lines. The first is the physical line, which you actually see on the screen, and which GetLineInfo returns information about, and the "logical" lines (paragraphs, really) which end in a newline from the MUD. Depending on the MUD type, and your screen width, physical and logical lines might be the same. However with a narrow screen width they are probably not. Here is an example:
01: ‘Twas brillig, and the slithy toves
02: Did gyre and gimble in the wabe: (newline)
03: All mimsy were the borogoves,
04: And the mome raths outgrabe.
05: "Beware the Jabberwock, my son! (newline)
06: The jaws that bite, the claws that catch!
07: Beware the Jubjub bird, and shun
08: The frumious Bandersnatch!" (newline)
In this hypothetical example, there are 8 physical lines in the screen, however only 3 logical lines (ending in newline). Newline is the character 0x0A (\n) which you receive from the MUD.
Triggers match on logical lines, and thus a trigger that matched on "Jubjub" would match when line 8 arrived, however the trigger match text woiuld be lines 6, 7, and 8 concatenated (ie. the match text would be 'The jaws that bite, the claws that catch! Beware the Jubjub bird, and shun The frumious Bandersnatch!" '.
The reason for this is triggers should match on logical lines, regardless of how you currently have the screen width set up.
So you can see your problem is more complicated than "subtracting one". In this example, you would need to scan backwards, looking for a line with the "hard return" flag set, which would the the last line from the previous logical line, and then keep scanning backwards until you got (yet another) line with the "hard return" flag set, and then add one. The difference between those two batches of lines would be the previous logical line. You then need to get the text from those line(s), concatenate them together, and then do whatever you want with them.
As for your question about the blank line at the end, as far as I can see from the trigger matching code, when the trigger fires that blank line has not been added yet, so the last line in the buffer should actually be the line that caused the trigger to fire (allowing for the multiple line problem I just described).
What is probably much, much simpler, is simply to do this ...
- Make a "catch all" trigger that matches every line (eg. match on * if you don't mind missing blank lines).
- Give this trigger a low sequence (eg. 50) and set it to "keep evaluating" (so other triggers are still processed).
- Have this trigger save the matching line as "the previous line" in your script (eg. in a variable)
- Have your "real" trigger have a lower sequence (eg. 40) - so the previous line is not stored yet
- When the real trigger fires, it can look at the saved line (from the other trigger) to see what was received in the previous line, run its regexp on it, and then do whatever.
That way you achieve the same result without mucking around with lines in the line buffer. Let the program do all that work for you.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|