@@ -272,16 +272,32 @@ The function returns a `char` pointer: if the user didn't yet press enter
272
272
to provide a line to the program, it will return ` linenoiseEditMore ` , that
273
273
means we need to call ` linenoiseEditFeed() ` again when more data is
274
274
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.
277
276
When the function returns NULL, than the user pressed CTRL-C or CTRL-D
278
277
with an empty line, to quit the program, or there was some I/O error.
279
278
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:
282
280
283
281
linenoiseEditStop(&ls);
284
282
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
+
285
301
Now that we have a way to avoid blocking in the user input, we can use
286
302
two calls to hide/show the edited line, so that it is possible to also
287
303
show some input that we received (from socekts, bluetooth, whatever) on
@@ -291,7 +307,7 @@ screen:
291
307
printf("some data...\n");
292
308
linenoiseShow(&ls);
293
309
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
295
311
example using select(2) and the asynchronous API:
296
312
297
313
```c
0 commit comments