Reputation: 2935
I need to create a mainloop for my program and wrote the following function:
void menu(){
int ch;
cbreak();
noecho();
initscr();
refresh();
while (ch != KEY_F(9)){
ch = getch();
cout << ch << endl;
switch (ch){
case KEY_F(1): add();
break;
case KEY_F(2): edit();
break;
case KEY_F(3):
break;
case KEY_F(4):
break;
}
}
endwin();
}
But getch() doesn't work and print -1 in loop. how i do? May i set special attr or call special func?
Upvotes: 0
Views: 6039
Reputation: 2935
Yes, my loop is here:
initscr();
clear();
noecho();
cbreak(); /* Line buffering disabled. pass on everything */
startx = (80 - WIDTH) / 2;
starty = (24 - HEIGHT) / 2;
menu_win = newwin(HEIGHT, WIDTH, starty, startx);
keypad(menu_win, TRUE);
mvprintw(0, 0, "Name of my program");
refresh();
print_menu(menu_win, highlight);
while (true)
{ c = wgetch(menu_win);
switch(c){
TYPE OF KEYS;
}//END OF SWITCH
}//END OF LOOP
Upvotes: 0
Reputation: 290
First, every ncurses function should be used only after initscr()
has been called. In your code cbreak()
and noecho()
are probably ignored.
Second, if you want to use function keys, you have to tell that to ncurses, by calling keypad(stdscr, TRUE)
. However, since not every computer has got function keys, you should always check if the system support that functionality, using has_key()
(same for has_colors()
that checks if current terminal supports colors).
Upvotes: 0