On Wed, Jan 18, 2012 at 12:16:50PM -0700, Darin McBride wrote: > On Wednesday January 18 2012 10:13:48 AM Joel Roth wrote: > > > I'm curious as to how you would receive events registered wtih Event while > > > T::RL is waiting for text, since T::RL is currently going to be spinning > > > the Tk event loop, not the Event event loop, unless you have an idle > > > callback registered with Tk that simply spins the Event loop once. > > > > I use Event in a situation that the app runs without loaded > > the Tk based GUI, to provide timers, etc. In that case, > > tkRunning is not set. > > Yeah, I'm very curious. Are you running multi-threaded? That should do it, > but otherwise, I can't figure it out. > > > > In other words, as far as I can tell, today, T::RL will only spin a Tk > > > loop. If Tk isn't loaded, it won't spin any loop, and all events will be > > > on hold (with a possible exception of signal handlers) until the user > > > hits enter. > > I'm glad no one told *me* that! :-) > > > > A T::RL based command prompt seems to run fine alongside > > an Event event loop. I may be able to dig up some > > test code to verify this FYI. > > You've piqued my curiosity. :-) Here's the test I've been running, it's as > simple as I can make it. If you uncomment out the two tk lines and comment > out the Event line, it works. But if you try to remove Tk, the timer doesn't > print out the elapsed time (or something approximating such) at the top of the > console, assuming ANSI escape sequences are being interpreted (I was too lazy > to do any other method of controlling the cursor as this one dates back to my > DOS 5.0 days). > > I assume that if I moved the Event loop to one thread and the Tk loop (or > basically, T::RL without tk) to a separate thread from the Event loop, it'll > work. But that now comes with all the joys and tribulations of > multithreading. As opposed to the joys and tribulations of event programming. > > #!/usr/bin/perl > > use strict; > use warnings; > > use Event; > #use Tk; > use AnyEvent; > use Term::ReadLine; > > my $esc; > BEGIN { $esc = "\x1b["; > print "${esc}2J${esc}3H"; > } > > my $t = 0; > my $w = AE::timer (0,1,sub {print "${esc}s${esc}1H$t s ${esc}u";++$t}); > my $term = Term::ReadLine->new('...'); > #$term->tkRunning(1); > > my $x = $term->readline('> '); Hi, While I don't have time this morning to get a working test case, I find that when the app uses Event, it runs Event::loop(), whereas when it uses Tk, it *doesn't* run MainLoop(); tkRunning(1) somehow substitutes for it. Again, this is all using Terminal::ReadLine::Gnu, which I found necessary to get the behaviors I needed. Sorry for the lack of specifics at the moment. Regards, -- Joel RothThread Previous | Thread Next