I'm trying to create a typewriter effect for a console app and I'm having some trouble with a part of it. I can get the text to display one letter at a time, but I'm having trouble ending the loop if a keypress is found and print the rest of the text. I started with a for loop then went to a while to try "while((ch = getch()) < 0) &&....)" but it just waits for input. I have the main function in raw() "mode" and I figured that would make it not wait for input, but I'm pretty new to ncurses and I'm stuck on where to go. Any help would be very appreciated.
void twtext(char text[]) {
int twdelay = 35;
if (strlen(text) >= 25)
twdelay = 10;
else
twdelay = 35;
int cb;
int i = 0;
//Just waits at input. Without the first part it displays the text fine.
while (((cb = getch()) < 0) && (i < strlen(text))) {
if (cb > 0) { //If keypressed (attempt)
twdelay = 0;
}
printw("%c", text[i]);
refresh();
msleep(twdelay);
i++;
}
printw("\n");
refresh();
}
Perhaps nodelay is what you're looking for. You can find information on the specific behavior that this applies to Input Processing under the Delay Mode section here.