bug-ncurses
[Top][All Lists]
Advanced

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

RE: unget_wch() seems to fail for non-print keys on Linux systems


From: pjfarley3
Subject: RE: unget_wch() seems to fail for non-print keys on Linux systems
Date: Sun, 16 May 2021 14:34:23 -0400

> -----Original Message-----
> From: Bug-ncurses <bug-ncurses-bounces+pjfarley3=earthlink.net@gnu.org> On
> Behalf Of pjfarley3@earthlink.net
> Sent: Saturday, May 15, 2021 8:52 PM
> To: bug-ncurses@gnu.org
> Subject: RE: unget_wch() seems to fail for non-print keys on Linux systems
<Snipped> 
> Then if I understand correctly, if get_wch() returns KEY_CODE_YES (or in
the
> python version, if the return value is of type integer rather than type
> string) then I should be able to use ungetch() with the integer value
returned
> from get_wch() to put the key code back for the next get_wch() to
retrieve, is
> that correct?

I went ahead on the assumption that my interpretation was correct and
updated my python script to use ungetch() for an integer return value from
get_wch() and it worked perfectly.

I also put together a very small C language POC (pasted below) and it too
worked as you have described.  When get_wch() returns KEY_CODE_YES then
using ungetch() with the integer value allows the next get_wch() to retrieve
the same key code value.

Thanks again for your insight and help with this issue.

Peter

C language POC below.  Compile and link on linux systems with:

gcc -o tstungetwch -DNCURSES_WIDECHAR=1 tstungetwch.c -lncursesw

Execute as ./tstungetwch

--- tstungetwch.c ----
#include <stdlib.h>
#include <string.h>
#include <curses.h>

int main( const int argc, const char *argv[]) {
    char text[80];
    wint_t wch;
    int rc = 0;

    initscr();
    cbreak( );
    noecho( );
    clear( );
    raw( );
    keypad( stdscr, 1);
    mvaddstr( 0, 2, "Hit any non-print key like up-arrow or End.");
    move (1, 2);
    while (rc != KEY_CODE_YES)
    {
        rc = get_wch(&wch);
    }
    sprintf( text, "get_wch() RC=%d.", rc);
    mvaddstr( 1, 2, text);
    sprintf( text, "You entered %d (%#04x)", wch, wch);
    mvaddstr( 2, 2, text);
    mvaddstr( 3, 2, "Using ungetch() to put that back into input.");
    rc = ungetch((int)wch);
    sprintf( text, "ungetch() RC=%d.", rc);
    mvaddstr( 4, 2, text);
    mvaddstr( 5, 2, "Using get_wch() to re-get your key.");
    rc = get_wch(&wch);
    sprintf( text, "get_wch() RC=%d.", rc);
    mvaddstr( 6, 2, text);
    sprintf( text, "get_wch returned %d (%#04x)", wch, wch);
    mvaddstr( 7, 2, text);
    rc = getch();
    endwin( );
    return( 0);
}
--- tstungetwch.c  ----




reply via email to

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