Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Curses::UI callbacks

by gdanko (Initiate)
on Oct 11, 2011 at 17:04 UTC ( #930859=perlquestion: print w/ replies, xml ) Need Help??
gdanko has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I am trying to create a top-like interface for some info here at work. I can display the text and whatnot using Curses::UI, but the callback to repopulate the data will not fire until a key is pressed. Is there a way to make the callback fire off immediately after the mainloop is called?

Comment on Curses::UI callbacks
Re: Curses::UI callbacks
by keszler (Priest) on Oct 12, 2011 at 01:16 UTC

    Curses::UI does have methods for timed events, but they are not documented. You need to read the source to find them. Based on a quick scan it looks like you need to do something like $cui->set_timer( $timer_id, $callback_ref );. There is an optional 3rd parm that seems to be # of seconds delay, default 1.

    When you set_timer it is enabled. Methods disable_timer and enable_timer both take just one parm, the $timer_id.

    Modus operandi: The CUI mainloop does some setup, then enters the following infinite loop: while ($self->{mainloop}) { $self->do_one_event }. do_one_event does various things including checking for keypress and mouse movement. One of the various things is do_timer, which loops through all the existing $timer_ids and executes their callbacks.

    update: couldn't resist playing with it:

    #!/usr/bin/env perl use strict; use warnings; use diagnostics; use Curses::UI; my $cui = Curses::UI->new(); my $win = $cui->add( 'window_id', 'Window', ); my $editor = $win->add( 'myeditor', 'TextEditor', -readonly, 1, -text, scalar `date;ps -ef`, ); $cui->set_binding( sub { exit; }, "\cQ"); # CTRL-Q to exit $cui->set_timer( 't1', sub { $editor->text(scalar `date;ps -ef`); $editor->draw; }, ); $cui->mainloop;

      What I need is to have my main callback executed once a second. It looks like it's re-executed as soon as it exits and this is a lot of unnecessary overhead. Looking at these timer functions and wondering if it's possible to use one to accomplish my goal.
Reaped: Re: Curses::UI callbacks
by NodeReaper (Curate) on Oct 14, 2011 at 12:38 UTC
Reaped: Re: Curses::UI callbacks
by NodeReaper (Curate) on Oct 16, 2011 at 12:46 UTC
Reaped: Re: Curses::UI callbacks
by NodeReaper (Curate) on Oct 17, 2011 at 13:15 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://930859]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2014-08-28 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (259 votes), past polls