Perl Curses::UI

只谈情不闲聊 提交于 2019-12-11 03:52:54

问题


I am trying to use the library Curses:UI from http://search.cpan.org/dist/Curses-UI/ to build a UI on linux karmic.

I can create a simple user interface e.g.:

#!usr/usr/bin/perl

use strict;
use Curses;
use Curses::UI;

$ui = new Curses::UI(-color_support=>1,-clear_on_exit=>1,-intellidraw=>1);
my $window = $ui->add('window', 'Window',-intellidraw=>1);
my $message = $window->add(-text=>"Hello!",-intellidraw=>1);
$window->focus(); 
$ui->mainloop();

Question: I need some way to communicate informatio to the UI i.e. I have a loop which will wait for message to come and change the text in window. Once this message comes a popup will be displayed. Attempt:

my $ui = new Curses::UI(-color_support=>1,-clear_on_exit=>1,-intellidraw=>1);
my $window = $ui->add('window', 'Window',-intellidraw=>1);
my $message = $window->add(-text=>"Hello!",-intellidraw=>1);

pseudocode
while(true) #implemented a function to wait
{
    popup($window->text("Hello how are you?"));
}

$window->focus(); 
$ui->mainloop();

Problem: The above does not work. I am given a dark screen where my message is displayed. I have read the documentation and when I relocate : $ui->mainloop() above the while loop I am given the user interface but now nothing communicates to the window.

Coincise Question: I need some way of displaying the user interface wait for inputs and display messages.

Could anyone please help me on this? Thank you!


回答1:


I would just replace $ui->mainloop() with my own eventloop where my own stuff is updated aswell.

For reference $ui->mainloop() is implemented as follows:

sub mainloop {
    my ($self) = @_;

    # Draw the initial screen.
    $self->focus(undef, 1); # 1 = forced focus
    $self->draw;
    doupdate();

    # Inifinite event loop.
    while (1) { $self->do_one_event }
}

So I would simply add your own tick() function to the while loop.



来源:https://stackoverflow.com/questions/2931951/perl-cursesui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!