From c34352549ac1fda8eab9b45260dfda4d2b6488f1 Mon Sep 17 00:00:00 2001 From: Michael 'ASAP' Weinrich Date: Sun, 15 Mar 2020 21:31:48 -0700 Subject: [PATCH] Added Kconfig for enabling 0 length returns from linenoise --- components/console/Kconfig | 10 ++++++++++ components/console/linenoise/linenoise.c | 8 ++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 components/console/Kconfig diff --git a/components/console/Kconfig b/components/console/Kconfig new file mode 100644 index 0000000000..a153b490de --- /dev/null +++ b/components/console/Kconfig @@ -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 \ No newline at end of file diff --git a/components/console/linenoise/linenoise.c b/components/console/linenoise/linenoise.c index 3b2e1c18e7..0cf86fc0c2 100644 --- a/components/console/linenoise/linenoise.c +++ b/components/console/linenoise/linenoise.c @@ -116,6 +116,7 @@ #include #include #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; }