使用 c++ 在 ncurses 中打印子菜单时出现问题
Issue with printing sub-menu in ncurses with c++
我正在尝试打印与带有 ncurses 显示的主菜单关联的子菜单。这是我的组织方式:
- do{} while ((; 循环与 wgetch 从用户获取键盘输入
- 如果用户按回车键,则在清除整个屏幕后显示子菜单条目。
不幸的是,我无法通过第二步,子菜单永远不会显示在屏幕上。
#include <ncurses.h>
#include <iostream>
#include <string>
int main()
{
std::string nameMainMenuExample = "/parent1/folder";
std::string nameSubMenuExample = "/folder/file";
// initialize ncurses
WINDOW *win;
win = initscr();
raw();
curs_set(0);
cbreak();
box(win, 0, 0);
refresh();
wrefresh(win);
keypad(win, true);
// end initialize ncurses
int highlight = 0;
int choice;
// PRESS 'a' to ESCAPE LOOP
do {
mvwprintw(win, 1, 1, nameMainMenuExample.c_str());
switch (choice) {
case KEY_UP:
--highlight;
if (highlight == -1) {
highlight = 0;
}
break;
case KEY_DOWN:
++highlight;
if (highlight == 1) {
highlight = 0;
}
break;
case KEY_ENTER: // Enter key pressed
clear();
mvwprintw(win, 1, 1, nameSubMenuExample.c_str());
refresh();
break;
default:
break;
}
} while ((choice = wgetch(win)) != 97); // random choice a == 97
endwin();
return 0;
}
我只希望在 ncurses 清除主菜单的屏幕后将子菜单打印在屏幕上。谢谢
如果要激活 Enter 键上的子菜单,则应根据 KEY_ENTER
(类似于数字16777221(检查返回的值wgetch
,而不是 10。
您正在混合对不同窗口的调用(clear
和refresh
使用stdscr
(,并且您的wgetch
调用使用的调用正在获取自己的wrefresh
。 由于菜单窗口没有刷新,它永远不会出现,并且由于wgetch
执行wrefresh
,这可能会进一步模糊内容。
首先,使wrefresh
调用应用于要重新绘制的窗口。
在C++中使用ncurses
,ENTER 键值只是'n'
例如:
case 'n':
clear();
mvwprintw(win, 1, 1, nameSubMenuExample.c_str());
refresh();
break;
相关文章:
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 为"adjacent"变量赋值时出现问题
- 我的神经网络不起作用 [XOR 问题]
- 在Ubuntu 16.04上安装Cilk时出现问题
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 编译包含字符串的代码时遇到问题
- Project Euler问题4的错误解决方案
- 问题:什么是QAbstractItemView::NoEditTriggers的反面
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 我的开关菜单在一段时间循环中出现问题
- 使用 c++ 在 ncurses 中打印子菜单时出现问题
- QMainWindow菜单栏:OpenGL触发的功能导致GL上下文问题
- MFC 进度条问题和文件菜单生成
- 通过循环创建弹出菜单 w.r.t 到参数时出现问题
- 在 SDL 中,当我在屏幕上绘制菜单时,它会使游戏变慢并且无法正常工作,我该如何解决这个问题?
- 制作菜单时遇到的问题
- 菜单重新出现时出现问题.使用switch语句
- 鼠标按钮模拟-右键和上下文菜单问题