Asynchronous readline?

P

Philip Mak

I am developing a console application that accepts typed commands from
the user. At the same time, it must display incoming data about events
that occur. Events can occur at any time, not just as a result of a
command the user typed, so I need asynchronous input/output. (Think
like in a MUD client, for example.)

Is there an existing Perl module I can use that will handle input and
output for me, making it so that the input line doesn't get mixed with
the output if new output comes while the user is typing, allowing
up-arrow to be pressed to recall previous commands (like with
"readline", except that readline doesn't work asynchronously AFAIK)?
This seems like a problem that should already be solved, so I'd rather
not re-invent the wheel...
 
R

Rocco Caputo

I am developing a console application that accepts typed commands from
the user. At the same time, it must display incoming data about events
that occur. Events can occur at any time, not just as a result of a
command the user typed, so I need asynchronous input/output. (Think
like in a MUD client, for example.)

Is there an existing Perl module I can use that will handle input and
output for me, making it so that the input line doesn't get mixed with
the output if new output comes while the user is typing, allowing
up-arrow to be pressed to recall previous commands (like with
"readline", except that readline doesn't work asynchronously AFAIK)?
This seems like a problem that should already be solved, so I'd rather
not re-invent the wheel...

POE::Wheel::ReadLine does this, although the current version on the CPAN
isn't nearly as good as the one in development. The next release
(already in CVS) will be a lot more compatible with gnu readline.

Term::Visual is another way to write clients. It's full-screen like
tinyfugue's visual mode. I already wrote a simple chat client with it,
at http://poe.perl.org/poedown/oscon2004/chat-client.perl . The code is
released under the same terms as Perl itself. You're free to use it as
the basis for your application.

A disclaimer is in order: POE is an event driven system (it implements
the "Reactor" pattern). Any existing code you have may need to be
restructured to be compatible with the modules I've mentioned.

Several other examples are in the same directory as chat-client.perl,
including the chat server to go along with it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top