Hi,

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

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.