Hello Monks! I was wondering if I could steal your fancy brains for a moment! I have written a few Curses::UI apps and realized that they look like stop animation slow pokes when running. The read from streams that are updated in milliseconds but i cannot seem to update the label's text fields in the windows faster than once per second :/ I looked at the sauce for UI.pm and saw the set_timer() function and that it (can) take three parameters, but no matter what I pass to it, it only refreshes the windows text labels each second. Here is a simple example that doesn't update fields but will print over the curses window "called!" each second the timer calls it:

#!/usr/bin/perl -w use strict; use Curses::UI; my $date = localtime(); my $n = 1; # i've tried -2,-1,0,0.1,0.2,...,<1 my $cui = new Curses::UI(-color_support=>1); my $titlewid = $cui->add('titlew','Window',-border=>0,-height=>1,-widt +h=>34); $titlewid->add('titlel', 'Label',-text =>"my slow motion app!",-bold = +> 1,-fg=>"blue",-height=>1); my $widclock = $cui->add('clock','Window',-border=>0,-height=>1,-x=>35 +,-width=>25); $winclock::label = $widclock->add('wclock','Label',-text=>$date,-bold= +>0,height=>1,-width=>25); $winclock::label->draw(); $cui->set_binding( sub{exit}, "\cC"); $cui->set_timer('update_timer',\&call,$n); # call back in here $cui->mainloop(); sub call{ print "called!\n"; }

The source of UI.pm has:

sub set_timer($$;) { my $self = shift; my $id = shift; my $callback = shift; my $time = shift || 1; $self->fatalerror( "add_timer(): callback is no CODE reference" ) unless defined $callback and ref $callback eq 'CODE'; $self->fatalerror( "add_timer(): id is not set" ) unless defined $id; my $config = { -time => $time, -callback => $callback, -enabled => 1, -lastrun => time(), }; $self->{-timers}->{$id} = $config; $self->set_read_timeout; return $self; }

(it is here CPAN UI.pm)

Do you guys think there is some way I could hack it to "sleep" for less than a second? maybe 100 milliseconds? I don't wanna alter the pm and recompile because i would like my code to be easily redistributable :( Without the set_timer() function i have no other idea how to update the fields in "real" time. I tried using Sub::Override, but had no luck. Any ideas?

Thanks so much!

In reply to [Resolved] timing for curses::UI and set_timer() by return0

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.