本文介绍了如何在ncurses的&放大器替换字符串的菜单项; C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图找出如何我可以从ncurses的菜单替换 ITEM_NAME
。从,我可以'找不到任何类似 set_item_name
或东西。任何想法,如果有一个工作围绕这个?
例如,替换选择1
W / 字符串1
在 KEY_ENTER
的#include<&curses.h里GT;
#包括LT&;&menu.h GT;char *之选择[] = {
选择1,选择2,选择3,4选,退出,
};诠释主(){
项目** my_items,* cur_item;
INT C,I;
MENU * my_menu; initscr的();
CBREAK();
NOECHO();
键盘(stdscr上,TRUE); my_items =(ITEM **)释放calloc(6,sizeof的(ITEM *));
对于(I = 0; I&小于5 ++ⅰ)
my_items [I] = NEW_ITEM(选择[I]中,选择由[i]);
my_items [5] =(ITEM *)NULL; my_menu = new_menu((ITEM **)my_items);
post_menu(my_menu);
刷新(); 而((C =的getch())!= KEY_F(1)){
开关(三){
案例KEY_ENTER:
//例如替换选择1W /字符串1
打破;
案例KEY_DOWN:
menu_driver(my_menu,REQ_DOWN_ITEM);
打破;
案例KEY_UP:
menu_driver(my_menu,REQ_UP_ITEM);
打破;
}
}
free_item(my_items [0]);
free_item(my_items [1]);
free_menu(my_menu);
endwin();
}
解决方案
看起来像调用的再次是预期的方法。
I'm trying to figure out how can I replace an item_name
from an ncurses menu. From the man pages, I can't find any set_item_name
or something similar. Any ideas if there's a work-around for this?
e.g., replace "Choice 1"
w/ "String 1"
on KEY_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();
}
解决方案
Looks like calling set_menu_items()
again is the expected method.
这篇关于如何在ncurses的&放大器替换字符串的菜单项; C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!