Okay, this is driving me up the walls, because I can't get this working properly. I'm trying to use POE::Wheel::ReadLine to make a cpan-type interface (type a command, press enter, get output, or press up or down to see history), but even the simplest program seems to be having problems. I got this program from the POE cookbook:

#!/usr/bin/perl # This sample shows how POE::Wheel::ReadLine is used to read user # input from the console. It is a single-user chat system: It just # starts a session and lets you talk to yourself. # Use the tools everyone needs. use strict; use warnings; use POE; # The base system. use POE::Wheel::ReadLine; # For reading lines from the console. # Create a session to manage the events we want. Each "inline_states" # entry defines the function that will handle a corresponding event. # Here readline_run() is triggered by the "_start" event. The # "got_input" event triggers the got_input_handler() function. # Finally, readline_stop() is called to handle the "_stop" event. # The _start and _stop events are supplied by POE to notify you just # after a session has been created, and just before it will be # destroyed. They give you the opportunity to initialize things and # shut them down. POE::Session->create ( inline_states => { _start => \&readline_run, got_input => \&got_input_handler, _stop => \&readline_stop, } ); # Let the schizophrenia begin! Once initial sessions have been # created, we run them until everything is done. The rest of this # program is the functions that handle events. $poe_kernel->run(); exit 0; # This subroutine creates our ReadLine module and sends our inital # Prompt. ReadLine's "InputEvent" parameter specifies the event that # will be sent when it has read a line of input or some other user # generated exception. As we've seen, it is triggered by POE just # after the session is created. sub readline_run { my ($heap) = $_[HEAP]; $heap->{readline_wheel} = POE::Wheel::ReadLine->new( InputEvent => 'got_input' ); $heap->{readline_wheel}->get("Say Something: "); } # The session is about to stop. Ensure that the ReadLine object is # deleted, so it can place your terminal back into a sane mode. This # function is triggered by POE's "_stop" event. sub readline_stop { delete $_[HEAP]->{readline_wheel}; } # The input handler adds user input to an input history, displays what # the user entered, and prompts for another line. It also handles the # "interrupt" exception, which is thrown by POE::Wheel::ReadLine when # the user presses Ctrl+C. # If you recall, POE::Session->create() has mapped the "got_input" # event to the got_input_handler() function. Looking back, you will # see that POE::Wheel::ReadLine->new() is used to generate "got_input" # events for each line of input the user enters. # ReadLine input handlers take two arguments other than the usual # KERNEL, HEAP, and so on. ARG0 contains any input that was entered. # If ARG0 is undefined, then ARG1 holds a word describing a # user-generated exception such as "interrupt" (the user pressed # Ctrl+C) or "cancel" (the user pressed Ctrl+G). sub got_input_handler { my ( $heap, $kernel, $input, $exception ) = @_[ HEAP, KERNEL, ARG0, ARG1 ]; if ( defined $input ) { $heap->{readline_wheel}->addhistory($input); $heap->{readline_wheel}->put("I heard $input"); } elsif ( $exception eq 'interrupt' ) { $heap->{readline_wheel}->put("Goodbye."); delete $heap->{readline_wheel}; return; } else { $heap->{readline_wheel}->put("\tException: $exception"); } $heap->{readline_wheel}->get("Say Something Else: "); }

If I run this, not much works with backspace, delete, numpad keys, up, down, left, right, mostly broken. Not to mention it is in vi mode.

So is it not logical, that since bash and the POE module both use readline, that if I run the following command:

bind -pv > .inputrc

...all bash settings (which currently work perfectly fine thank you very much) would transfer over to the Perl program? Apparently not. It fixes home and end, and the delete key, but not backspace or anything else. Not to mention the fact that it gives a bunch of errors at the start about unknown functions.

So, Perl monks, how can I make this POE::Wheel::ReadLine function just like Bash does, with an up/down history, backspace, everything else?


In reply to Making a shell-type interface with POE::Wheel::ReadLine by linolium

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.