drivers/serial: Modify serial/pty to allow NSH/Telnet line edit#19499
Conversation
Both the UART and PTY serial drivers previously assumed all VT100/ANSI escape sequences were fixed 3-byte CSI sequences, causing longer CSI and SS3 key sequences (such as Home, End, Delete, and modified keys) to leak stray characters into the terminal when local echo was enabled. This patch replaces the fixed-length logic with a state machine that correctly recognizes and suppresses escape sequences of any length, while preserving the data delivered to applications. The change only affects local echo behavior, is fully backward compatible, and has been validated with both interactive NSH sessions and automated PTY tests. Signed-off-by: Alan C. Assis <acassis@gmail.com> Assisted-by: Claude Code
|
|
@xiaoxiang781216 @jerpelea @cederom @linguini1 please take a look |
linguini1
left a comment
There was a problem hiding this comment.
I wonder if this will fix the weird 'K' artifact on the Picos
Yes, probably it will too |
|
I will try with the Pico today if I have some time and let you know. That would be awesome! |
I think some terminals that are not VT102 compatible also will display the [^K, please double check if your serial console terminal supports it. |
|
@linguini1 a curiosity: if you press: Ctrl+V the next key you type will be printed as raw key, so you will see how the key is send to the application (the terminal in this case). Try: Ctrl+V+ENTER, or other special key, like arrows keys, etc. |
|
Haha just like Vim! I'll try that as well. |
This might have been it, I noticed it I think mostly with a pyserial shell but almost never in Minicom. |
Yes, pyserial will not parser these codes, unless you add some VT102 filter |
|
Ah, so that was the issue after all then. Anyways, good improvement! |
Summary
Both the UART and PTY serial drivers previously assumed all VT100/ANSI escape sequences were fixed 3-byte CSI sequences, causing longer CSI and SS3 key sequences (such as Home, End, Delete, and modified keys) to leak stray characters into the terminal when local echo was enabled. This patch replaces the fixed-length logic with a state machine that correctly recognizes and suppresses escape sequences of any length, while preserving the data delivered to applications. The change only affects local echo behavior, is fully backward compatible, and has been validated with both interactive NSH sessions and automated PTY tests.
Assisted-by: Claude Code
Impact
Users will be able to use keys arrows, Home, End, etc to edit the nsh> command line (patch to nuttx-apps will come)
Testing
Tested on sim:nsh and stm32f103-minimum:nsh
Note the cursor moving to the left: