in reply to Avoid newline echoing so I can capture a line and reprompt over it

Hi,
If I'm reading you correctly, what you wish to do is print the prompt, then the answer on the new line, but leave the cursor at the prompt. Does that sound about right?
I'm not sure how/if you can do this with Term::ReadLine, but an example of a "general solution" is something like what is in Re: Clearing / rewriting a line in the console (windows).

#!perl -w $| = 1; use strict; use Time::HiRes qw( sleep ); for ( 1 .. 100 ) { print "\r \r${_}% Complete."; sleep( 0.33 ); }

Also have a look at the thread: How do you clear the current line?
Neil

  • Comment on Re: Avoid newline echoing so I can capture a line and reprompt over it
  • Download Code

Replies are listed 'Best First'.
Re^2: Avoid newline echoing so I can capture a line and reprompt over it
by hlen (Beadle) on Sep 02, 2004 at 06:59 UTC
    Hmm, I'm not sure you got all there is to it. Thanks for the clearing link, that'll be useful. I'll try to explain better:
    Suppose this on your term:
    A context line Prompt: []
    Now you type something:
    A context line Prompt: Here is what I just typed[]
    I want to press enter and get:
    A context line Prompt: []
    Instead of:
    A context line Prompt: Here is what I just typed Prompt: []
    There.. I hope this makes the whole problem visible.

    Thanks again
      OK,
      Do you have any code that you're working on at present?

      Neil

        Here is what the code I'm trying to work on does:
        sub getlineUnix { my $message; eval { local $SIG{ALRM} = sub { $old = $readline::line; die }; alarm($config{timeout}) unless $^O =~ /win32/i; $message = $term->readline("Talk: ", $old); $old = $readline::line = ''; alarm(0) unless $^O =~ /win32/i; }; $message; }
        But I think the call to readline is the only important one
        in there. Here's what I think it comes down to in
        Term::ReadLine:
        sub get_line { my $self = shift; $self->Tk_loop if $Term::ReadLine::toloop && defined &Tk::DoOneEvent +; my $in = $self->IN; local ($/) = "\n"; return scalar <$in>; }