Re: Bugs when porting ncurses to a new platform

"G. Branden Robinson" <[email protected]> Sat, 4 Jul 2026 17:30:36 -0500
Newsgroups gmane.comp.lib.ncurses.bugs
Message-ID <20260704223036.qh6365c6gtqnftav@illithid>
--bcmgqvtnqzqfoxcd
Content-Type: text/plain; protected-headers=v1; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Subject: Re: Bugs when porting ncurses to a new platform
MIME-Version: 1.0

Hi Antonio,

At 2026-07-04T22:04:38+0000, Antonio Ni=C3=B1o D=C3=ADaz wrote:
> I've done a few more tests. If I assign single characters to
> ku/kd/kr/kl, like "ku=3DA", it works as expected (when I press A I get a
> KEY_UP event). It's just multi-character strings that fail. However, I
> have noticed that if I make it "ku=3DAA" it will hang slightly after I
> press the first A (and then I just receive an A key press event
> instead of KEY_UP because it hasn't seen a second A). So I think that
> there may be some issue with some wait loop in ncurses...

Your example established that you're using keypad mode.  Have you read
the getch(3) man page?  What you are observing sounds exactly like what
is documented there.

   Keypad Mode
     Call keypad(3NCURSES) on a window to configure keypad mode when
     reading input from it.  In keypad mode, curses treats key strokes
     not from the alphabetic section of the keyboard (those
     corresponding to the ECMA=E2=80=906 character set =E2=80=94=E2=80=94 s=
ee ascii(7) =E2=80=94=E2=80=94
     optionally modified by either the control or shift keys) as
     function keys.  (In curses, the term =E2=80=9Cfunction key=E2=80=9D in=
cludes but is
     not limited to keycaps engraved with =E2=80=9CF1=E2=80=9D, =E2=80=9CPF=
1=E2=80=9D, and so on.)  If a
     window is in keypad mode, wgetch translates these key strokes to a
     numeric code corresponding to the KEY_ symbols listed in subsection
     =E2=80=9CKey Codes=E2=80=9D below.  If the window is not in keypad mod=
e, the input
     queue populates with the characters of the function key=E2=80=99s esca=
pe
     sequence, which the application must collect individually with
     multiple wgetch calls.

     =E2=80=A2   The curses.h header file declares many function keys whose
         names begin with KEY_; these object=E2=80=90like macros have integ=
er
         values outside the range of eight=E2=80=90bit character codes.

     =E2=80=A2   In ncurses, user=E2=80=90defined function keys are configu=
red with
         define_key(3NCURSES); they have no names, but are also expected
         to have integer values outside the range of eight=E2=80=90bit char=
acter
         codes.

     A variable intended to hold a function key code must thus be of
     type short or larger.

     Most terminals one encounters follow the ECMA=E2=80=9048 standard inso=
far
     as their function keys produce character sequences prefixed with
     the escape character ESC.  This fact implies that curses cannot
     distinguish a user=E2=80=99s press of the escape key (assuming it sends
     ESC) from the beginning of a function key=E2=80=99s character sequence
     without waiting to see if, and how soon, further input arrives.

     =E2=80=A2   If the escape sequence matches a string capability definin=
g a
         function key for the terminal type (such as key_home (khome) or
         key_up (kuu1)), wgetch returns the function key code
         corresponding to the unique sequence defined by the terminal.

     =E2=80=A2   If the escape sequence matches no function keys defined fo=
r the
         terminal type, call wgetch repeatedly to obtain the codes of
         the individual characters of the sequence, in the order they
         occurred in the input.

     =E2=80=A2   If wgetch cannot decide the validity of the input as a fun=
ction
         key because it has not read enough characters to disambiguate
         it, the function waits until it has this information or the
         escape delay elapses.  Configure the escape delay with the
         global variable ESCDELAY, an extension (see section
         =E2=80=9CEXTENSIONS=E2=80=9D below), or the environment variable o=
f the same
         name (see section =E2=80=9CENVIRONMENT=E2=80=9D of ncurses(3NCURSE=
S)), also an
         extension.

     Consequently, a user of a curses application that employs keypad
     mode may experience a pause or =E2=80=9Chang=E2=80=9D after pressing t=
he escape key
     while curses collects sufficient characters to disambiguate the
     input.  If the window is in =E2=80=9Cno time=E2=80=90out=E2=80=9D mode=
, the escape delay is
     effectively infinite; see notimeout(3NCURSES).  In the event of
     such a pause, further typing =E2=80=9Cawakens=E2=80=9D curses.

Regards,
Branden

--bcmgqvtnqzqfoxcd
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEh3PWHWjjDgcrENwa0Z6cfXEmbc4FAmpJiYUACgkQ0Z6cfXEm
bc57zw/+Lm6H9QTFFXMZfE/UoEevEjTYW24jNHBGowYHa3DiPTh9sk9AIh5gQtmC
Bm9bMkx1p4DM/XC0UDMhQ+WR9Ubuc+5kQcRqVUsvjwQkVzRdlJqN6rN+97R09pQE
iSkrZu+YeHe+1tFyRJx661+mEjZezh756OlsYOCti9lXPxgSfqTaUk8Pkjg5aB/K
Mg44w9oaCgxbkjFqyznkw+QSRHlAehEs/eT3yPwliq5l7aQSsme5R/joWx5bWoA3
+VP6vWkPSqqihye/veDMKeGvaO8+fh8ECbmRJRMxRAReEx4RsGnXnVoyHcUMKEm8
sy8I9PwaJrpuROKd4Cgrv1ECAsJTmGuY3mJ7as56YnJJqbJcWNaiXmWe1PO2KIq6
xRnJTS3NVegBzKuM+1SMIHpMPCYkxIasu1PMy5ZNqPwEPol9I/cwmqCi8EcSXHcH
YZKtQwL/z50shZdOGB2ZBp2bT4T8c4pBRPNptDGSe1RgP3BL9tjV6h3XfIVM7UyB
311zI8AbywRSGX1lYiOmZs78AV4D9NLl6E18VV6vFcsFnuXlOEFDx9rvofyUgvk7
W8zvg/xov7/3ZBthxpWPn1QtgkBanAYNhNaWIGMAOfAat0wA/+x6p/AdNF7qStCu
XC5V57dhYhxBctVFBMNyaV4AQvtZR9e8AbseQeOU1lyIrwB6J/Y=
=vj0Z
-----END PGP SIGNATURE-----

--bcmgqvtnqzqfoxcd--