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

Backspace character not decrementing the buffer properly #10

Open
TitanBalls opened this issue Sep 19, 2023 · 0 comments
Open

Backspace character not decrementing the buffer properly #10

TitanBalls opened this issue Sep 19, 2023 · 0 comments

Comments

@TitanBalls
Copy link

TitanBalls commented Sep 19, 2023

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.

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

No branches or pull requests

1 participant