I have this loop:
Code: Select all
int c = 0;
while((c = getch()) != KEY_F(1))
{
switch(c){
case KEY_DOWN:
menu_driver(menuObj, REQ_DOWN_ITEM);
break;
case KEY_UP:
menu_driver(menuObj, REQ_UP_ITEM);
break;
case '\n': /* enter */
menu_driver(menuObj, REQ_TOGGLE_ITEM);
// Cycle through the items and find which was
// toggled
ITEM** items = menu_items(menuObj);
for(i=0; i < item_count(menuObj); i++){
if( item_value( items[i] ) == TRUE ){
// Get rid of menu, so normal output
const char* item = item_description(items[i]);
// Get rid of menu
unpost_menu(menuObj);
refresh();
endwin();
// Keyboard mapping
keypad(stdscr, FALSE);
// Call function
callFunction( item );
set_item_value(items[i], FALSE);
// Keyboard mapping
keypad(stdscr, FALSE);
// Bring menu back
initscr();
post_menu(menuObj);
refresh();
}
}
}
// refresh the menu (draw the menu again)
refresh();
}
Code: Select all
void callFunction(const char* s)
{
printf("\n Function called is: %s\n Press any key to continue.\n", s);
getchar();
}
Right now when I select an item, the function is call and nothing appears. Then when I select another one, the function comes up and prints the FIRST menu item. Then for the third, it prints the second, and etc, so its always one behind.
Any ideas??