I use Terminal::ReadLine::Gnu with the AnyEvent asynchronous framework in an application and manage to immediately catch Ctrl-C.
Edit
I am replacing previous code with a working example
use Term::ReadLine; use AnyEvent; use Event; use strict; use warnings; my $events = {}; my $text = {}; my $term = Term::ReadLine->new("MyApp"); ($text->{screen_lines}, $text->{screen_columns}) = $term->get_screen_s +ize(); # create a STDIN watcher $events->{stdin} = AE::io(*STDIN, 0, sub { &{$term->Attribs->{'callback_read_char'}}(); }); $term->callback_handler_install(prompt(), \&process_line); # handle Control-C from terminal $events->{sigint} = AE::signal('INT', \&cleanup_exit); $term->stuff_char(10); # necessary to respond to Ctrl-C at first promp +t &{$term->Attribs->{'callback_read_char'}}(); print prompt(); $Event::DIED = sub { my ($event, $errmsg) = @_; print($errmsg); $term->Attribs->{line_buffer} = q(); if($term){ $term->clear_message(); $term->rl_reset_line_state(); } }; Event::loop(); sub cleanup_exit { print "\n caught $SIG{INT}",@_,"\n"; $term->rl_deprep_terminal(); exit; } sub prompt {"Enter command : "} sub process_line { my ($input) = @_; print "got some text: $input\n"; }
In reply to Re: Catching INT in Term::ReadLine::Gnu->readline()
by gnosti
in thread Catching INT in Term::ReadLine::Gnu->readline()
by mbrouillet
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |