embedded-cli
embedded-cli copied to clipboard
Backspace character not decrementing the buffer properly
Hello,
I am using your library with a NUCLEO-G071RB dev kit and when I use a backspace, the cli buffer is not properly decremented.
For example :
echo on ->backspace -> n will not yield "echo on" but "echo on\127n"
If I add 0x7F (delete ascii char) to the switch case in cli_put(), it works properly.
cli_status_t cli_put(cli_t *cli, char c)
{
switch(c) {
case CMD_TERMINATOR:
if(!cmd_pending) {
*buf_ptr = '\0'; /* Terminate the msg and reset the msg ptr. */
strcpy(cmd_buf, buf); /* Copy string to command buffer for processing. */
cmd_pending = 1;
buf_ptr = buf; /* Reset buf_ptr to beginning. */
}
break;
case '\b':
case 0x7F: // <- If I add this, backspace works properly
/* Backspace. Delete character. */
if(buf_ptr > buf)
buf_ptr--;
break;
default:
/* Normal character received, add to buffer. */
if((buf_ptr - buf) < MAX_BUF_SIZE)
*buf_ptr++ = c;
else
return CLI_E_BUF_FULL;
break;
}
return CLI_OK;
}
I am not sure in which case the delete ascii would be treated differently, so I leave it up to you to add this fix or not.