apps/nsh: Add support to command line editing on NSH#3657
Open
acassis wants to merge 5 commits into
Open
Conversation
Then readline_write() was called with buflen == 0 it was causing a debug assertion. Now it returns early for instead of asserting. Signed-off-by: Alan C. Assis <acassis@gmail.com>
This commit adds support to nsh> command line editing. This is one of the most missing feature of the NuttShell. If you typed a long command line and make a mistake you need to press Backspace and remove everything until reach that typo. Only the basic editing feature is enabled by default (left/right keys movement, Home/End to move to the beginning or ending of the command line). More advanced features are available when CONFIG_READLINE_EDIT_EMACS is selected. It enables the Emacs-style control keys (Ctrl+A/B/D/E/F/K/U/W) that allow more flexible line editing. Other more advanced feature is enabled when CONFIG_READLINE_CMD_HISTORY and CONFIG_READLINE_EDIT_EMACS_REVERSE_SEARCH are enabled. It allows the user to press Ctrl+R to do reverse search in the command line history. Signed-off-by: Alan C. Assis <acassis@gmail.com> Assisted-by: Claude Code
The original readline_common.c file had some duplicated code that was causing the nsh to be more than 1KB bigger. This clean up will allow adding line editing without increasing the final firmware size too much. Signed-off-by: Alan C. Assis <acassis@gmail.com> Assisted-by: Claude Code
readline cached the current prompt only when TAB completion was enabled, even though line-editing redraws also depend on that cached prompt. With TAB completion disabled, full-line redraws erased the prompt and repainted only the command buffer. Make the prompt cache available whenever line editing is enabled. Signed-off-by: Alan C. Assis <acassis@gmail.com>
acassis
requested review from
cederom,
jerpelea,
linguini1,
simbit18 and
xiaoxiang781216
July 23, 2026 20:14
linguini1
previously approved these changes
Jul 23, 2026
cederom
previously approved these changes
Jul 24, 2026
cederom
left a comment
Contributor
There was a problem hiding this comment.
Thank you @acassis :-) I agree with @xiaoxiang781216 remarks please update before merge.. and one day we need to add vi like edit :D
Replace fragile cursor compensation with full-line redraws where needed, fix Ctrl+W buffer/screen corruption, properly consume unrecognized CSI sequences, and always clean up leaked local-echo characters from buggy serial drivers. These changes make line editing consistent across terminals while preserving existing behavior. Signed-off-by: Alan C. Assis <acassis@gmail.com> Assisted-by: Claude Code (Sonnet 5)
linguini1
approved these changes
Jul 24, 2026
cederom
approved these changes
Jul 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
One missing feature on nsh> is the ability to command line editing. If the user makes a mistake at the beginning of the line he/she needs to erase all characters until arrive there and fix the typo.
Now the user can use the arrow keys to move until the mistake and fix it.
This feature adds less than 700 bytes to the firmware (only Line Edit is enabled by default)
Impact
User will be able to use the nsh> more efficiently
Testing
Line editing: