Skip to content

apps/nsh: Add support to command line editing on NSH#3657

Open
acassis wants to merge 5 commits into
apache:masterfrom
acassis:nsh_cmdline
Open

apps/nsh: Add support to command line editing on NSH#3657
acassis wants to merge 5 commits into
apache:masterfrom
acassis:nsh_cmdline

Conversation

@acassis

@acassis acassis commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

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)

original stm32f103-minimum:nsh without line edit, emacs, TAB and History support:
alan@dev:~/nuttxspace/nuttx$ arm-none-eabi-size nuttx
   text	   data	    bss	    dec	    hex	filename
  51192	    472	   2952	  54616	   d558	nuttx

With: Line Edit, Without Emacs, TAB, History:
$ arm-none-eabi-size nuttx
   text	   data	    bss	    dec	    hex	filename
  51844	    472	   2956	  55272	   d7e8	nuttx

With: Line Edit and Emacs, Without TAB, History:

$ arm-none-eabi-size nuttx
   text	   data	    bss	    dec	    hex	filename
  52220	    472	   2956	  55648	   d960	nuttx

With: Line Edit, Emacs and TAB, Without History
$ arm-none-eabi-size nuttx
   text	   data	    bss	    dec	    hex	filename
  52756	    472	   2960	  56188	   db7c	nuttx

With: Line Edit, Emacs, TAB and History, Without: Reverse Search
$ arm-none-eabi-size nuttx
   text	   data	    bss	    dec	    hex	filename
  53060	    472	   3228	  56760	   ddb8	nuttx

With: Line Edit, Emacs, TAB, History and Reverse Search
$ arm-none-eabi-size nuttx
   text	   data	    bss	    dec	    hex	filename
  53896	    472	   3228	  57596	   e0fc	nuttx

Impact

User will be able to use the nsh> more efficiently

Testing

Line editing:

image

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>
acassis and others added 4 commits July 23, 2026 15:53
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>
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants