-
Notifications
You must be signed in to change notification settings - Fork 16
Add support for command line editing #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Forget about my initial comment here. Tried accidentally with an old FW. Works as expected. Really cool would be to use cursor up to recall the last cmd from history. |
Yes, I know 😁 In order to get this working, I had to first learn how command editing on serial consoles actually works, by intercepting what is sent back and forth if you connect a USB-UART cable to a Raspberry Pi Zero... |
|
I added support for also editing using the command history as requested. This means that cursor-up and cursor-down allows to go through the history of previous commands. |
The current code for entering commands via the serial CLI is completely refactored and moved out of rtlplayground.c into a separate file cmd_edit.c putting code into BANK2. The serial ring buffer sbuf[] is now exclusively used for receiving keys, including escape sequences (DEL will generate a 4-byte escape sequence). The command is now held in cmd_buffer. This reduces XMEM use, because the serial buffer can be much smaller. Supported is only editing the current command line via backspace, del, cursor left and right. Because the code cannot distinguish escape sequences which are not yet complete (because the serial isr has not yet put all characters into the serial buffer) from the dozens of unsupported ones (F-keys/home, Page up/down, cursor up/down...) they are ignored and remain in the serial buffer until the ring-pointer overwrites them. This is standard behaviour for consoles, which will print out garbage for unsupported characters. In this implementation, the command line buffer and the visible command line in the terminal are always synced, so garbage can be removed again by ediing the line. The code makes several redundant checks in order to prevent race-conditions between the serial ISR and the comand-editing code.
|
Rebased to latest main because of merge conflicts. |
The current code for entering commands via the serial CLI is completely refactored and moved out of rtlplayground.c into a separate file cmd_editor.c putting code into BANK2.
The serial ring buffer sbuf[] is now exclusively used for receiving keys, including escape sequences (DEL will generate a 4-byte escape sequence). The command is now held in cmd_buffer. This reduces XMEM use, because the serial buffer can be much smaller.
Supported is only editing the current command line via backspace, del, cursor left and right.
Because the code cannot distinguish escape sequences which are not yet complete (because the serial isr has not yet put all characters into the serial buffer) from the dozens of unsupported ones (F-keys/home, Page up/down, cursor up/down...) they are ignored and remain in the serial buffer until the ring-pointer overwrites them. This is standard behaviour for consoles, which will print out garbage for unsupported characters. In this implementation, the command line buffer and the visible command line in the terminal are always synced, so garbage can be removed again by ediing the line.
The code makes several redundant checks in order to prevent race-conditions between the serial ISR and the comand-editing code.