Ncurses:如何在不丢失当前位置的情况下刷新菜单? [英] Ncurses: how to refresh a menu without losing current position?

查看:115
本文介绍了Ncurses:如何在不丢失当前位置的情况下刷新菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不丢失当前位置的情况下重新加载菜单中的数据?

How can I reload the data in a menu without losing the current position?

例如,当用户选择"一个项目并执行更改数据的操作时. (更新项目,删除项目或向菜单添加新项目.)我想重新加载菜单,但仍将光标停留在刚刚选择的项目上.最好的方法是什么?

For example, when a user "selects" an item, and an action is performed that changes the data. (Either updating the item, removing it, or adding a new item to the menu.) I'd like to reload the menu but still keep the cursor on the item that was just selected. What's the best way to do this?

作为参考,这个问题似乎非常接近,但是我认为它不涉及添加/删除问题:

For reference, this question seemed very close, but I don't think it covers the add/remove issue: How to replace a string menu item in ncurses & C

这个问题似乎也很相似,但是对我来说太具体了: Ncurses菜单-记住选择

This question also seemed similar, but was too specific for me: Ncurses menu - remembering selection

推荐答案

如果重建菜单,则程序必须跟踪以前的当前"项目,并在通过. getch 函数刷新屏幕,并刷新程序的位置为getch设置的位置将变为明显的光标位置.

If you rebuild a menu, your program will have to keep track of what was the "current" item before, and find that before resuming its reads via getch. The getch function refreshes the screen, and the position which your program has set for the getch becomes the apparent cursor position.

通常,您将使用item_index询问当前项目的菜单库,并getch.同样,如果您重建菜单,则该索引信息可能会过时.

Normally you would use item_index to ask the menu library which is the current item, and set_current_item to tell the menu-library which item the cursor would be on, but it's possible to do your calls to getch "anywhere" on the screen. Likewise, if you rebuild a menu, that index information may be stale.

没有某些特定的示例程序,只能提供一般建议.

Without some specific sample program, there's only general advice which can be offered.

这篇关于Ncurses:如何在不丢失当前位置的情况下刷新菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