Howdy, Stranger!

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

Categories

command line editor module?

archimedesarchimedes Member Posts: 31
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

  • fzapperfzapper Member Posts: 7
    : 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)

  • archimedesarchimedes Member Posts: 31
    Using that code does the same thing. Arrow keys print stuff like ^[[D.

    This is on Linux, perl 5.6.0.
  • Chris BrownChris Brown USAMember Posts: 4,496 ✭✭

    ______ // http://forcoder.org // free video tutorials and ebooks about [ Perl, Scratch, PL/SQL, Delphi, Objective-C, Visual Basic .NET, MATLAB, Assembly, PHP, JavaScript, C++, C, Visual Basic, Python, Java, Go, Ruby, C#, R, Swift Fortran, Bash, VBScript, Julia, Ada, Clojure, D, Apex, Awk, Rust, Lua, Alice, FoxPro, SAS, Crystal, Hack, Scheme, Kotlin, Scala, Dart, F#, Lisp, Prolog, Erlang, Transact-SQL, COBOL, ABAP, LabVIEW, Logo, ML ] ______________

Sign In or Register to comment.