使用 Curses 开发套件 (Cdk) 时打印原始数据
我的 Perl 程序需要在 ncurses 和原始控制台之间跳转,因为它在循环中执行系统调用,如下所示(为了强调问题而简化):
- init Cdk
- 显示菜单
- deinit Cdk
- 运行系统调用
不幸的是,Cdk 似乎在处初始化 ncurses >使用Cdk
导入而不是实例化 (Cdk::init()
),所以我不知道如何禁用它。这种行为在我看来是完全荒谬的;除了上面描述的循环之外,我的程序还有一个特殊的模式,其中数据库被初始化 - 这部分不提供任何类型的菜单(仅原始控制台输出),但似乎我现在必须用菜单格式化所有输出- 甚至不使用菜单!再说一次,现在只是为了打印程序帮助输出似乎需要我生成一个 Cdk 小部件 - 太疯狂了。
使用 Cdk 时是否有办法轻松跳入和跳出 ncurses 还是我被搞砸了?
一些示例代码:
#!/usr/bin/perl
use Cdk;
eval {popupLabel(["popup before init"]);}; # will fail as init() isn't called
print "Test after use\n"; # won't be printed (which is a problem!)
Cdk::init();
print "Test after init\n"; # won't be printed
popupLabel(["popup after init"]);
Cdk::end();
print "Test after end\n"; # won't be printed
My perl program needs to jump between ncurses and a raw console as it executes a system call in a loop, like this (simplified for problem emphasis):
- init Cdk
- present menu
- deinit Cdk
- run system call
Unfortunately Cdk appears to initialize ncurses at the use Cdk
import and not instantiation
(Cdk::init()
) and so I don't know how to disable it. This behavior seems completely absurd to me; apart from the loop described above, my program also has a special mode where a database is initialized - this part does not present any kind of menu (only raw console output) yet it would seem that I now have to format all my output with menus - whilst not even using a menu! And again, just to print the program help output now seems to require me to generate a Cdk widget - insane.
Is there a way to easily jump in and out of ncurses when using Cdk or am I screwed?
Some example code:
#!/usr/bin/perl
use Cdk;
eval {popupLabel(["popup before init"]);}; # will fail as init() isn't called
print "Test after use\n"; # won't be printed (which is a problem!)
Cdk::init();
print "Test after init\n"; # won't be printed
popupLabel(["popup after init"]);
Cdk::end();
print "Test after end\n"; # won't be printed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下内容(使用较新的 Curses 模块)似乎可以满足您的要求: Curses 和非 Curses 的部分混合在一起:
至少这个模块是今年 1 月发布的,而不是上个世纪(如 1998 年发布的 Cdk)......
The following (which uses the newer Curses module) seems to do what you want: bits of Curses, and bits of non-Curses intermingled:
At least this module was released this January and not (like Cdk, released 1998) last century...
好吧,我得到了我想要的,为 Curses::UI 废弃 Cdk。感谢 mfontani 发布答案!
这是我的示例解决方案,它使用
Curses::UI
和Curses::UI::Listbox
:Well, I got what I wanted, scrapping Cdk for Curses::UI. Thanks mfontani for posting an answer!
Here's my example solution which uses
Curses::UI
andCurses::UI::Listbox
: