FAQ
I have a Perl program with a simple command line interface where the
user can enter commands.

I read these commands in a loop that looks like:

while($rc == 0) {
print "$LCLdebuggerPrompt";
$debugCommand = <STDIN>;
chop $debugCommand; # remove trailing newline
$rc = handleCmd($debugCommand);
}

I'd like to be able to add 2 things to this process:

1) protect the command prompt field, so that using the "backspace" or
"left arrow" keys don't move the cursor into the command prompt field.

2) add a "command retrieve" function, so that the "up arrow" and "down
arrow" keys display commands kept in a list of previously stored
commands.

Neither the "protect command prompt" or "up arrow" functions works in
the above example, because I'm missing a more elaborate method for
sampling keyboard input than a read to <STDIN> provides.

Short of learning Perl-curses or writing a full-blown TK-Perl app, are
there any simple techniques - (read: minimum learning time) that I can
use to implement a "protect command prompt" or "retrieve up-arrow key
indication" function?

thanks in advance for any suggestions,
Gavin Bowlby

Search Discussions

  • Mr. Shawn H. Corey at Apr 11, 2006 at 8:03 pm

    On Tue, 2006-11-04 at 11:01 -0700, Gavin Bowlby wrote:
    Short of learning Perl-curses or writing a full-blown TK-Perl app, are
    there any simple techniques - (read: minimum learning time) that I can
    use to implement a "protect command prompt" or "retrieve up-arrow key
    indication" function?
    No, there are no simple techniques.

    Two choices:

    use POSIX
    See `perldoc POSIX` and search for 'termio'.

    use Term::ReadKey;
    See http://search.cpan.org/~jstowe/TermReadKey-2.30/

    Hint: the POSIX stuff is harder to follow (OK, it's all hard to follow).


    --
    __END__

    Just my 0.00000002 million dollars worth,
    --- Shawn

    "For the things we have to learn before we can do them, we learn by doing them."
    Aristotle

    * Perl tutorials at http://perlmonks.org/?node=Tutorials
    * A searchable perldoc is at http://perldoc.perl.org/
  • Jay Savage at Apr 13, 2006 at 1:10 am

    On 4/11/06, Mr. Shawn H. Corey wrote:
    On Tue, 2006-11-04 at 11:01 -0700, Gavin Bowlby wrote:
    Short of learning Perl-curses or writing a full-blown TK-Perl app, are
    there any simple techniques - (read: minimum learning time) that I can
    use to implement a "protect command prompt" or "retrieve up-arrow key
    indication" function?
    No, there are no simple techniques.

    Two choices:

    use POSIX
    See `perldoc POSIX` and search for 'termio'.

    use Term::ReadKey;
    See http://search.cpan.org/~jstowe/TermReadKey-2.30/

    Hint: the POSIX stuff is harder to follow (OK, it's all hard to follow).
    And tedious. if you're not doing much of it, see perldoc -f getc for a
    non-portable suggestion.

    If you really need to do this, both Term::Readkey and Posxi termois
    will work, as suggested, but take a serious look at curses. It's
    really not that bad and gives you as much flexibilty and control as
    you'll ever need.

    HTH,

    -- jay
    --------------------------------------------------
    This email and attachment(s): [ ] blogable; [ x ] ask first; [ ]
    private and confidential

    daggerquill [at] gmail [dot] com
    http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org

    values of β will give rise to dom!

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedApr 11, '06 at 6:01p
activeApr 13, '06 at 1:10a
posts3
users3
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase