develooper Front page | perl.perl5.porters | Postings from January 2012

Re: [perl #108470] Term::ReadLine should use AE instead of Tk forevent looping

From:
Joel Roth
Date:
January 20, 2012 07:52
Subject:
Re: [perl #108470] Term::ReadLine should use AE instead of Tk forevent looping
Message ID:
20120120155211.GA29272@sprite
On Wed, Jan 18, 2012 at 07:27:35AM -0700, Darin McBride 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.

Here is a demonstration code, which depends on Term::ReadLine::Gnu.

Cheers,



use Term::ReadLine; # automatically loads Term::ReadLine::Gnu, 
                    # which must be present
use Event;
use AnyEvent;

my $term = new Term::ReadLine("Test Event");
my $attribs = $term->Attribs;
$term->callback_handler_install( "> ", sub{ print "got: @_\n" });
my $stdin_watcher = AE::io(*STDIN, 0, 
	sub 
	{ 
		$attribs->{'callback_read_char'}->(); 
	}
);
my $timer = AE::timer(5,0, 
	sub
	{ 
		print "....timed out\n"; 
		$term->rl_deprep_terminal(); # restore usual terminal behavior
		exit;
	}
);
Event::loop();
__END__



-- 
Joel Roth



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About