command line editor module?

I'm writing a program that accepts commands on stdin, but entering the commands is annoying since the arrow keys print their control sequences, and if you type a long command that wraps to the next line there is no way to backspace to the previous line.

I want behavior similar to a shell prompt. So far the only information I've found has suggested changing settings with stty or using Term::ReadKey...but that seems to really mess things up. I tried that and it let the user use the arrows to move anywhere in the terminal window...even above the line containing the prompt.

So am I doomed to have a stupid command line interface, or am I missing something here?

Comments

  • : I'm writing a program that accepts commands on stdin, but entering the commands is annoying since the arrow keys print their control sequences, and if you type a long command that wraps to the next line there is no way to backspace to the previous line.
    :
    : I want behavior similar to a shell prompt. So far the only information I've found has suggested changing settings with stty or using Term::ReadKey...but that seems to really mess things up. I tried that and it let the user use the arrows to move anywhere in the terminal window...even above the line containing the prompt.
    :
    : So am I doomed to have a stupid command line interface, or am I missing something here?
    :

    What environment and perl are you running? The following works on my system (w2k, ActivePerl):

    @l = <>; # ctrl-Z to end input
    foreach $x (@l){
    print $x;
    }

    I use doskey and the up/down arrows even bring up the previous entries! (hmmmm, doskey might make all the difference)

  • Using that code does the same thing. Arrow keys print stuff like ^[[D.

    This is on Linux, perl 5.6.0.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories