Jump to content

[Biblioteca ncurses] Problemas a fazer free de menus


casdio
 Share

Recommended Posts

Boas.

Estou com um problema a fazer menus com a ncurses.

O meu codigo e tipo isto:

void mainMenu()
{	ITEM **my_items;
MENU *menu_main;
int c, n_choices, i;
ITEM *cur_item;

initscr();
cbreak();
keypad(stdscr, TRUE);
start_color();

init_pair(1,COLOR_BLUE,COLOR_BLACK);
init_pair(2,COLOR_GREEN,COLOR_BLACK);
init_pair(3,COLOR_WHITE,COLOR_BLACK);

bkgd(COLOR_PAIR(3));

n_choices = ARRAY_SIZE(items_main);
my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *)); 
for(i = 0; i < n_choices; ++i)
        my_items[i] = new_item(items_main[i], "");
my_items[n_choices] = (ITEM *)NULL;

menu_main = new_menu((ITEM **)my_items);
set_menu_back(menu_main, COLOR_PAIR(2));

attron(COLOR_PAIR(1));
mvprintw(LIM, 0, "Prima F4 para sair a qualquer momento");
attroff(COLOR_PAIR(3));

post_menu(menu_main);
refresh();

while((c = getch()) != KEY_F(4))
{   switch(c)
    {	case KEY_DOWN:
	        menu_driver(menu_main, REQ_DOWN_ITEM);
			break;
		case KEY_UP:
			menu_driver(menu_main, REQ_UP_ITEM);
			break;
		case 10: //o 10 e o ENTER
		{
			move(LIM+1,0);
			clrtobot();
			cur_item=current_item(menu_main)
			option5();
			break;				
		}	
	}
}	

freeMenus(menu_main,n_choices,my_items);
}

void freeMenus(MENU *menu, int n, ITEM **items)
{
int i;

unpost_menu(menu);
free_menu(menu);
for(i=0;i<n;++i)
	free_item(items[i]);
endwin();
}

void menuAdmin(void)
{
ITEM **opcoes;
MENU *menu_admin;
int o, opc,i;
ITEM *cur_item;

opc=ARRAY_SIZE(items_admin);

opcoes=(ITEM **)calloc(opc + 1, sizeof(ITEM *));
for(i = 0; i < opc; ++i)
	opcoes[i] = new_item(items_admin[i], "");
opcoes[opc] = (ITEM *)NULL;

menu_admin = new_menu((ITEM **)opcoes);
set_menu_back(menu_admin, COLOR_PAIR(2));

attron(COLOR_PAIR(1));
mvprintw(LIM, 0, "Prima F2 para voltar ao menu principal");
attroff(COLOR_PAIR(3));

post_menu(menu_admin);
refresh();

while((o = getch()) != KEY_F(2))
{   switch(o)
    {	case KEY_DOWN:
	        menu_driver(menu_admin, REQ_DOWN_ITEM);
			break;
		case KEY_UP:
			menu_driver(menu_admin, REQ_UP_ITEM);
			break;
		case 10:
		{
			move(LIM+1,0);
			clrtobot();
			cur_item=current_item(menu_admin);
			choose_option(cur_item->index,LIM);
			break;				
		}	
	}
}	

freeMenus(menu_admin,opc,opcoes);
mainMenu();
}

void option_5(void)
{
move(1,0);
clrtobot();
refresh();
menuAdmin();
}

Isto em todos os menus.

Quando uso um sozinho, funciona direito. Mas, ao aceder a um menu atraves de outro, ja nao. Quando saio, a consola fica a preto a espera de que carregue nuam tecla qualquer. Ou seja, ha free's que nao estao a funcionar direito.

Alguém me pode ajudar nisto?

P.s: ja agora, alguem sabe como posso fazer para, ao inserir dados atraves do teclado, estar a ver o que escrevo?

edit: ja resolvi o problema de nao ver ao escrever, tinha a opção noecho();

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.