【发布时间】:2013-07-11 18:13:48
【问题描述】:
我正在为我的应用程序使用 Linux 和 ncurses,并且我正在使用 getch 作为使用 nodelay 的非阻塞。问题是,在使用 getch 循环输入时,它总是会错过第一个字符。例如,输入“Helloworld”将打印为“elloworld”。 目前我似乎没有发现任何问题,但可能是因为我已经盯着代码很久了,或者我错过了一些东西。
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);
}
【问题讨论】:
标签: c linux nonblocking ncurses getch