0

I'm testing an ncurses program that was running under ncurses5 but recently compiled under curses6 in a new environment (putty/xterm/virtualbox) and can't get it to recognize any function keys. The arrow keys work fine but only those that use an escape sequence appear to fail.

chtype c;
initscr();
start_color();
noecho();
cbreak();
intrflush(stdscr, TRUE);
keypad(stdscr, TRUE);
c=getch();
printf("c=%d\n", (int)c);

Pressing F1 returns "c=27". I'm using putty and tried various settings with TERM set to xterm. Outside of curses, F1 returns \EOP as expected, and I'm using TERM=xterm which appears to define the function key properly in termcap. I understand the keypad() routine is suppose to cause the getch/wgetch routines to return the numeric key equivalent of 265 KEY_F(1), but I can't get anything but 27 with various combos of break, raw, notimeout, etc.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
AJJ
  • 143
  • 11

3 Answers3

2

Both putty and xterm have several options for their function-keys. The default configurations for each differ, which you can see using

infocmp putty xterm

and it seems that kf1 (F1) is one of many differences, e.g., (putty on the left, xterm on the right):

    kent: NULL, '\EOM'.
    kf1: '\E[11~', '\EOP'.
    kf13: '\E[25~', '\E[1;2P'.
    kf14: '\E[26~', '\E[1;2Q'.
    kf15: '\E[28~', '\E[1;2R'.
    kf16: '\E[29~', '\E[1;2S'.
    kf17: '\E[31~', '\E[15;2~'.
    kf18: '\E[32~', '\E[17;2~'.
    kf19: '\E[33~', '\E[18;2~'.
    kf2: '\E[12~', '\EOQ'.
    kf20: '\E[34~', '\E[19;2~'.
    kf21: NULL, '\E[20;2~'.
    kf22: NULL, '\E[21;2~'.
    kf23: NULL, '\E[23;2~'.
    kf24: NULL, '\E[24;2~'.

(Some copies of ncurses' terminal database are minimal, but there's a full database which includes the putty description).

If the terminal database doesn't show the key as you're configured, ncurses will not recognize it, and you will see the escape character.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • Yes, I checked out the xterm settings and verified that my function keys are returning the correct escape sequence. The TERM is set to xterm in putty as well. The problem is that ncurses is still reading only the first char (ESC) even though I use the keypad() routine which is suppose to tell the wgetchar() to return a numeric value of 265 instead of the actual escape sequence, but its not. – AJJ Nov 27 '17 at 19:09
  • It's probably not a bug in ncurses, but S/O isn't well suited to dialog. Try [bug-ncurses](https://invisible-island.net/ncurses/ncurses.faq.html#how_to_report). – Thomas Dickey Nov 28 '17 at 00:10
0

Doh! I finally found there was an alias "alias cmd='TERM=Linux cmd'" in an old .bashrc file, so my TERM was set to linux only for the duration of the command. Stupid simple issue that took hours of debugging to figure out. Lesson learned.

AJJ
  • 143
  • 11
0

At least on my copy of putty (0.76) the default TERM is set to xterm. As others have explained putty does not use the same escape codes as xterm, so this is definitely an unfortunate default. Set the term option (available in the putty menus before you open the connection) to putty and everything will work right, unless your .bashrc file also overrides the TERM (which would be highly unfortunate).

you can check what your current TERM is: echo $TERM

Al Ro
  • 466
  • 2
  • 11