This is a discussion on getch, nodelay, extended curses within the AIX Operating System forums, part of the Unix Operating Systems category; --> Hello AIX crew, Having some strange behavior with extended curses (-lcur) I can't seem to resolve. Recently we started ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hello AIX crew, Having some strange behavior with extended curses (-lcur) I can't seem to resolve. Recently we started using nodelay(stdscr, ) in conjuction with getch(). We've had no problems with getch till this point with the BACKSPACE key (code 263 with libcur), but when we use nodelay(), the backspace key returns intermittently, sometimes returning 263, other times just sitting with a -2 (no key pressed) code. I've compiled some tests, 1. I compiled with gnu ncurses, works perfectly. 2. Compiled a test with standard curses libcurses, it returns 0x8 consistently with no problems. Even the following code by Floyd Davidson does not always catch the backspace key all the time: int kbhit(void) { int cnt = 0; int error; static struct termios Otty, Ntty; tcgetattr(0, &Otty); Ntty = Otty; Ntty.c_iflag = 0; /* input mode */ Ntty.c_oflag = 0; /* output mode */ Ntty.c_lflag &= ~ICANON; /* line mode */ Ntty.c_cc[VMIN] = CMIN; /* minimum time to wait */ Ntty.c_cc[VTIME] = CTIME; /* minimum characters to wait for */ if (0 == (error = tcsetattr(0, TCSANOW, &Ntty))) { struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 100; select(1, NULL, NULL, NULL, &tv); /* a small time delay */ struct timeval tv; error += ioctl(0, FIONREAD, &cnt); error += tcsetattr(0, TCSANOW, &Otty); } return (error == 0 ? cnt : -1 ); } Anyone have any ideas? TIA greatly charris |
| ||||
| Found my solution. Basically this version/set of curses (libcur.a using cur00.h-cur05.h) was not taking the terminal out of 'cooked mode', a mode that does some special processing on the erase key (namely backspace I presume). It looks like ncurses does this by default possibly or when setting nodelay, but this is not the default behavior for AIX libcur.a, eventhough odly enough, AIX's sister, libcurses.a, does. Anyway, most of the curses libraries do this by using cbreak(). However, even more conveniently, libcur.a does not support cbreak, you will get a segfault for even trying, which upon further digging I found crmode(); Hope this helps |