Thread: ncruses and menu

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    14

    ncurses and menu

    I have compiled and run the following, exactly as suggested in the ncurses library manual (Menus Library)

    Code:
    include <curses.h>
    #include <menu.h>
    
    #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
    #define CTRLD 	4
    
    char *choices[] = {
                            "Choice 1",
                            "Choice 2",
                            "Choice 3",
                            "Choice 4",
                            "Exit",
                      };
    
    int main()
    {	ITEM **my_items;
    	int c;				
    	MENU *my_menu;
    	int n_choices, i;
    	ITEM *cur_item;
    	
    	
    	initscr();
    	cbreak();
    	noecho();
    	keypad(stdscr, TRUE);
    	
    	n_choices = ARRAY_SIZE(choices);
    	my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *));
    
    	for(i = 0; i < n_choices; ++i)
    	        my_items[i] = new_item(choices[i], choices[i]);
    	my_items[n_choices] = (ITEM *)NULL;
    
    	my_menu = new_menu((ITEM **)my_items);
    	mvprintw(LINES - 2, 0, "F1 to Exit");
    	post_menu(my_menu);
    	refresh();
    
    	while((c = getch()) != KEY_F(1))
    	{   switch(c)
    	    {	case KEY_DOWN:
    		        menu_driver(my_menu, REQ_DOWN_ITEM);
    				break;
    			case KEY_UP:
    				menu_driver(my_menu, REQ_UP_ITEM);
    				break;
    		}
    	}	
    
    	free_item(my_items[0]);
    	free_item(my_items[1]);
    	free_menu(my_menu);
    	endwin();
    }
    What I get is the following:

    ncruses and menu-bad_menu-png

    As you can see, only the last item appears. However, when I start hitting the down arrow to activate REQ_DOWN_ITEM, the menu "unrolls" until I hit the bottom, when I get the full menu:

    ncruses and menu-full_menu-png

    This is a MWE; I have a much longer menu which does the same thing. The infuriating thing is that this worked---that is, I got the full menu displayed as soon as it was posted---for months, and I can't find that I changed anything in the menu code to make this happen.

    Does anyone have any ideas?
    Last edited by dgoodmaniii; 09-26-2022 at 12:43 PM.

  2. #2
    Registered User
    Join Date
    Nov 2009
    Posts
    14
    Well, I reinstalled ncurses and all seems right with the world again. But does anyone have any notion what was going on?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 01-16-2015, 02:32 PM
  2. How to add a Menu?
    By iluvanimestyle in forum C++ Programming
    Replies: 3
    Last Post: 09-13-2011, 05:50 PM
  3. menu
    By Drake in forum Game Programming
    Replies: 12
    Last Post: 11-29-2005, 12:02 PM
  4. MENU IDs
    By Granger9 in forum Windows Programming
    Replies: 1
    Last Post: 02-08-2003, 11:49 AM
  5. How to modify a menu into a menu Folder(contains submenus) ??
    By L.O.K. in forum Windows Programming
    Replies: 3
    Last Post: 01-09-2003, 02:26 PM

Tags for this Thread