Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-24 07:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found