Delete Character action

Topics: Developer Forum, Project Management Forum
Developer
Aug 21, 2013 at 8:56 PM
I found that the Delete action was malfunctioning, so I tried to fix it. Upon sending that command, the buffer from caret to the end would be filled with a character. The method (DeleteCharacter(), line 1149 Keyboard.cs) contained a lot of code. It looks like it copied and juggled some things around, and I don't understand why it was doing that. I "fixed" the bug by checking the cursor position's field attributes to make sure it was not protected and then just sent a null character to the cursor position.
I haven't found any problems with this fix, but I'd like to call attention to it and see if a second pair of eyes could take a look. Please check it out if you speak 3270.

Thank you,
Josh Usovsky
Oct 15, 2013 at 6:17 PM
I think this library is port to C# from C++. It has some bugs but is usefull for handling basic client host actions. I was trying to develop custom 3270 emulator based on this library some years ago, but finally I gave up on that project. I took a look at your basic wpf emulator nad I have to say it has some potential. Mine was developed in WinForms as I am not very familiar with WPF. I am glad that this project is not completely dead ;)
Developer
Oct 21, 2013 at 7:37 PM
Yes, this library is a port of x3270. That's why I want to pull my hair out when I have to go very deep into the code. I've done my best to clean it up, let alone fixing all the excisting bugs, but much work remains! :) Thanks for the compliment, Adlorem. Spend some time with WPF. It's not easy moving over to WPF from a Winforms history, but the productivity you gain is well worth it. It can be downright heady at times!

Josh Usovsky
Oct 23, 2013 at 7:28 AM
I know your problem. I had to rewrite lots of code before using this library as my host connector. Lots of code I did not fully understood ;). Actually out of curiosity I moved my old project to WPF, but it looks like WinForms are more suitable for an oldschool stuff like terminal emulators ^^. Execution and rendering is much more effective then in WPF. In WPF I am getting a really nasty lags, when operating on terminal. Maybe its my approach, because I did in old school way like Attachmate 2000. It emulates all actions on host in real time. I didn't noticed this in new emulators like f.e. host explorer, new attachmate extra. Maybe it is because they don't refresh host screen all the time you type on terminal. My approach was sendkey -> wait for host response -> render screen in buffer -> display on terminal. There is also memory issue. With WPF i got memory consumption 200% higher. I am not telling that WinForms are better. They are actually not, because its an old technology (like mainframes itself). They were just better on my approach which is not necessarily the best ;)
Nov 23, 2013 at 12:08 PM
Edited Nov 23, 2013 at 12:38 PM
Josh I am currently back to Big Iron thing, and tried your changes to the library. Please reconsider your DeleteCharacter approach. Your current action just sends null to current cursor position. That is fine but what about text left on the right side of cursor position? Surviving characters should be shifted to the left. In is done by blockcopy of existing array of bytes. Actually this function is working fine. What was your problem?
Developer
Dec 3, 2013 at 4:47 PM
Hmm. Let me revisit that. For me, it was not working. If I recall, it would move the cursor back, but was not removing the deleted character. I tried to duplicate the functionality I was seeing in Attachmate Reflection. A character would be cleared, but the remaining text to the right of the cursor did not move.
And I apologize for the slow response. I cut the cable while traveling for Thanksgiving!

Josh Usovsky
Dec 3, 2013 at 8:04 PM
Well Josh, for me function you described is reserved for <insert> which is not implemented in this library. Delete function should shift remaining characters to the left. Lets say you have line of text and you want to remove just one character. In this case you have to retype whole remaining text to the right? I don't think its good solution. Of course it depends on emulator, but it works like this in all emulators I know. I have connected new library to my emulator and:
  1. XML rendering is malfunctioning. 30% of my mainframe screens are wrongly displayed. It is due to conversion method used in library.
  2. Some of fields are not implemented in XML.
  3. Insert function doesn't work at all.
  4. BlockCopy makes strange things ;))
    You have made a great job with renaming functions to more readable, but I cannot agree with you about delete character function sorry ;)
I also looked into you new function WaitForHostSettle. Looks interesting. Reminds me WaitForHostQuiet from old Attachmate. I was writting macros in it like 10 years ago ;). Looks interesting. I admire your hard work.
Developer
Dec 17, 2013 at 7:39 PM
Okay, I finally got around to doing some work on this last night. I found the problem with Delete(). There was a bug in CopyBlock() that I fixed, which was the original problem with Delete(). After fixing CopyBlock(), I restored Delete() functionality. It should work as you're expecting again. I was thinking of backspace, which just moves the cursor back without deleting a character. That's the functionality that I am not too fond of because it is different from everything contemporary. At any rate, grab the latest code for the fixes.
I also made a couple small changes in an attempt to help make cursor tracking a bit better. I added a CursorLocationChanged event to TNEmulator. I'm having some trouble with it in the WPF demo app in that the cursor in the TextBox jumps back to zero any time I use the fixed Delete() method. I believe it must be some sort of collision between the binding and the processing the TextBox does on its own.
Dec 20, 2013 at 8:34 PM
Edited Dec 20, 2013 at 8:36 PM
Glad to hear that ;)

Meanwhile I fixed the code by myself. To ensure XML is rendered properly change in code:
        private string encodeXML(string data)
        {
            //data = data.Replace("\"", "&quot;");
            //data = data.Replace(">", "&gt;");
            data = data.Replace("<", "&lt;");
            data = data.Replace("&", "&amp;");
            return data;
        }
to:
        private string EncodeXML(string data)
        {
            data = System.Security.SecurityElement.Escape(data);          
            return data;
        }
That fixes all problems with wrongly formatted screens permanently.
Developer
Dec 20, 2013 at 8:59 PM
Thanks! I'll get that integrated shortly. I've never used the XML functionality, so I appreciate the fix!

Josh
Dec 20, 2013 at 11:21 PM
Edited Dec 24, 2013 at 7:59 PM
You are welcome. BTW:

Skwerl wrote:
I was thinking of backspace, which just moves the cursor back without deleting a character. That's the functionality that I am not too fond of because it is different from everything contemporary. At any rate, grab the latest code for the fixes.

To implement destructive backspace replace with:
public bool BackSpaceAction(params object[] args)
        {
            if (this.keyboardLock != 0)
            {
                this.EnqueueTypeAheadAction(new ActionDelegate(BackSpaceAction), args);
                return true;
            }
            if (this.telnet.IsAnsi)
            {
                this.telnet.SendErase();
                return true;
            }
            if (this.reverseMode)
            {
                this.DeleteCharacter();
            }
            else if (!this.flipped)
            {
                this.MoveLeft();
               this.DeleteCharacter();
            }
            else
            {
                int address;

                address = this.telnet.Controller.CursorAddress;
                this.telnet.Controller.DecrementAddress(ref address);
                this.telnet.Controller.SetCursorAddress(address);
            }
            return true;
        }