[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Omit extra blank lines

Omit extra blank lines

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


Pages: 1 2  

Posted by Digs   USA  (17 posts)  [Biography] bio
Date Tue 12 Jun 2012 04:01 AM (UTC)

Amended on Tue 12 Jun 2012 04:15 AM (UTC) by Digs

Message
I'm attempting to omit all extra blank lines from the output window. In other words, I'd like to replace consecutive blank lines with a single blank line

There is an existing plugin that successfully omits all blank lines: http://www.gammon.com.au/forum/?id=8768. It uses the regex pattern "^$".

The second plugin on that page attempts to remove just the extra blank lines, but it misses many. It uses a combination of the patterns "^$" and "^.+$".

I've attempted several different methods myself. No matter what I try, I end up with extra blank lines or I remove too many.

The common issue appears to be that there is no regex pattern that will match all non-blank lines in the output window. I thought that "." would do this, but it matches non-visible (gagged) lines too. It might be ideal if triggers had an invert match setting (PCRE has "-v" or "--invert-match"). Then "^$" with invert match set would match just the non-blank lines.

Thoughts? Ideas? Need more information?
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #1 on Tue 12 Jun 2012 04:17 AM (UTC)

Amended on Tue 12 Jun 2012 05:07 AM (UTC) by Worstje

Message
^$ catches all blank lines, assuming that Global Option is turned on. But I assume it is, from what you already said.

Thus, if it does not catch the lines you think it should, there are three possible reasons I can think of:

1) Those lines aren't actually empty.

2) Another trigger with a higher sequence beats your trigger to it, and they don't have Keep Evaluating turned on.

3) You play a game (an IRE mud?) which terminates its prompts with the IAC EOR/GA character. If there's no new line to signify a line is done, MUSHclient cannot trigger on it. (Thus, it actually ends up thinking that what follows the 'prompt' is a part of the same line.) As such, you may need to turn on the world option where this character is converted to a newline.
[Go to top] top

Posted by Digs   USA  (17 posts)  [Biography] bio
Date Reply #2 on Tue 12 Jun 2012 04:44 AM (UTC)
Message
The pattern "^$" matches all blank lines for me - no issues with that. Yes, the global option is on. Using this pattern by itself works great for removing all blank lines, but I want to just remove the extra blank lines.

The issue is that "." doesn't match just non-blank lines. It matches some "blank" lines too (gagged lines). I need a way to reliably match just the non-blank lines.

One scenario:
Trigger1 - match "^$" and enable triggers 2 & 3
Trigger2 - match "^$" (lower sequence) and gag
Trigger3 - match "." and disable triggers 2 & 3

This looks like it should work, but "." matches some blank (gagged) lines.

I'm playing on Aardwolf, but that's good information. Thanks.
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #3 on Tue 12 Jun 2012 05:14 AM (UTC)
Message
For Trigger3, have you tried printing the line (second) parameter? Also, can you paste it in its entirety?

I suspect you are doing something wrong and the line you think is empty is, in fact, no empty.

Alternatively, can you try ^.+$ for your match pattern? Or try ^[^\n]+$ ?
[Go to top] top

Posted by Digs   USA  (17 posts)  [Biography] bio
Date Reply #4 on Tue 12 Jun 2012 06:16 AM (UTC)

Amended on Tue 12 Jun 2012 06:56 AM (UTC) by Digs

Message
Yes, I've printed the line parameter. To keep things simple, I created a trigger using "^.+$". It sends the matched line back to the output. It echos all visible lines, and non-visible lines.


<triggers>
  <trigger
   enabled="y"
   keep_evaluating="y"
   match="^.+$"
   regexp="y"
   send_to="2"
   sequence="100"
  >
  <send>~ %0</send>
  </trigger>
</triggers>


Here's some of the output. The line's that start with "~ " are the echoed lines. It's easy to see all the "blank" lines that were echoed:


"Posted: Hard Hat Zone."  
~ "Posted: Hard Hat Zone."  

