开发者

Curses::UI::Dialog does not respond to enter key

开发者 https://www.devze.com 2023-04-13 05:41 出处:网络
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

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'],
    );
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号