bug-ncurses
[Top][All Lists]
Advanced

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

Re: Ncurses keypad is not properly working in FreeBSD


From: Thomas Dickey
Subject: Re: Ncurses keypad is not properly working in FreeBSD
Date: Tue, 24 Jan 2023 03:59:37 -0500
User-agent: Mutt/1.10.1 (2018-07-13)

On Tue, Jan 24, 2023 at 12:09:08PM +0800, Archimedes Gaviola wrote:
>  Hi,
> 
> I have a C program that accepts and displays numeric characters in 0-9 only
> and with alphabet keys, function keys are expected not to respond to any
> code from the keyboard using keypad(). I simulated a plain Ncurses C
> program without a window and another one with a window using the newwin()
> function. The program without window works getting no response from
> alphabet keys as well as function keys, however the Enter/return key (ch ==
> KEY_ENTER) is not working instead I use (ch == '\n') to get it to work. The

The usual point of confusion for KEY_ENTER is that terminal descriptions
use the escape sequence from the numeric-keypad (active when keypad() is
called), rather than the "Enter" key on the main keyboard.

The numeric keypad in xterm (like vt100, etc), sends escape sequences
when keypad-mode is enabled.  xterm changes those to the "face codes",
e.g., 0, 1, 2, etc., when NumLock is pressed.  Those escape sequences
are documented in the xterm control sequences.

Some other terminals (for which of course no documentation exists)
use different escape sequences (determined by the X keyboard configuration),
e.g., cursor-keys, page up/down, etc.

CDK doesn't know about any of those escape sequences.  If your terminfo
database is reasonably up-to-date, it'll have extended definitions which
allow ncurses to return just keycodes rather than the bytes of the escape
sequence, e.g.,  (using infocmp -x xterm):

        ka2=\EOx, kb1=\EOt, kb3=\EOv, kc2=\EOr,
        kp5=\EOE, kpADD=\EOk, kpCMA=\EOl, kpDIV=\EOo, kpDOT=\EOn,
        kpMUL=\EOj, kpSUB=\EOm, kpZRO=\EOp,

which come from this block in the terminfo.src:

https://invisible-island.net/ncurses/terminfo.src.html#tic-xterm_keypad

xterm+keypad|xterm emulating VT100/VT220 numeric keypad,
        kbeg=\EOE, kp5=\EOE, kpADD=\EOk, kpCMA=\EOl, kpDIV=\EOo,
        kpDOT=\EOn, kpMUL=\EOj, kpSUB=\EOm, kpZRO=\EOp,
        use=vt220+keypad,

If you're using the default ncurses on FreeBSD rather than the port,
you'll get something that corresponds more/less to their termcap,
which is rather inaccurate...

> backspace key (ch == KEY_BACKSPACE) is working. For the program with the
> window, I expect it to behave similar to the plain program but the function
> keys such F5 to F12 are showing codes on the screen as well as Insert,
> Delete, Page Up and Page Down keys are also showing codes. Only F1, F2, F3

Insert/Delete, Page Up and Page Down are (on PC keyboards...) in the "editing
keypad", for which some terminals don't agree with the $TERM that the
developers chose.

There's no details on this report, so we can only guess.

> and F4 are behaving expectedly. The same thing happens to the Enter/return
> and backspace keys I use (ch == '\n') and  (ch == '\b') to get them working.
> 
> I need your help in this case if there's something I missed in the Ncurses
> initialization parameters or maybe a sort of environment variable
> configuration problem with my FreeBSD OS. My FreeBSD system is using xterm.
> 
> pangi@siquijor:~ # echo $TERM
> xterm
> 
> FreeBSD version: FreeBSD 14.0-CURRENT (arm64)
> 
> Ncurses version:
> #define NCURSES_VERSION_MAJOR 6
> #define NCURSES_VERSION_MINOR 2
> #define NCURSES_VERSION_PATCH 20210220

this looks like the base/bundled version, which isn't something that I can fix.
For problems with that, FreeBSD has its own bug-reporting system.

At the moment, the port is up to 6.3, which would have a patch 20211021

https://cgit.freebsd.org/ports/tree/devel/ncurses/
 
> 1. Plain C program (without window)
> 
> #include <ncurses.h>
> 
> int main(void)
> {
>         initscr();
>         keypad(stdscr, TRUE);
>         noecho();
> 
>         int i;
> 
>         for (i=1; i<=14; i++)
>         {
>                 int ch = getch();
>                 if ((ch == '1') || (ch == '2') || (ch == '3') \
>                      || (ch == '4') || (ch == '5') || (ch == '6') \
>                      || (ch == '7') || (ch == '8') || (ch == '9') \
>                      || (ch == '0'))
>                 {
>                         addch(ch);
>                         refresh();
>                 } else {
>                         --i;
>                 }
> 
>                 //if (ch == KEY_ENTER) (not working)
>                 if (ch == '\n')
>                 {
>                         printw("Return key is pressed.\n");
>                 }
> 
>                 if (ch == KEY_BACKSPACE)
>                 {
>                         printw("Backspace key is pressed.\n");
>                 }
> 
>         }
>         endwin();
>         return 0;
> }
> 
> 2. Plain C derived program (with window)
> 
> #include <ncurses.h>
> 
> int main(void)
> {
>         WINDOW *alpha;
> 
>         initscr();
>         //keypad(stdscr, TRUE); (the same outcome with keypad(alpha, TRUE)
> below)
>         keypad(alpha, TRUE);
>         noecho();
>         start_color();
>         init_pair(1,COLOR_WHITE,COLOR_BLUE);
> 
>         alpha = newwin(0,0,0,0);
>         if( alpha == NULL)
>         {
>                 endwin();
>                 puts("Problem creating window");
>                 return(1);
>         }
> 
>         wbkgd(alpha,COLOR_PAIR(1));
>         wrefresh(alpha);
> 
>         int i;
> 
>         for (i=1; i<=14; i++)
>         {
>                 int ch = wgetch(alpha);
>                 if ((ch == '1') || (ch == '2') || (ch == '3') \
>                      || (ch == '4') || (ch == '5') || (ch == '6') \
>                      || (ch == '7') || (ch == '8') || (ch == '9') \
>                      || (ch == '0'))
>                 {
>                         waddch(alpha,ch);
>                         wrefresh(alpha);
>                 } else {
>                         --i;
>                 }
> 
>                 //if (ch == KEY_ENTER) (not working)
>                 if (ch == '\n')
>                 {
>                         wprintw(alpha,"Return key is pressed.\n");
>                 }
> 
>                 //if (ch == KEY_BACKSPACE) (not working)
>                 if (ch == '\b')
>                 {
>                         wprintw(alpha,"Backspace key is pressed.\n");
>                 }
> 
>         }
>         endwin();
>         return 0;
> }
> 
> Thanks and best regards,
> Archimedes

-- 
Thomas E. Dickey <dickey@invisible-island.net>
https://invisible-island.net

Attachment: signature.asc
Description: PGP signature


reply via email to

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