Hi all,
I've made a patch to add command line edition (including arrow keys) and history to the shell prompt :
ENTER ; validate edition
CTRL-C or ESCAPE+ESCAPE : abort edition
BACKSPACE (BS or DEL) : delete character on the left of cursor
CTRL-A / CTRL-E : move cursor to beginning / end of line
CTRL-B / ARROW-LEFT : move cursor back one character
CTRL-F / ARROW-RIGHT : move cursor forward one character
CTRL-P / ARROW-UP : older history entry
CTRL-N / ARROW-DOWN : newer history entry
This works with shell on serial console but also when connected through Telnet.
I've tested this patch with MQX 3.4 and MQX 3.7 but it should work with other versions as nothing seems to have changed in the impacted code.
This support is added in a new Shell_getline() function called at prompt that temporarily disables echo on stdin and manages the echo by itself (as does bash shell under Linux). This function is called by the shell instead of fgets() for prompt.
I've also fixed the telnet server to make it work also when connected to the MQX shell through Telnet.
This also fixes the IO_IOCTL_SERIAL_SET_FLAGS ioctl that was failing in disabling the echo when connected through Telnet; so now your can disable the echo for example at a password imput.to prevent password from beeing displayed.
By default the history size is only one command (the last one), but it can be set to any greater value (if you have enough RAM) by changing shell/source/include/sh_prv.h from :
char HISTORY[SHELL_MAX_CMDLEN]; // one line of history
to
char HISTORY[SHELL_MAX_CMDLEN*10]; // 10 lines of history
If you want to call Shell_getline() from an application program, you can declare it as global and use some history or not depending on requirements.
In addition you can also use the last patch I posted if you want to fix non working BACKSPACE key or prevent over deletion when using standard fgets(), fgetline() .... functions on serial console, in existing applications other than shell prompt.
Also please note that "!" no more works to recall last command (use ARROW-UP or CTRL-B), so in addition to what the patch does, you can also delete the whole "if" block containing the deleted line :
// strncpy(shell_ptr->HISTORY,shell_ptr->CMD_LINE,sizeof(shell_ptr->HISTORY));
If you want to keep support for "!", add it to the Shell_getline_internal() function where ENTER or \n are processed to return the last command from history when "!" has been typed.