bug-ncurses
[Top][All Lists]
Advanced

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

Re: halfdelay(...) not working with get_wch()


From: Bill Gray
Subject: Re: halfdelay(...) not working with get_wch()
Date: Thu, 4 Jul 2024 10:37:59 -0400
User-agent: Mozilla Thunderbird



On 7/4/24 06:53, Giorgos Xou wrote:
According to the man-page <https://linux.die.net/man/3/get_wch>,

   I'd suggest looking at

https://invisible-island.net/ncurses/man/curs_get_wch.3x.html

The linux.die.net pages for ncurses haven't been updated for... well, dunno how long (the date is omitted on those pages), but it's been a _long_ time. Unfortunately, they're usually the first hit I see if I search for a curses function.

it seems like halfdelay should work with both getch and get_wch
functions,  but this isn't the case.

Can you provide simple test code? The example below uses halfdelay(5); that should (and appears to) ensure that the spinner changes only twice a second, with either function called. (If you hit a lot of keys, it will speed up; the half-second delay applies only if there's no input.) Works on ncurses and PDCurses*.

-- Bill

I'm not using them actively together at all, but I just discovered this discrepancy by accident (and then thought I should report about it). Anyways, that's all, have a nice dayyy! 👋


#define HAVE_NCURSESW
#define NCURSES_WIDECHAR 1
#define _XOPEN_SOURCE_EXTENDED 1

/* Test program to see if halfdelay( ) functions identically for
getch( ) and get_wch( ).  Compile with

cc -Wall -Wextra -o halftest halftest.c -lncursesw         */

#include <curses.h>

int main( void)
{
   int loop = 0, pass;
   SCREEN *screen_pointer = newterm(NULL, stdout, stdin);

   halfdelay( 5);    /* delay 0.5 seconds on getch() & wgetch() */
   noecho( );
   mvprintw( 2, 0, "Spinner should change twice a second.");
   mvprintw( 3, 0, "Hit 'q' when done.");
   for( pass = 0; pass < 2; pass++)
   {
      int quit = 0;

      mvprintw( 1, 0, "Testing %s and halfdelay()",
              (pass ? "get_wch()" : "getch()"));
      while( !quit)
      {
         const char *spinner = "\\|/-";
         wint_t wch;

         mvprintw( 4, 0, "%c", spinner[loop++ & 3]);
         if( !pass && getch( ) == 'q')
            quit = 1;
         if( pass && OK == get_wch( &wch) && wch == 'q')
            quit = 1;
      }
   }
   endwin();
                       /* Not really needed,  but ensures Valgrind  */
   delscreen( screen_pointer);         /* says all memory was freed */
   return( 0);
}



reply via email to

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