3
我想創建一個Curses :: UI應用程序。到目前爲止一切正常,但我的對話似乎不想回應關閉的輸入鍵。我已經嘗試過這些樣品,但是由於某種原因,如果我這樣做,則對話框不會響應按鍵。看到,主窗口中的內容將最終填滿屏幕並每x秒刷新一次,所以我希望對話框覆蓋屏幕並在輸入時關閉。這是我測試腳本的代碼。Curses :: UI ::對話框沒有迴應輸入密鑰
如果您運行它,屏幕將每隔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'],
);
}