在 C++ 中使用 ncurses 换行

New line with ncurses in c++

#include <ncurses.h>

int main(int argc, char ** argv)
{
    initscr();
    while(1){
        int c = getch();
        if(c == 'q'){
            break;
        }
    }
    return 0;
}

好的,很抱歉格式不正确,但这就是代码。 它工作正常,终端捕获我按的任何字符但是当我按 ENTER 时我无法换行。 为什么?

谢谢

curses 有一个功能:

nl/nonl
The nl and nonl routines control whether the underlying display device translates the return key into newline on input.

source-code comment提到ICRNL:

/*
 * Simulate ICRNL mode
 */
if ((ch == '\r') && sp->_nl)
    ch = '\n';

这是一个 POSIX termios 特征:

CR
Special character on input, which is recognized if the ICANON flag is set; it is the <carriage-return> character. When ICANON and ICRNL are set and IGNCR is not set, this character shall be translated into an NL, and shall have the same effect as an NL character. It cannot be changed.