Feature request, hiding 'backspace' character

Posted by Dcruze on Thu 02 Aug 2018 02:42 PM — 4 posts, 17,747 views.

#0
With the following LPC code, which is meant to make it more difficult for players to use triggers - it displays normally in CMUD and TinyFugue, but in MushClient it tries to print the backspace characters (char 8), which makes it look like garbage in the terminal window.

Is there something I can do (as a player), to prevent this? It should appear like normal text.

-d


string no_trig(string str)
{
   string *chars;
   int     i;

   if(!stringp(str) || ((i = strlen(str)) < 2)){
      return str;
   }

   chars = allocate(i);

   while(i--){
      chars = str[i..i];
   }

   return implode(chars, " " + sprintf("%c", 8));
}
#1
This is what I mean, MushClient is on the left and CMUD is on the right. The added space and backspace should cancel themselves out, but it doesn't in MushClient.

https://i.imgur.com/rk0g7Gj.png

[img]https://i.imgur.com/rk0g7Gj.png[/img]
Australia Forum Administrator #2
There's some discussion about that here:

Template:post=5114
Please see the forum thread: http://gammon.com.au/forum/?id=5114.


This simple plugin will handle the case you've shown which has a character followed by a single backspace:

Template:saveplugin=Handle_Backspaces
To save and install the Handle_Backspaces plugin do this:
  1. Copy the code below (in the code box) to the Clipboard
  2. Open a text editor (such as Notepad) and paste the plugin code into it
  3. Save to disk on your PC, preferably in your plugins directory, as Handle_Backspaces.xml
    • The "plugins" directory is usually under the "worlds" directory inside where you installed MUSHclient.
  4. Go to the MUSHclient File menu -> Plugins
  5. Click "Add"
  6. Choose the file Handle_Backspaces.xml (which you just saved in step 3) as a plugin
  7. Click "Close"
  8. Save your world file, so that the plugin loads next time you open it.



<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="Handle_Backspaces"
   author="Nick Gammon"
   id="955936e1d411d5663bcc5dba"
   language="Lua"
   purpose="Attempts to processing incoming backspaces"
   date_written="2018-08-03"
   requires="4.90"
   version="1.0"
   >
</plugin>

<!--  Script  -->
<script>
<![CDATA[

function OnPluginPacketReceived (sText)
  return string.gsub (sText, ".\008", "")  -- backspace removes previous character
end -- function

]]>
</script>
</muclient>



That uses the OnPluginPacketReceived callback to get at the incoming packet before it is displayed. This will fail for more complex cases (eg. xxx\b\b\b) however it should get you past this initial problem.

If they try getting funny and having two or three backspaces in a row (with a corresponding number of junk characters) then this modification to the function would handle it:


function OnPluginPacketReceived (sText)
  sText = string.gsub (sText, "...\008\008\008", "")  -- three in a row
  sText = string.gsub (sText, "..\008\008", "")        -- two in a row
  return string.gsub (sText, ".\008", "")  -- backspace removes previous character
end -- function


After that you might want to write a proper loop to handle any number of them.
#3
That works perfectly. Thanks a bunch :)

-d