Ncurses:如何在不丢失当前位置的情况下刷新菜单?

编程入门 行业动态 更新时间:2024-10-22 13:41:56
本文介绍了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?

作为参考,这个问题似乎非常接近,但是我认为它不涉及添加/删除问题:如何在ncurses&中替换字符串菜单项C

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询问当前项目的菜单库,并 set_current_item 告诉菜单库光标将位于哪个项目上,但是可以在屏幕上任意位置"调用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:如何在不丢失当前位置的情况下刷新菜单?

本文发布于:2023-11-02 14:43:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552683.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:当前位置   情况下   菜单   如何在   Ncurses

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!