forked from test34/can_wizard
Changed some API
This commit is contained in:
parent
1efb4699d4
commit
ba2c37c9c8
3 changed files with 15 additions and 13 deletions
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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. */
|
||||
|
|
Loading…
Reference in a new issue