Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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;


In reply to Re: Curses::UI callbacks by keszler
in thread Curses::UI callbacks by gdanko

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-25 06:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found