hlen has asked for the wisdom of the Perl Monks concerning the following question:

That pretty much states it.. I'm looking for a way to interectively capture a line of input and redraw the prompt over it, avoiding the line's scrolling up. I'm using Term::ReadLine, but a general solution would be nicely accepted. Seems I'd need to avoid the term's echoing of the newline and then print "\rPrompt: ".. something like that.

Thanks in advance
  • Comment on Avoid newline echoing so I can capture a line and reprompt over it

Replies are listed 'Best First'.
Re: Avoid newline echoing so I can capture a line and reprompt over it
by neilh (Pilgrim) on Sep 02, 2004 at 06:39 UTC
    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

      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

Re: Avoid newline echoing so I can capture a line and reprompt over it
by doowah2004 (Monk) on Sep 02, 2004 at 12:53 UTC
    For a quick-low-tech solution, just clear the screen and re-write 'A Context Line'.