bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getch() doesn't return ERR when in nocbreak and nodelay mode.


From: Thomas Dickey
Subject: Re: getch() doesn't return ERR when in nocbreak and nodelay mode.
Date: Sun, 10 Feb 2013 15:25:09 -0500
User-agent: Mutt/1.5.20 (2009-06-14)

On Sun, Feb 10, 2013 at 07:19:25PM +0100, Nils Christopher Brause wrote:
> Hi!
> 
> When ncurses is in nocbreak and nodelay mode, according to the man pages,
> getch() should return ERR when no key has been pressed. But instead it
> returns '\n' every time it is called.
> 
> Consider this very simple program:
> 
> #include <stdio.h>
> #include <ncurses.h>
> int main()
> {
>   FILE *log;
>   log = fopen("log", "w");
>   initscr();
>   noecho();
>   nocbreak();
>   nodelay(stdscr, TRUE);
>   int c;
>   while((c = getch()) != ERR) fprintf(log, "%d,", c);
>   endwin();
>   fclose(log);
>   return 0;
> }
> 
> PDCurses doesn't do this. I'm using ncurses 5.9. Is this a bug in ncurses?

Apparently (but it's been that way quite a while).  In a quick check,
I see that Solaris curses simply returns ERR immmediately and there's nothing
written to the log.

ncurses says it's in cooked mode, and recurs to call wgetnstr which
returns an error (because of the nodelay).  But it does an ungetch for
the newline whether or not there is an error.

Changing the code to only do the ungetch('\n') if there was no error
looks like the appropriate fix (will verify, etc).

-- 
Thomas E. Dickey <address@hidden>
http://invisible-island.net
ftp://invisible-island.net

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]