diff --git a/components/console/esp_console_repl.c b/components/console/esp_console_repl.c index 123572d..e971371 100644 --- a/components/console/esp_console_repl.c +++ b/components/console/esp_console_repl.c @@ -516,7 +516,7 @@ static void esp_console_repl_task(void *args) linenoiseSetMaxLineLen(repl_com->max_cmdline_length); while (repl_com->state == CONSOLE_REPL_STATE_START) { - char *line = linenoise(repl_com->prompt); + char *line = linenoise(repl_com->prompt, NULL); if (line == NULL) { ESP_LOGD(TAG, "empty line"); /* Ignore empty lines */ diff --git a/components/console/linenoise/linenoise.c b/components/console/linenoise/linenoise.c index d57bddd..90db2a7 100644 --- a/components/console/linenoise/linenoise.c +++ b/components/console/linenoise/linenoise.c @@ -1198,21 +1198,18 @@ void linenoiseEditStop(struct linenoiseState *l) { * In many applications that are not event-drivern, we can just call * the blocking linenoise API, wait for the user to complete the editing * and return the buffer. */ -static char *linenoiseBlockingEdit(char *buf, const char *prompt) +static char *linenoiseBlockingEdit(struct linenoiseState *l) { - struct linenoiseState l; /* Editing without a buffer is invalid. */ - if (buf == NULL) { + if (l->buf == NULL) { errno = EINVAL; return NULL; } char *res; - l.buf = buf; - l.buflen = max_cmdline_length; - l.prompt = prompt; - linenoiseEditStart(&l); - while((res = linenoiseEditFeed(&l)) == linenoiseEditMore); - linenoiseEditStop(&l); + l->buflen = max_cmdline_length; + linenoiseEditStart(l); + while((res = linenoiseEditFeed(l)) == linenoiseEditMore); + linenoiseEditStop(l); return res; } @@ -1265,9 +1262,14 @@ int linenoiseProbe() { } /* The high level function that is the main API of the linenoise library. */ -char *linenoise(const char *prompt) { +// passing ls_to_pass is optional, you can just provide NULL +char *linenoise(const char *prompt, struct linenoiseState **ls_to_pass) { + struct linenoiseState l; + if (ls_to_pass != NULL) *ls_to_pass = &l; char *buf = calloc(1, max_cmdline_length); - char *retval = linenoiseBlockingEdit(buf, prompt); + l.prompt = prompt; + l.buf = buf; + char *retval = linenoiseBlockingEdit(&l); free(buf); return retval; } diff --git a/components/console/linenoise/linenoise.h b/components/console/linenoise/linenoise.h index 0b99d16..ac915c3 100644 --- a/components/console/linenoise/linenoise.h +++ b/components/console/linenoise/linenoise.h @@ -87,7 +87,7 @@ void linenoiseHide(struct linenoiseState *l); void linenoiseShow(struct linenoiseState *l); /* Blocking API. */ -char *linenoise(const char *prompt); +char *linenoise(const char *prompt, struct linenoiseState **ls_to_pass); void linenoiseFree(void *ptr); /* Completion API. */