c - 为什么在这种情况下会显示 printw?

标签 c ncurses

为什么在这种情况下,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 and wrefresh routines (or wnoutrefresh and doupdate) must be called to get actual output to the terminal, as other routines merely manipulate data structures. The routine wrefresh copies the named window to the physical screen, taking into account what is already there to do optimizations. The refresh routine is the same, using stdscr as the default window. Unless leaveok 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/

相关文章:

c - C 中的 sin v/s sinf 函数

python - 如何在 Python 的 curses 中获得更多颜色?

c - 是否可以从终端应用程序更改鼠标图标?

emacs - 使用文本用户界面的 IDE(如 ncurses)

python - 在 Raspi 上使用带有 Python 的 C 库

c - Socket 服务器关闭命令的连接

c - 这是对 strcpy() 功能的误解吗?

c - 修复 "undefined reference to"ft. makefile.txt 和 pthreads

c++ - 屏幕上字符的 "Width"

haskell - 如何对 NCurses getEvent 执行条件操作