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);
|
linenoiseSetMaxLineLen(repl_com->max_cmdline_length);
|
||||||
while (repl_com->state == CONSOLE_REPL_STATE_START) {
|
while (repl_com->state == CONSOLE_REPL_STATE_START) {
|
||||||
char *line = linenoise(repl_com->prompt);
|
char *line = linenoise(repl_com->prompt, NULL);
|
||||||
if (line == NULL) {
|
if (line == NULL) {
|
||||||
ESP_LOGD(TAG, "empty line");
|
ESP_LOGD(TAG, "empty line");
|
||||||
/* Ignore empty lines */
|
/* Ignore empty lines */
|
||||||
|
|
|
@ -1198,21 +1198,18 @@ void linenoiseEditStop(struct linenoiseState *l) {
|
||||||
* In many applications that are not event-drivern, we can just call
|
* In many applications that are not event-drivern, we can just call
|
||||||
* the blocking linenoise API, wait for the user to complete the editing
|
* the blocking linenoise API, wait for the user to complete the editing
|
||||||
* and return the buffer. */
|
* 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. */
|
/* Editing without a buffer is invalid. */
|
||||||
if (buf == NULL) {
|
if (l->buf == NULL) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
char *res;
|
char *res;
|
||||||
l.buf = buf;
|
l->buflen = max_cmdline_length;
|
||||||
l.buflen = max_cmdline_length;
|
linenoiseEditStart(l);
|
||||||
l.prompt = prompt;
|
while((res = linenoiseEditFeed(l)) == linenoiseEditMore);
|
||||||
linenoiseEditStart(&l);
|
linenoiseEditStop(l);
|
||||||
while((res = linenoiseEditFeed(&l)) == linenoiseEditMore);
|
|
||||||
linenoiseEditStop(&l);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1265,9 +1262,14 @@ int linenoiseProbe() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The high level function that is the main API of the linenoise library. */
|
/* 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 *buf = calloc(1, max_cmdline_length);
|
||||||
char *retval = linenoiseBlockingEdit(buf, prompt);
|
l.prompt = prompt;
|
||||||
|
l.buf = buf;
|
||||||
|
char *retval = linenoiseBlockingEdit(&l);
|
||||||
free(buf);
|
free(buf);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ void linenoiseHide(struct linenoiseState *l);
|
||||||
void linenoiseShow(struct linenoiseState *l);
|
void linenoiseShow(struct linenoiseState *l);
|
||||||
|
|
||||||
/* Blocking API. */
|
/* Blocking API. */
|
||||||
char *linenoise(const char *prompt);
|
char *linenoise(const char *prompt, struct linenoiseState **ls_to_pass);
|
||||||
void linenoiseFree(void *ptr);
|
void linenoiseFree(void *ptr);
|
||||||
|
|
||||||
/* Completion API. */
|
/* Completion API. */
|
||||||
|
|
Loading…
Reference in a new issue