Skip to content

Commit d4054c6

Browse files
authored
Merge pull request #3 from hagaigold/develop
fix delete character from buffer
2 parents 6c66ce9 + 04589cb commit d4054c6

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ It targets communication with embedded systems from remote terminal to quickly s
1313
* Written in C language (C99)
1414
* No dynamic allocation, maximum number of commands assigned at compile time
1515
* Highly configurable
16-
* Simple help-text with `cmd -v` option
16+
* Simple help-text with `cmd -h` option
1717
* User friendly MIT license
1818

1919
## Contribute

dev/main.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@
33
#include <string.h>
44
#include <stdint.h>
55

6+
/**
7+
* \brief Reading one character at a time
8+
*
9+
* This is useful to test the shell in a "raw" mode (non-canonical input)
10+
* Please note that conio.h is a windows only header
11+
*/
12+
#ifndef LWSHELL_TEST_READ_SINGLE_CHAR
13+
#define LWSHELL_TEST_READ_SINGLE_CHAR 0
14+
#endif
15+
16+
#if LWSHELL_TEST_READ_SINGLE_CHAR
17+
#include <conio.h>
18+
#endif
19+
620
void example_minimal(void);
721

822
int32_t
@@ -89,7 +103,13 @@ main(void) {
89103
printf("Start entering your command and press enter...\r\n");
90104
while (1) {
91105
char str[255];
106+
107+
#if LWSHELL_TEST_READ_SINGLE_CHAR
108+
str[0] = getch();
109+
str[1] = '\0';
110+
#else
92111
fgets(str, sizeof(str), stdin);
112+
#endif
93113

94114
/* Insert input to library */
95115
lwshell_input(str, strlen(str));

lwshell/src/lwshell/lwshell.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ lwshell_input(const void* in_data, size_t len) {
285285
case LWSHELL_ASCII_BACKSPACE: {
286286
/* Try to delete character from buffer */
287287
if (lw->buff_ptr > 0) {
288-
lw->buff[lw->buff_ptr] = '\0';
289288
--lw->buff_ptr;
289+
lw->buff[lw->buff_ptr] = '\0';
290290
LW_OUTPUT(lw, "\b \b");
291291
}
292292
break;

0 commit comments

Comments
 (0)