Reputation:
#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
Reputation: 54525
curses has a function for this:
nl/nonl
Thenl
andnonl
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 theICANON
flag is set; it is the <carriage-return> character. WhenICANON
andICRNL
are set andIGNCR
is not set, this character shall be translated into anNL
, and shall have the same effect as anNL
character. It cannot be changed.
Upvotes: 1