Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Here is the POSIX::sigaction variant of the short patch updating the script to work with UNIX again. It no longer requires the extra CR, instead using unsafe signals locally for interrupting readline.

Thanx to anonymous for the pointer.

Please use the earlier Patch for the time being.

(partial line lost, as noted below; so it's patch is merely a valid example for interrupting linked code with POSIX::sigaction, and annoying the user, but not for sane interrupted ReadLine use

@@ -408,15 +408,18 @@ ##################################################################### +# my $old; my $term = new Term::ReadLine 'pmchat'; +use POSIX qw/SIGALRM/; + +my $posixsigh=sub { + $old = $readline::line; + die +}; sub getlineUnix { my $message; eval { - local $SIG{ALRM}=sub { - $old = $readline::line; - die - }; + POSIX::sigaction(SIGALRM, POSIX::SigAction->new($posixsigh)); ## I don't use the version of readline from ReadKey (that include +s ## a timeout) because this version stores the interrupted (what @@ -427,8 +430,11 @@ $message = $term->readline("\rTalk: ", $old); $old = $readline::line = ''; alarm(0) unless $win32; + POSIX::sigaction(SIGALRM, POSIX::SigAction->new(undef)); }; + $message="" if not defined $message; + #warn "seen: $message\n"; $message; }

It might be another improvement to also comment-out the undef of the handler and move the setting of the handler to just below the use Term::Readline; as SIGALRM shouldn't happen without us using alarm().

Update 1: with the change of the Alarm, I cannot obtain the partial input line (noticed when reducing the timeout). While there's a tantalizing rl_set_keyboard_input_timeout(int usec) for Gnu ReadLine, it's probably not worth the effort, as the version of the patch in the first post works well enough. KISS wins, I guess.

Please drop me a line if you've a trick to try and get the partial line buffer. Thanx.


In reply to Re: pmchat-2 by jakobi
in thread pmchat-2 by samwyse

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (6)
    As of 2020-04-09 22:33 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      The most amusing oxymoron is:
















      Results (49 votes). Check out past polls.

      Notices?