C - 从 ncurses ui 到外部程序并返回
我正在制作一个程序,在 ncurses 中显示一些信息,然后打开 vim (使用 system
)以允许用户编辑文件。不过,退出 vim 后,ncurses 屏幕不会重绘。 refresh
和 wrefresh
不执行任何操作,导致我漂亮的菜单完全被丢弃。
所以,我被送回命令行。当我移动到菜单项时,它们会重新绘制。稍微移动一下会得到如下所示的结果:
正如你所看到的,我不再处于我漂亮的 ncurses 中环境,。
我可以完全拆除 ncurses 并重新设置,但有些东西(如菜单位置)不会保留。
我该如何正确地做到这一点?有没有更好的方法来调用一些外部程序并优雅地返回这里?
I'm making a program that displays some info in ncurses, and then opens vim (using system
) to allow the user to edit a file. After vim is exited, though, the ncurses screen won't redraw. refresh
and wrefresh
don't do anything, resulting in the complete trashing of my beautiful menu.
So, I get sent back to the command line. The menu items redraw when I move to them. Moving around a bit results in something that looks like this:
As you can see, I no longer am in my pretty ncurses environment,.
I could tear down ncurses completely and set things up again, but then some stuff (like menu position) is not preserved.
How do I do this correctly? Is there a better way to call some external program and return here gracefully?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从来没有必要完全重新启动诅咒。
如果您执行类似
def_prog_mode() 的操作,该怎么办
endwin()
执行系统调用
,refresh() 应该恢复它
I've never had to restart curses entirely.
what if you do something like
def_prog_mode() then
endwin()
execute system call
and refresh() should restore it
将程序状态与诅咒状态分开。
我所知道的唯一干净的方法是完全停止并重新启动诅咒。如果您的程序对其内部状态有一个清晰的概念(它应该如此),那么应该很容易返回到相同的位置。
祝你好运!
Separate your program state from the curses state.
The only clean way I know of is to stop and restart curses entirely. If your program has a clean notion of its internal state (as it should), then it should be easy to go back to the same position.
Good luck!