Skip to content
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

Add ability to "refresh" the command prompt for a new session #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

joemcool
Copy link

This PR adds a function shell_refresh(const char * msg), which "refreshes" the command prompt by removing any input from the input buffer and shell, and prints a welcome message and new command prompt. This is useful if the user will be connecting to the shell after the command prompt has been printed (eg, when connecting via Telnet). The welcome message must be supplied when the function is called, and can be either in RAM or PROGMEM.

This PR builds on #19, since it uses the same shell_clear_command() function. I can resubmit the PR without the rest of the command history features from #19 if that is desired.

This commit adds a command history feature.  It works similarly to other command shells, where the up and down arrow keys cycle through recently used commands. The user can make changes to a previous command's text before running it again.  If the user has already entered part of a command and then scrolls through the history, the partial command is saved at the beginning of the history list.we  This feature requires a significant amount of memory to be used for storing the command history list.  As a rule of thumb, command history should only be enabled on systems with at least 8k of RAM (Arduino MEGA and better).  It can be enabled on smaller systems, but only when (CONFIG_SHELL_MAX_INPUT * (CONFIG_SHELL_COMMAND_HISTORY + 1)) + 4 bytes of RAM are available.  For a history list that is 10 commands long and the default input buffer length 0f 70, this would be 774 bytes.  This much memory usage only makes sense on some systems, so this feature is disabled by default.  To enable it, set the CONFIG_SHELL_COMMAND_HISTORY macro in Shell.h to the desired command history list length.  The max history length is 255 entries.

To implement this feature, the following changes were made:
--A number of global variables were added (4 bytes), and count was moved from a static in shell_task to be a global as well
--shellbuf is expanded into a two dimensional array, the first dimension is the list of historic commands, and the second dimension is the index within that command buffer.  The command history list is implemented as a ring buffer.
--Added shell_clear_command(), a public function to clear the current command buffer and displayed text in the shell
--Basic processing of VT100 escape sequences, including Command Sequence Indroducer sequences, for receiving arrow keys.  This may also lead to implementing the left and right arrow keys as a future project, allowing the user to move a cursor left and right when typing a command.  The biggest hurdle to this right now is that editing the middle or beginning of a long command will lead to lots of inserting in the middle of a command buffer, which will be slow.
--In addition to using count to track the length of an entered command, command text (including arguments) are now terminated by a NULL char
--When command history is enabled, command text (including arguments) are now copied to a new buffer for parsing.  This prevents the NULL string terminators between each argument from being added to the command history entry.
Adds Dont Linemode and Will Echo Telnet options to the Telnet example.  These are needed for cleanly sending arrow keys.  NOTE: Putty doesn't respect Dont Linemode, and requires that Terminal->Local Line Editing be forced off.

Also fixed a typo in Shell.h
This PR adds shell_refresh(), which refreshes the command prompt by removing any input from the input buffer and shell, and prints a welcome message and new command prompt.  This is useful if the user will be connecting to the shell after the command prompt has been printed (eg, when connecting via Telnet).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant