user14800938
user14800938

Reputation:

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;
}

Ok, sorry for bad formatting but that is the code. It's work fine, the terminal catch any character I press but when I press ENTER i can't get a newline. Why?

Thanks

Upvotes: 0

Views: 1257

Answers (1)

Thomas Dickey
Thomas Dickey

Reputation: 54525

curses has a function for this:

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

The source-code comment mentions ICRNL:

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

which is a POSIX termios feature:

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.

Upvotes: 1

Related Questions