~ <MAPSTART>
~ North of the Grand Plaza
~  
~  
~                             
~          [?] <!> [?]      
~      -------     -------     
~      - - - - < > -!- - -  
~      -------     -------     
~             |.!.|         
~                 |            
~          [?] .#.|         
~      ---                     
~     |##> (~) (!) (!)      
~      ---             ---     
~      - - (~) . > (~) - -  
~      ---             ---     
~     |##> (!) (~) (~) ##>| 
~      ---             ---     
~  
~ [ Exits: N S W * ]
~ <MAPEND>
[ Exits: north south west other ]
~ [ Exits: north south west other ]
(Golden Aura) A stout dwarf, Wesnir, walks slowly, admiring the views of Aylor.
~ (Golden Aura) A stout dwarf, Wesnir, walks slowly, admiring the views of Aylor.
(Red Aura) A goblin carries a large money sack that reads 'Tax'.
~ (Red Aura) A goblin carries a large money sack that reads 'Tax'.
A gnomish incinerator bot is here, belching smoke and fire.
~ A gnomish incinerator bot is here, belching smoke and fire.

~ (Golden Aura) You would stomp A touring dwarf into the ground.
~ (Red Aura) You would stomp An aylorian tax collector into the ground.
~ You would be completely annihilated by Incinerator bot!


I could post one of my test plugins, but they all suffer from the same issue - I can't find a way to match only visible, non-blank lines. My most successful versions just try to work around this issue.
[Go to top] top

Posted by Digs   USA  (17 posts)  [Biography] bio
Date Reply #5 on Tue 12 Jun 2012 06:48 AM (UTC)
Message
Here's a trigger only version. It actually works fairly well, but it removes too many blank lines.

The first trigger matches and removes all blank lines. It counts the number of blank lines, and adds back a single blank line when the count is "1":


  <trigger
   enabled="y"
   group="GagBlanks"
   match="^$"
   omit_from_output="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>local BlankNum

BlankNum = GetVariable("BlankNum")

if BlankNum == nil then
  BlankNum = 0
end

BlankNum = BlankNum + 1

if BlankNum == 1 then
  Note ("")
end

SetVariable ("BlankNum", BlankNum)
SetVariable ("IsBlank", "true")</send>
  </trigger>
</triggers>


The second trigger attempts to match on lines that are not blank. It then resets the blank lines counter.


<triggers>
  <trigger
   enabled="y"
   group="GagBlanks"
   match="."
   regexp="y"
   send_to="12"
   sequence="101"
  >
  <send>local IsBlank

IsBlank = GetVariable("IsBlank")

if IsBlank == "false" or IsBlank == nil then
  SetVariable ("BlankNum", 0)
end

SetVariable ("IsBlank", "false")</send>
  </trigger>
</triggers>
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #6 on Tue 12 Jun 2012 07:00 AM (UTC)
Message
Okay, re-reading this thread five times has made me catch on to what you want. All the details with triggers and regular expressions made me blind to what you wanted to achieve, and I'm sorry it took me a while to grasp that. :)

Your primary problem is most likely that the output window is more than mud output: scripted notes and (if turned on) sent commands are also displayed in it. Those are never sent through the trigger system, because obviously it isn't game output.

Thus Note()-outputting empty lines would defeat any system you have. While I think I can come up with something that works reasonably well, I think you are going about your problem entirely the wrong way, where you are trying to counter the effects of (for example) a leaky roof by putting a bucket underneath rather than properly fixing it. Any bucket-like solution I concoct will only give more headaches in the long run, I can promise you that.

Where do your extra empty lines come from? Why are they happening? Are they side-effects from other omitted text? Is it crappy game output? Do you have scripts that output too much?
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #7 on Tue 12 Jun 2012 07:03 AM (UTC)
Message
We're cross-posting a bit now.

Try setting your trigger to Send to: 'Script (after omit)', number 14. Script works really wonky if you use it the way you use it in the old 12 mode. (Another reason why I avoid scripting like that, but I digress.)
[Go to top] top

Posted by Digs   USA  (17 posts)  [Biography] bio
Date Reply #8 on Tue 12 Jun 2012 08:41 AM (UTC)
Message
No worries! I'm just happy to have someone to bounce things off of. Thanks! ;-)

The semi-solution I posted is ugly, but it's one of my better functioning tests. I tried 14 instead of 12, but didn't see any difference. It's a dead end though, so let's not waste time on it.

If I could match all the visible, non-blank lines in the output window then this would be a non-issue and the solution would be a very simple one. Like I said, PCRE has an option to invert matches - a trigger option that allows for this would be great. If there's another simple option, I'd be interested.


