Added Kconfig for enabling 0 length returns from linenoise

This commit is contained in:
Michael 'ASAP' Weinrich 2020-03-15 21:31:48 -07:00 committed by Ivan Grokhotkov
parent 8a2413b5c0
commit c34352549a
2 changed files with 16 additions and 2 deletions

View file

@ -0,0 +1,10 @@
menu "Linenoise"
config ESP_LINENOISE_RETURN_ZERO_STRING
bool "Return 0 length strings"
default n
help
If enabled linenoise will return 0 length strings if the user presses enter with out typing
a command, if disabled NULL will be returned instead.
endmenu

View file

@ -116,6 +116,7 @@
#include <sys/fcntl.h>
#include <unistd.h>
#include "linenoise.h"
#include "sdkconfig.h"
#define LINENOISE_DEFAULT_HISTORY_MAX_LEN 100
#define LINENOISE_MAX_LINE 4096
@ -979,11 +980,14 @@ char *linenoise(const char *prompt) {
} else {
count = linenoiseDumb(buf, LINENOISE_MAX_LINE, prompt);
}
#ifdef CONFIG_ESP_LINENOISE_RETURN_ZERO_STRING
if (count >= 0) {
#else
if (count > 0) {
#endif
sanitize(buf);
count = strlen(buf);
}
if (count < 0) {
} else {
free(buf);
return NULL;
}