getting f keys to work on curses osx

closed account (L0M4jE8b)
Hello all,

I'm new to the forum and I haven't programmed C/C++ in about 4 years. Anyways here's the issue.

I'm trying to use ncurses to get function keys on a terminal in OSX 10.4, however it does not work.
Here's my code...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <ncurses.h>

int main()
{       int ch;

        initscr();                      /* Start curses mode            */
        raw();                          /* Line buffering disabled      */
        keypad(stdscr, TRUE);           /* We get F1, F2 etc..          */
        noecho();                       /* Don't echo() while we do getch */

        printw("Type any character to see it in bold\n");
        ch = getch();
        while (ch != KEY_F(1))
        {
                if(ch == KEY_F(1))      
                        printw("F1 Key pressed: Ending program.\n");

                else
                {       printw("The pressed key is ");
                        attron(A_BOLD);
                        printw("%c\n", ch);
                        attroff(A_BOLD);
                }

                refresh();       
                ch = getch();
        }
        printw("end\n");
        endwin();                       /* End curses mode                */

        return 0;
}

(Yes its ripped right out of the tutorial)


What I expect is the program to terminate and print "end", however I get the following and I have to kill the program.

1
2
3
4
Type any character to see it in bold
The pressed key is ^[
The pressed key is O
The pressed key is P


My guess is my terminal is not sending the correct keycode for F1? This could be a terminal configuration issue, although I have other terminal programs that accept the function keys without any configuration changes.

Has anyone ran into this issue or have any ideas?


Last edited on
It looks to me like it is definitely a configuration issue, however I doubt it is the terminal's problem.

Try setting
timeout( 200 );
up at the top with the rest of your initializations. If this doesn't fix it, then your terminfo is incorrectly configured.

Go to the shell prompt and type
echo $TERM

Then you'll have to navigate your way to the terminfo database. You can find its possible locations by typing
locate vt100
(where you replace "vt100" with whatever your TERM variable is). It is probably somewhere in /usr/lib/terminfo/ but not necessarily. You'll have to use the tic (terminfo compiler) program to decompile and view your terminfo data. Make sure that the function sequences are correctly specified. If they aren't, fix them and recompile.

If you google around with your specific OS version and terminal name you might find others who have had the same problem and have already fixed it...

I don't have access to a Mac so that's the best I can help with. Sorry I couldn't be of more help.
closed account (L0M4jE8b)
Thanks for the information, it helped me solve the issue.

I just switched the terminal to vt100 and it's working now.
There must be something wrong with the "term-color" configuration in the database.
Topic archived. No new replies allowed.