That said, you're right, it is usually better to treat the cause and not the symptom.

I've looked into it, a good portion of the extra empty lines are coming from Aardwolf_Consider_Window (http://www.gammon.com.au/forum/bbshowpost.php?id=9681). Especially with the setting "conw auto". I'll look into it more, and will post there if I have questions about it.


NOTE: This seems to be a handy trigger for seeing the non-gagged output in a notepad window. It works great side-by-side with the regular output window:


<triggers>
  <trigger
   enabled="y"
   keep_evaluating="y"
   match="^.*$"
   regexp="y"
   send_to="5"
   sequence="100"
  >
  <send>%0</send>
  </trigger>
</triggers>



[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #9 on Tue 12 Jun 2012 10:38 AM (UTC)

Amended on Tue 12 Jun 2012 10:40 AM (UTC) by Worstje

Message
I don't have the sanity of mind right now to go into depth on trying to figure your problem out (that's for tomorrow), but I can advise you to use sequence="5" for that trigger. That will pretty much ensure it is executed first. ('1' would still be better technically, but the point is to be before the default 100, and before any other plugins that likely want to pre-empt the defaults. With '5' you leave yourself some room if ever there is a situation you don't want notepadded.)

G'nite for today. :-)
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #10 on Tue 12 Jun 2012 01:48 PM (UTC)

Amended on Tue 12 Jun 2012 02:16 PM (UTC) by Fiendish

Message
Digs said:

Here's some of the output. The line's that start with "~ " are the echoed lines. It's easy to see all the "blank" lines that were echoed:

"Posted: Hard Hat Zone."  
~ "Posted: Hard Hat Zone."  

~ <MAPSTART>
~ North of the Grand Plaza
~  
~  
~                             
~          [?] <!> [?]      
~      -------     -------     
~      - - - - < > -!- - -  
~      -------     -------     
~             |.!.|         
~                 |            
~          [?] .#.|         
~      ---                     
~     |##> (~) (!) (!)      
~      ---             ---     
~      - - (~) . > (~) - -  
~      ---             ---     
~     |##> (!) (~) (~) ##>| 
~      ---             ---     
~  
~ [ Exits: N S W * ]
~ <MAPEND>
[ Exits: north south west other ]
~ [ Exits: north south west other ]
(Golden Aura) A stout dwarf, Wesnir, walks slowly, admiring the views of Aylor.
~ (Golden Aura) A stout dwarf, Wesnir, walks slowly, admiring the views of Aylor.
(Red Aura) A goblin carries a large money sack that reads 'Tax'.
~ (Red Aura) A goblin carries a large money sack that reads 'Tax'.
A gnomish incinerator bot is here, belching smoke and fire.
~ A gnomish incinerator bot is here, belching smoke and fire.

~ (Golden Aura) You would stomp A touring dwarf into the ground.
~ (Red Aura) You would stomp An aylorian tax collector into the ground.
~ You would be completely annihilated by Incinerator bot!


I could post one of my test plugins, but they all suffer from the same issue - I can't find a way to match only visible, non-blank lines. My most successful versions just try to work around this issue.



So in this example which lines exactly do you want to remove? There is an in-game command 'shortmap' for unpadding the automap, but IMO what you think you want out of this is a really bad idea. The map loses any placement consistency if you removing the padding, which makes it pretty hard to use because your eyes have to bounce around too much. That's why it is padded by default. Nowhere else in your example do you have two consecutive blank lines.

And why are you showing map tags in your main output? I would think you'd either use them or turn them off.


Worstje said:
Okay, re-reading this thread five times has made me catch on to what you want. All the details with triggers and regular expressions made me blind to what you wanted to achieve, and I'm sorry it took me a while to grasp that. :)

Your primary problem is most likely that the output window is more than mud output: scripted notes and (if turned on) sent commands are also displayed in it. Those are never sent through the trigger system, because obviously it isn't game output.

Thus Note()-outputting empty lines would defeat any system you have. While I think I can come up with something that works reasonably well, I think you are going about your problem entirely the wrong way, where you are trying to counter the effects of (for example) a leaky roof by putting a bucket underneath rather than properly fixing it. Any bucket-like solution I concoct will only give more headaches in the long run, I can promise you that.

Where do your extra empty lines come from? Why are they happening? Are they side-effects from other omitted text? Is it crappy game output? Do you have scripts that output too much?
Worstje is likely correct. The server to my knowledge never sends multiple blank lines in a row except for specific cases where it is actually beneficial to have them like inside the map tags.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #11 on Tue 12 Jun 2012 07:17 PM (UTC)
Message
Fiendish, look at the trigger above the post: all lines prefixed with ~ are trigger notes that also show the stuff that's been gagged.
[Go to top] top

Posted by Digs   USA  (17 posts)  [Biography] bio
Date Reply #12 on Tue 12 Jun 2012 08:11 PM (UTC)
Message
Looking back over the posts, I think this subject has become a bit muddied. My bad. Sorry that I made you insane Worstje. I shouldn't post when I'm tired. :-)

