Merge pull request #3 from hagaigold/develop

fix delete character from buffer
This commit is contained in:
Tilen Majerle 2022-01-02 19:13:47 +01:00 committed by GitHub
commit d4054c674f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 2 deletions

View File

@ -13,7 +13,7 @@ It targets communication with embedded systems from remote terminal to quickly s
* Written in C language (C99)
* No dynamic allocation, maximum number of commands assigned at compile time
* Highly configurable
* Simple help-text with `cmd -v` option
* Simple help-text with `cmd -h` option
* User friendly MIT license
## Contribute

View File

@ -3,6 +3,20 @@
#include <string.h>
#include <stdint.h>
/**
* \brief Reading one character at a time
*
* This is useful to test the shell in a "raw" mode (non-canonical input)
* Please note that conio.h is a windows only header
*/
#ifndef LWSHELL_TEST_READ_SINGLE_CHAR
#define LWSHELL_TEST_READ_SINGLE_CHAR 0
#endif
#if LWSHELL_TEST_READ_SINGLE_CHAR
#include <conio.h>
#endif
void example_minimal(void);
int32_t
@ -89,7 +103,13 @@ main(void) {
printf("Start entering your command and press enter...\r\n");
while (1) {
char str[255];
#if LWSHELL_TEST_READ_SINGLE_CHAR
str[0] = getch();
str[1] = '\0';
#else
fgets(str, sizeof(str), stdin);
#endif
/* Insert input to library */
lwshell_input(str, strlen(str));

View File

@ -285,8 +285,8 @@ lwshell_input(const void* in_data, size_t len) {
case LWSHELL_ASCII_BACKSPACE: {
/* Try to delete character from buffer */
if (lw->buff_ptr > 0) {
lw->buff[lw->buff_ptr] = '\0';
--lw->buff_ptr;
lw->buff[lw->buff_ptr] = '\0';
LW_OUTPUT(lw, "\b \b");
}
break;