Let's consider that example:
#include <ncurses.h>
#include <unistd.h>
// ...
// Some functions like `contains` and `getBuff`
// ...
int main() {
initscr(); // Init curses mode
// ... Do some initialisation
int *input; // Input buffer
while(1) {
getBuff(input); // Get all characters currently available into buffer
if(contains(input, 'q')) break; // If there is 'q' in buffer - break
// ... Do something with buffer
usleep(100000); // Wait some time
}
endwin(); // Exit curses
return 0;
}
Here, in the loop the program waits some time, and after it gets all input got while it was sleeping.
The main problem is in getBuff()
— I don't know how to make it.
I've tried using halfdelay()
and while(getch() != ERR)
, but it doesn't work fine. If the user presses any key and does not release it, the program stops at the loop.
So, getBuff()
might get all input available at the time of its call, not later.