Curses-UI-AnyEvent
view release on metacpan or search on metacpan
lib/Curses/UI/AnyEvent.pm view on Meta::CPAN
my $cui = Curses::UI::AnyEvent->new(-color_support => 1);
$cui->set_binding(sub { exit }, "\cC");
$cui->set_binding(sub { $cui->mainloopExit() }, "q");
my $win = $cui->add('win', 'Window',
-border => 1,
-bfg => 'red',
);
my $textviewer = $win->add('mytextviewer', 'TextViewer',
-text => '',
);
my $watcher = AE::timer 1, 1, sub {
$textviewer->{-text} = localtime() . "\n" . $textviewer->{-text};
$textviewer->draw;
};
$textviewer->focus();
$cui->mainloop();
=head1 DESCRIPTION
Very simple integration with L<Curses::UI> and L<AnyEvent>. Just create a C<Curses::UI::AnyEvent> object instead of a C<Curses::UI> one and use it as normal.
You'll probably want to install some AnyEvent watchers before you call C<mainloop()>. Alternatively, if you want to setup the async handlers without blocking, you can use the C<startAsync> method:
$cui->startAsync();
## add some other handlers...
AE::cv->recv; ## block here instead
Most things work, including mouse support.
=head1 DIALOGS
L<Curses::UI> unfortunately implements a separate event loop in order to handle modal dialogs. This conflicts with our AnyEvent loop so it needed to be stubbed out by replacing the internal C<tempdialog> method. Informational dialogs work normally, e...
$cui->dialog("Some information: blah blah blah");
## ^^ Returns immediately, not when dialog dismissed!
If you wish to perform some action after the dialog is dismissed, or in the case of query dialogs you wish to access the value, there is a new C<-cb> parameter that accepts a callback:
$cui->question(-question => "What is your name?",
-cb => sub {
my $name = shift;
## ...
});
Note that while a dialog is active, all keypresses are routed to that dialog instead of the main screen. However, since the main event loop is still active, it can still be processing externally triggered or timed events.
=head1 BUGS
There are still a few places that call `do_one_event()` in a loop instead of using the AnyEvent loop so they will busy-loop until dismissed by the user and no background events will be processed. The cases I know about are search windows and fatal er...
=head1 SEE ALSO
L<Curses-UI-AnyEvent github repo|https://github.com/hoytech/Curses-UI-AnyEvent>
L<Curses::UI>
L<AnyEvent>
L<Curses::UI::POE>
=head1 AUTHOR
Doug Hoyte, C<< <doug@hcsw.org> >>
=head1 COPYRIGHT & LICENSE
Copyright 2016 Doug Hoyte.
This module is licensed under the same terms as perl itself.
( run in 1.171 second using v1.01-cache-2.11-cpan-39bf76dae61 )