Unix Technical Forum

getch, nodelay, extended curses

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 ...


Go Back   Unix Technical Forum > Unix Operating Systems > AIX Operating System

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-05-2008, 07:32 AM
Charris
 
Posts: n/a
Default getch, nodelay, extended curses

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-05-2008, 07:34 AM
Charris
 
Posts: n/a
Default Re: getch, nodelay, extended curses

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:28 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com