#19 Documentation on how to use newtFormWatchFd();
Opened 2 years ago by viniciusferrao. Modified 2 years ago

Hello, I'm trying to feed a newtLabel() with a data stream (FILE *) and I was unable to properly create a newtForm that will exit when the data stream ends.

Since there's little documentation I was reading the library and found newtFormWatchFd() that seems to do the job, but again, since there's no documentation we can't know for sure if the function is expected to do what we are thinking.

Is there any example or better documentation on this function specifically?

For the code block my goal of to do somethings like this:

FILE* file = popen("ls -l", "r");
char *out = NULL;
size_t outlen = 0;
while (getline(&out, &outlen, file) >= 0) {
    text = newtLabel(0, 0, out);
    newtFormAddComponents(form, text, NULL);
    newtFormWatchFd(form, (long) file, NEWT_FD_READ);
}

Thank you.


newtFormWatchFd() is useful when you need to update a form or widget while it is running. It just specifies a file descriptor (not FILE *) to be monitored by select(). When there is some data ready for reading/writing, the form will exit with NEWT_EXIT_FDREADY. You can make the update and run the form again.

Instead of adding multiple newtLabels, I'd suggest to try a textbox and set the full text with newtTextboxSetText().

Login to comment on this ticket.

Metadata