Curses::UI::Dialog 不响应回车键
我正在尝试创建一个 Curses::UI 应用程序。到目前为止,一切正常,但我的对话框似乎不想响应关闭的回车键。我已经尝试过这些示例并且它们可以工作,但由于某种原因,如果我这样做,对话框不会响应按键。看,主窗口中的内容最终将填满屏幕并每 x 秒刷新一次,因此我希望对话框覆盖屏幕并在输入时关闭。这是我的测试脚本中的代码。
如果运行它,屏幕将每 10 秒更新一次,并在左侧显示时间。更新后,点击 X 弹出一个虚拟对话框。下次更新时,屏幕数据将覆盖仍处于活动状态的对话框。按 Enter 键退出对话框,然后您可以退出。
我的目标是让这个对话框位于一切之上。
#!/usr/local/bin/perl
use strict;
use warnings;
use Curses::UI;
my ($dialog, $main, $ui, $container, $content);
my $last_update = 0;
my $first_run = 0;
$ui = Curses::UI->new(
-color_support => 1,
-mouse_support => 0,
-border => 1,
-debug => 0
);
$main = $ui->add(
"main", "Window",
-bfg => "black",
-x => 0,
-y => 0,
-height => $ui->height,
-width => $ui->width
);
$main->focus();
$ui->set_binding( sub { $ui->leave_curses; exit(0); }, "q");
$ui->set_binding( \&exit, "x");
$ui->add_callback("callback", \&callback );
$ui->{-read_timeout} = 0.1;
$ui->mainloop;
sub callback {
if($first_run == 0) {
update_body();
$first_run = 1;
}
my $now = time;
if($now - $last_update >= 10) {
update_body();
$last_update = time;
}
}
sub update_body {
for(my $x = 0; $x < 2000; $x++) {
$main->delete("body$x");
}
for(my $x = 0; $x < ($ui->height - 5); $x++) {
my $now = time;
$main->add(
"body$x", "Label",
-x => 0,
-y => $x,
-text => $now,
-width => $ui->width
)->draw();
}
}
sub exit {
my $return = $ui->dialog(
-message => "Test dialog",
-title => "Test",
-buttons => ['ok'],
);
}
I am trying to create a Curses::UI application. So far everything is working but my dialog does not seem want to respond to the enter key for closing. I have tried the samples and they work but for some reason if I do it this way, the Dialog does not respond to key presses. See, the content in the main window will end up filling the screen and refreshing every x seconds so I'd like the Dialog to overlay the screen and close upon enter. Here is the code from my test script.
If you run it the screen will update every 10 seconds, displaying the time down the left side. After an update, hit X to bring up a dummy dialog. On next update the screen data will cover the dialog box which is still active. Hit enter to get out of the dialog and then you can exit.
My goal is to keep this dialog on top of everything.
#!/usr/local/bin/perl
use strict;
use warnings;
use Curses::UI;
my ($dialog, $main, $ui, $container, $content);
my $last_update = 0;
my $first_run = 0;
$ui = Curses::UI->new(
-color_support => 1,
-mouse_support => 0,
-border => 1,
-debug => 0
);
$main = $ui->add(
"main", "Window",
-bfg => "black",
-x => 0,
-y => 0,
-height => $ui->height,
-width => $ui->width
);
$main->focus();
$ui->set_binding( sub { $ui->leave_curses; exit(0); }, "q");
$ui->set_binding( \&exit, "x");
$ui->add_callback("callback", \&callback );
$ui->{-read_timeout} = 0.1;
$ui->mainloop;
sub callback {
if($first_run == 0) {
update_body();
$first_run = 1;
}
my $now = time;
if($now - $last_update >= 10) {
update_body();
$last_update = time;
}
}
sub update_body {
for(my $x = 0; $x < 2000; $x++) {
$main->delete("body$x");
}
for(my $x = 0; $x < ($ui->height - 5); $x++) {
my $now = time;
$main->add(
"body$x", "Label",
-x => 0,
-y => $x,
-text => $now,
-width => $ui->width
)->draw();
}
}
sub exit {
my $return = $ui->dialog(
-message => "Test dialog",
-title => "Test",
-buttons => ['ok'],
);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论