fasteddy516 / SimplySerial

A windows console application for serial communications.
MIT License
193 stars 23 forks source link

Arrow keys not working #12

Closed longwdl closed 3 years ago

longwdl commented 3 years ago

Check in teminals below:

  1. Windows Terminal
  2. CMD
fasteddy516 commented 3 years ago

The cursor (arrow) keys don't have direct ASCII table mappings like other characters, which is why they don't currently work. I can add support for sending the corresponding ANSI escape sequences for cursor movement, which should work in the majority of cases. (Support for ANSI sequences is not universal, but seems to be common on devices/applications that actually make use of the cursor keys.)

fasteddy516 commented 3 years ago

I was thinking about this more over the weekend, and came to two realizations:

1) I do not currently have anything to test against that both communicates via serial/RS-232 and makes use of the cursor keys.

2) SimplySerial is a raw serial terminal, not a full-fledged terminal emulator, so it will not interpret any incoming ANSI escape sequences sent back from a connected device.

Are you able to provide any information about your use case and/or device that requires use of the cursor keys? If you just need the cursor keys to send something so that you can process them on a device, that's easy enough for me to implement. If you want to use SimplySerial for something like connecting to a serial tty on a Raspberry Pi, you're going to run into problems displaying incoming data from the Pi.

longwdl commented 3 years ago

I was thinking about this more over the weekend, and came to two realizations:

  1. I do not currently have anything to test against that both communicates via serial/RS-232 and makes use of the cursor keys.
  2. SimplySerial is a raw serial terminal, not a full-fledged terminal emulator, so it will not interpret any incoming ANSI escape sequences sent back from a connected device.

Are you able to provide any information about your use case and/or device that requires use of the cursor keys? If you just need the cursor keys to send something so that you can process them on a device, that's easy enough for me to implement. If you want to use SimplySerial for something like connecting to a serial tty on a Raspberry Pi, you're going to run into problems displaying incoming data from the Pi.

I use SimplySerial for something like connecting to a serial tty on a Raspberry Pi. I want to use allow keys to look through my command history on remote device.

fasteddy516 commented 3 years ago

I just wanted to let you know I am looking into this, but it may be a couple of weeks before I have it finished.

I realized after my last message that even within the CircuitPython environment for which SimplySerial was developed, using the cursor keys allows scrolling through data history for the input() function (and possibly others), so supporting that functionality makes good sense. I still don't intend to turn SimplySerial into a fully-fledged terminal emulator with full ANSI escape-code support, as that is beyond the scope of what it is intended for.

Fortunately, getting the cursor keys to work is pretty straightforward, but processing the responses from a device involves processing the ANSI cursor-control sequences sent back to automatically erase the previous command from the screen and write the new one in its place, which will take some time for me to wrap my head around.

fasteddy516 commented 3 years ago

This might be a lot easier than I anticipated - it turns out Windows 10 console apps have native support for processing escape sequences, it just isn't enabled by default.

https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences

There also doesn't appear to be a straight-forward way for a C# novice to enable it, as everything in that article is c/c++. Thankfully, @tomzorz has posted an awesome gist showing exactly how to do it:

https://gist.github.com/tomzorz/6142d69852f831fb5393654c90a1f22e

fasteddy516 commented 3 years ago

Yep, way easier than I thought. I've published 0.6.0-beta here. If you can try it out and let me know if it works for you, that would be greatly appreciated.

longwdl commented 3 years ago

Yep, way easier than I thought. I've published 0.6.0-beta here. If you can try it out and let me know if it works for you, that would be greatly appreciated.

It works fine after upgrade to 0.6.0-beta.