To clarify, there are several distinct but related points:
#1. I never want more than one visible blank line between the lines of text in the output window.
#2. I'd like to be able to match all visible lines of text in the output window.
#3. My modified Aardwolf_Consider_Window plugin is causing extra blank lines to appear in the output window.


Point #1:

As mentioned, extra blank lines in the output can be caused by a number of things. While it would be ideal to always fix the cause instead of the symptom, that is not always easy or possible. I think Nick Gammon validated this point of view when he made his Omit_Blank_Lines plugin (http://www.gammon.com.au/forum/?id=8768). It works perfectly, but I prefer normal spacing.

The dual trigger example in post 6 is an ugly hack. I only posted it because an example was requested. While somewhat functional, it was a bad choice for discussion.

If point #2 can be addressed, then point #1 will be easily dealt with.


Point #2:

Is there a way to match all visible non-blank lines? The pattern ".+" matches both visible and omitted lines.

@Fiendish: I'm not trying to remove any lines in the example in post 5. I was showing that ".+" matches both visible and omitted lines, so it won't work as a solution for point #1.


Points #1 & #2, Example:

Here's a good, clean example of a plugin that attempts to omit extra blank spaces. It doesn't work because the third trigger named "not_a_blank_line" matches both visible and omitted lines. If you don't have any extra blank spaces to test this with, see the example for point #3.


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Tuesday, June 12, 2012, 9:29 AM -->
<!-- MuClient version 4.81 -->

<!-- Plugin "Omit_Extra_Blank_Lines" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Omit_Extra_Blank_Lines"
   author="Digs"
   id="9742160fe2a5ccb8e35478f1"
   language="Lua"
   purpose="Omits extra blank lines from output."
   date_written="2012-06-12 09:29:45"
   requires="4.81"
   version="1.0"
   >
<description trim="y">
<![CDATA[
Omits extra blank lines from output.

NOTE: The option "File > Global Preferences > Regular expressions can match on an empty string",
      must be checked.
]]>
</description>

</plugin>


<!--  Get our standard constants -->

<include name="constants.lua"/>

<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   match="^$"
   name="first_blank_line"
   regexp="y"
   script="start_omitting_blank_lines"
   send_to="12"
   sequence="2"
  >
  </trigger>
  <trigger
   enabled="n"
   keep_evaluating="n"
   match="^$"
   name="gag_blank_lines"
   omit_from_output="y"
   regexp="y"
   sequence="1"
  >
  </trigger>
  <trigger
   enabled="n"
   keep_evaluating="y"
   match="."
   name="not_a_blank_line"
   regexp="y"
   script="stop_omitting_blank_lines"
   send_to="12"
   sequence="10000"
  >
  </trigger>
</triggers>

<script>
<![CDATA[

function start_omitting_blank_lines ()
  EnableTrigger("gag_blank_lines", true)
  EnableTrigger("not_a_blank_line", true)
end

function stop_omitting_blank_lines ()
  EnableTrigger("gag_blank_lines", false)
  EnableTrigger("not_a_blank_line", false)
end

]]>
</script> 

</muclient>




Point #3

The Aardwolf_Consider_Window plugin uses this line in its code: Send ("echo nhm"). This is rather spammy, so I changed it to: SendNoEcho ("echo nhm"). The plugin triggers on this echo to refresh its window, and it does this often with the setting "conw auto". The echo is omitted, but strangely a blank line is left behind. Use the following example to easily reproduce this behavior (change the first trigger's match to something reproducible). Thoughts?


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Tuesday, June 12, 2012, 11:17 AM -->
<!-- MuClient version 4.81 -->

<!-- Plugin "EchoTest" generated by Plugin Wizard -->

<muclient>
<plugin
   name="EchoTest"
   author="Digs"
   id="7d2b31fb5db49f949d802307"
   language="Lua"
   purpose="TEST: SendNoEcho + omit the echo = extra space in output."
   save_state="y"
   date_written="2012-06-12 11:14:05"
   requires="4.81"
   version="1.0"
   >
<description trim="y">
<![CDATA[
Send an echo with SendNoEcho. 
Omit the echo.
There is then an extra space in the output window.
]]>
</description>

</plugin>


<!--  Get our standard constants -->

<include name="constants.lua"/>

<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   keep_evaluating="y"
   match="^[ Exits"
   regexp="y"
   script="send_echo"
   send_to="12"
   sequence="100"
  >
  </trigger>
  <trigger
   enabled="y"
   keep_evaluating="n"
   match="^EchoTest$"
   omit_from_output="y"
   regexp="y"
   sequence="100"
  >
  </trigger>
</triggers>

<script>
<![CDATA[

function send_echo ()
  SendNoEcho ("echo EchoTest")
end

]]>
</script> 

</muclient>

[Go to top] top

Posted by Digs   USA  (17 posts)  [Biography] bio
Date Reply #13 on Tue 12 Jun 2012 09:41 PM (UTC)
Message
Point #3

The extra blank line left by omitting the echoed text is not so strange. The blank line following the echo just needs to be removed too. Here's a modified version of the example that creates no extra blank lines. I'll make the changes to my modified plugin:


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Tuesday, June 12, 2012, 11:17 AM -->
<!-- MuClient version 4.81 -->

<!-- Plugin "EchoTest" generated by Plugin Wizard -->

<muclient>
<plugin
   name="EchoTest"
   author="Digs"
   id="7d2b31fb5db49f949d802307"
   language="Lua"
   purpose="TEST: SendNoEcho, and then remove the echo and the next blank line."
   save_state="y"
   date_written="2012-06-12 11:14:05"
   requires="4.81"
   version="1.0"
   >
<description trim="y">
<![CDATA[
Send an echo with SendNoEcho. 
Omit the echo, and the next blank line to avoid an extra blank line.
]]>
</description>

</plugin>


<!--  Get our standard constants -->

<include name="constants.lua"/>

<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   keep_evaluating="y"
   match="^[ Exits"
   regexp="y"
   script="send_echo"
   send_to="12"
   sequence="100"
  >
  </trigger>
  <trigger
   enabled="y"
   lines_to_match="2"
   match="^EchoTest\n\z"
   multi_line="y"
   regexp="y"
   script="omit_echo_and_blank"
   send_to="12"
   sequence="100"
  >
  </trigger>
</triggers>

<script>
<![CDATA[

function send_echo ()
  SendNoEcho ("echo EchoTest")
end

function omit_echo_and_blank ()
  DeleteLines(2)
end

]]>
</script> 

</muclient>
[Go to top] top

Posted by Digs   USA  (17 posts)  [Biography] bio
Date Reply #14 on Tue 12 Jun 2012 10:42 PM (UTC)
Message
Point #3

Unfortunately, it isn't practical to use multi-line triggers within the plugin Aardwolf_Consider_Window as a solution. It is not possible to know beforehand, which of the lines omitted by the single-line triggers will be followed by a blank line. The game output for "consider all" varies. Also, modifying the "^nhm$" trigger so it matches 2 lines breaks things.

1st "consider all":


(Red Aura) You would stomp A troglodyte into the ground.
(Red Aura) You would stomp Glittering cavern dust into the ground.
You would stomp A rock creature into the ground.
You would stomp A slimy rock into the ground.

nhm



2nd "consider all":


(Red Aura) You would stomp A troglodyte into the ground.
(Red Aura) You would stomp Glittering cavern dust into the ground.
You would stomp A rock creature into the ground.
You would stomp A slimy rock into the ground.
You would stomp A fossil into the ground.
You would stomp A fossil into the ground.

nhm

[Go to top] 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.


50,792 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]