I'm writing a typing game with ncurses in C++, and I noticed there are cbreak() and halfdelay() functions to switch modes for text input in ncurses.
I know cbreak() is used to disable line buffering when reading characters, and the difference between cbreak() and halfdelay() is halfdelay() take a parameter to blocking for X tenths.
And I was curious what if I use cbreak() with timeout(), does it works like halfdelay() ?
I made an experiment to see their difference:
Use halfdelay():
#include <ncurses.h>
int main()
{
initscr();
halfdelay(10); // blocking for 1s
getch();
endwin();
}
Use cbreak() and timeout():
#include <ncurses.h>
int main()
{
initscr();
cbreak();
timeout(1000); // blocking for 1s
getch();
endwin();
}
I found both of behavior are waiting for a char and exit the programs immediately until exceed 1s, so I would like to ask if they have difference in ncurses?