Skip to content

Commit 93b2db9

Browse files
committed
Multiplexing: documentation improved.
1 parent 3476ccc commit 93b2db9

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

README.markdown

+21-5
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,32 @@ The function returns a `char` pointer: if the user didn't yet press enter
272272
to provide a line to the program, it will return `linenoiseEditMore`, that
273273
means we need to call `linenoiseEditFeed()` again when more data is
274274
available. If the function returns non NULL, then this is a heap allocated
275-
data (to be freed with `linenoiseFree()`) representing the user input, and
276-
we can read the next line again with `linenoiseEditFeed(&ls)` calls.
275+
data (to be freed with `linenoiseFree()`) representing the user input.
277276
When the function returns NULL, than the user pressed CTRL-C or CTRL-D
278277
with an empty line, to quit the program, or there was some I/O error.
279278

280-
Finally, before exiting the program, we need to exit raw mode and do other
281-
clenaup. So we call:
279+
After each line is received (or if you want to quit the program, and exit raw mode), the following function needs to be called:
282280

283281
linenoiseEditStop(&ls);
284282

283+
To start reading the next line, a new linenoiseEditStart() must
284+
be called, in order to reset the state, and so forth, so a typical event
285+
handler called when the standard input is readable, will work similarly
286+
to the example below:
287+
288+
``` c
289+
void stdinHasSomeData(void) {
290+
char *line = linenoiseEditFeed(&LineNoiseState);
291+
if (line == linenoiseEditMore) return;
292+
linenoiseEditStop(&LineNoiseState);
293+
if (line == NULL) exit(0);
294+
295+
printf("line: %s\n", line);
296+
linenoiseFree(line);
297+
linenoiseEditStart(&LineNoiseState,-1,-1,LineNoiseBuffer,sizeof(LineNoiseBuffer),"serial> ");
298+
}
299+
```
300+
285301
Now that we have a way to avoid blocking in the user input, we can use
286302
two calls to hide/show the edited line, so that it is possible to also
287303
show some input that we received (from socekts, bluetooth, whatever) on
@@ -291,7 +307,7 @@ screen:
291307
printf("some data...\n");
292308
linenoiseShow(&ls);
293309
294-
To show all this, the linenoise example C file implements a multiplexing
310+
To the API calls, the linenoise example C file implements a multiplexing
295311
example using select(2) and the asynchronous API:
296312
297313
```c

0 commit comments

Comments
 (0)