为什么在这种情况下,printw
显示“Blah”?我使用 nocbreak
。所以 printw
不应该正常产生输出,因为输出是行缓冲的。
int main(int ac, char **av)
{
initscr();
nocbreak();
printw("Blah");
refresh();
while (1);
}
最佳答案
实际上,printw
不是行缓冲。 ncurses 将终端初始化为raw 模式 并根据需要模拟cooked 模式。但这仅适用于输入。对于输出,ncurses 会立即将相关更新写入屏幕,如 manual page 中所述:
The
refresh
andwrefresh
routines (orwnoutrefresh
and doupdate) must be called to get actual output to the terminal, as other routines merely manipulate data structures. The routinewrefresh
copies the named window to the physical screen, taking into account what is already there to do optimizations. Therefresh
routine is the same, usingstdscr
as the default window. Unlessleaveok
has been enabled, the physical cursor of the terminal is left at the location of the cursor for that window.
物理屏幕当然是您的终端。 ncurses 通过将其记录在 curscr
中来记住其中的内容:
This implementation of curses uses a special window
curscr
to record its updates to the terminal screen.This is referred to as the "physical screen" in the curs_refresh(3x) and curs_outopts(3x) manual pages.
从 ncurses 的角度来看,终端(您看到)和 curscr
是同一件事。
对于 printw
, 手册页说它的行为就像调用 waddstr
,然后调用 waddch
:
These functions write the (null-terminated) character string str on the given window. It is similar to calling
waddch
once for each character in the string.
关于c - 为什么在这种情况下会显示 printw?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56245960/