mirror of
https://github.com/espressif/esp-idf.git
synced 2026-05-04 20:05:25 +02:00
console: make empty line behavior run-time configurable
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
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
|
||||
@@ -116,7 +116,6 @@
|
||||
#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
|
||||
@@ -130,6 +129,7 @@ static int dumbmode = 0; /* Dumb mode where line editing is disabled. Off by def
|
||||
static int history_max_len = LINENOISE_DEFAULT_HISTORY_MAX_LEN;
|
||||
static int history_len = 0;
|
||||
static char **history = NULL;
|
||||
static bool allow_empty = true;
|
||||
|
||||
/* The linenoiseState structure represents the state during line editing.
|
||||
* We pass this state to functions implementing specific editing
|
||||
@@ -888,6 +888,10 @@ static int linenoiseEdit(char *buf, size_t buflen, const char *prompt)
|
||||
return l.len;
|
||||
}
|
||||
|
||||
void linenoiseAllowEmpty(bool val) {
|
||||
allow_empty = val;
|
||||
}
|
||||
|
||||
int linenoiseProbe(void) {
|
||||
/* Switch to non-blocking mode */
|
||||
int flags = fcntl(STDIN_FILENO, F_GETFL);
|
||||
@@ -980,13 +984,11 @@ 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);
|
||||
} else if (count == 0 && allow_empty) {
|
||||
/* will return an empty (0-length) string */
|
||||
} else {
|
||||
free(buf);
|
||||
return NULL;
|
||||
|
||||
@@ -43,6 +43,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct linenoiseCompletions {
|
||||
size_t len;
|
||||
char **cvec;
|
||||
@@ -68,6 +70,7 @@ void linenoiseClearScreen(void);
|
||||
void linenoiseSetMultiLine(int ml);
|
||||
void linenoiseSetDumbMode(int set);
|
||||
void linenoisePrintKeyCodes(void);
|
||||
void linenoiseAllowEmpty(bool);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user