Im using Linux and ncurses for my application, and i'm using getch as non-blocking using nodelay. The problem is that while looping with getch for the input, it always misses the first character. For example the input "Helloworld" would print up as "elloworld". I dont seem to see any problems at the moment, though maybe its because i've been staring at the code for far to long, or i've missed something out.
while(TRUE)
{
gchar chr;
gchar *cmd = g_malloc(50);
if((getch()) == ERR)
{
// no user input
}
else
{
gint i = 0;
while((chr = getch()) != '\n')
{
cmd[i] = chr;
waddch(ncurse->window, chr);
wrefresh(ncurse->window);
i++;
}
waddstr(ncurse->log, cmd);
wrefresh(ncurse->log);
wmove(ncurse->window, ncurse->window->_maxy, 2);
wclrtoeol(ncurse->window);
wrefresh(ncurse->window);
}
g_free(cmd);
}
What do you expect?
if((getch()) == ERR)
{
// no user input
}
discards the first character, if there is one.