[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: menu problems
From: |
Thomas Dickey |
Subject: |
Re: menu problems |
Date: |
Thu, 8 May 2003 18:52:57 -0400 |
User-agent: |
Mutt/1.3.27i |
On Thu, May 08, 2003 at 05:26:21PM -0500, Rob Benton wrote:
> I hope this is the right place to be asking this question. If not
> please let me know.
>
> Because I was having problems w/menu functions in one of my programs I
> decided to write the simplest program I could w/a menu. 3 options on
> the menu and all it does is move the selection up or down if the up or
> down arrow keys are pressed or quit the program if 'q' is pressed.
>
> menu_driver() returns E_REQUEST_DENIED when I send the REQ_UP or
> REQ_DOWN arguments. And the program ends with a segmentation fault when
> I call free_menu().
>
> I must be doing something wrong but I can't figure out what. I'd
> appreciate any input. (sorry for the ugly tabs)
offhand - the example 'menu_test()' function in test/ncurses.c uses
REQ_NEXT_ITEM and REQ_PREV_ITEM rather than REQ_UP/REQ_DOWN.
you shouldn't have to try to do endwin() in a signal handler (ncurses
already tries ;-). It's possible to overload signal handlers, e.g.,
by calling the result of
foo = signal(SIGINT, finish);
when 'foo' isn't one of the magic values. I guess atexit() is more reliable
though.
>
>
>
> #include <curses.h>
> #include <menu.h>
> #include <signal.h>
>
> void finish(int signal);
>
> int main() {
> int ch, rcode;
> ITEM * flash, * beep, * quit;
> MENU * mainmenu;
> ITEM * mlist[3];
>
> initscr();
> keypad(stdscr, true);
> noecho();
>
> signal(SIGINT, finish);
>
> flash = new_item("flash", "");
> beep = new_item("beep", "");
> quit = new_item("quit", "");
> mlist[0] = flash;
> mlist[1] = beep;
> mlist[2] = quit;
> mlist[3] = NULL;
>
> mainmenu = new_menu(mlist);
> set_menu_win(mainmenu, stdscr);
> set_menu_sub(mainmenu, stdscr);
> post_menu(mainmenu);
> refresh();
>
> while(1) {
> ch = getch();
> switch(ch) {
> case 'q':
> unpost_menu(mainmenu);
> free_menu(mainmenu);
> free_item(flash);
> free_item(beep);
> free_item(quit);
> finish(0);
> break;
> case KEY_UP:
> rcode = menu_driver(mainmenu, REQ_UP_ITEM);
> break;
> case KEY_DOWN:
> rcode = menu_driver(mainmenu, REQ_UP_ITEM);
> break;
> default:
> rcode = E_OK;
> }
> if (rcode != E_OK) {
> finish(rcode);
> }
> }
> }
>
> void finish(int signal) {
> endwin();
> if (signal != 0) {
> printf("err:%d\n", signal);
> }
> exit(signal);
> }
>
>
>
> _______________________________________________
> Bug-ncurses mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/bug-ncurses
--
Thomas E. Dickey <address@hidden>
http://invisible-island.net
ftp://invisible-island.net
- menu problems, Rob Benton, 2003/05/08
- Re: menu problems,
Thomas Dickey <=