bug-ncurses
[Top][All Lists]
Advanced

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

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


From: pjfarley3
Subject: unget_wch() seems to fail for non-print keys on Linux systems
Date: Fri, 14 May 2021 01:24:54 -0400

Hello,

I work in python using curses libraries in both linux environments and in
Windows environments but I don't yet know whether this is a python issue or
an ncurses issue in linux environments, so I am asking here for your help
and advice.

I am hoping you can help me narrow down where this bug may be happening by
telling me if the behavior I see with python is normal for ncurses on linux
or not.

I have attached a fairly simple python script that uses ncurses on linux
systems and PDCurses on Windows systems.  On Windows systems this code
*always* operates correctly.  On Linux systems (tested on Ubuntu 20.04 LTS
and Debian 10) using recent ncurses versions (6.2 on Ubuntu, 6.1 on Debian)
using the python syntax "stdscr.unget_wch(keyvalue)" where "keyvalue" is not
a printable character (e.g., End, Home, arrow keys, function keys etc.) it
seems to fail to correctly put the entire keycode back into the input buffer
such that a subsequent "stdscr.getkey()" fails to either retrieve the actual
keycode value or to translate it correctly to a "KEY_*" name.

Operating the example program "pycurses4.py":

1. If it isn't already installed in your linux system, install whichever
python3 version your distro supports.  On Ubuntu this is currently 3.8.5, on
Debian 3.7.3.
2. In a terminal window, run the command "python3 pycurses4.py"
3. When the program presents you with its screen, type the letters "a", "b"
and "c to observe what they do to the screen contents
4. Next press the up, down, left, right arrow keys and observe the
difference:
        a. The "get_wch()" and "getkey()" results (on screen, the "Last wide
character pressed:" and "Last 'key' value pressed:" lines, respectively)
will be correct values for both the letter and arrow keys
        b. The "getkey()" results will be incorrect for the arrow keys
because the "unget_wch()" following the "get_wch()" for the arrow keycodes
fails to allow "getkey()" to retrieve the same key value or perhaps fails to
allow it to translate the retrieved value to the correct keycode name
5. Quit the program by typing the "q" key (only lower case "q" quits the
program).

To prove that the code does perform "getkey()" correctly, run the program
again with "python3 pycurses4.py ck" which will run only the "getch()" and
"getkey()" parts of the program.  When the "get_wch()" part is not executed,
only "ungetch()" puts the received keycode back into the input buffer, and
"getkey()" is then able to retrieve and return the name of that that keycode
correctly.

If someone on this list would be kind enough to run this example code on
their own linux system to see the issue I am reporting, and then tell me
whether I should be looking to the python development team for a solution or
if this is possibly a bug in the underlying ncurses code, I would very much
appreciate it.

Regards,

Peter
--

Attachment: pycurses4.py
Description: Text Data


reply via email to

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