我试图弄清楚如何item_name
从 ncurses 菜单中替换一个。从手册页中,我找不到任何set_item_name
或类似的东西。如果有解决方法,有什么想法吗?
例如,更换"Choice 1"
w/ "String 1"
onKEY_ENTER
#include <curses.h>
#include <menu.h>
char *choices[] = {
"Choice 1", "Choice 2", "Choice 3", "Choice 4", "Exit",
};
int main() {
ITEM **my_items, *cur_item;
int c, i;
MENU *my_menu;
initscr();
cbreak();
noecho();
keypad(stdscr, TRUE);
my_items = (ITEM **) calloc(6, sizeof(ITEM * ));
for (i = 0; i < 5; ++i)
my_items[i] = new_item(choices[i], choices[i]);
my_items[5] = (ITEM*) NULL;
my_menu = new_menu((ITEM **) my_items);
post_menu(my_menu);
refresh();
while ((c = getch()) != KEY_F(1)) {
switch (c) {
case KEY_ENTER:
// e.g. replace "Choice 1" w/ "String 1"
break;
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();
}