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

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

Replies are listed 'Best First'.
Re^3: Avoid newline echoing so I can capture a line and reprompt over it
by neilh (Pilgrim) on Sep 02, 2004 at 07:05 UTC
    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>; }
        Here is a working example:
        use Term::ReadKey; my $prompt = "Gimme a char: "; while (1) { # updated to use the erase-to-EOL escape sequence print "\r$prompt\e[K"; my $key = ""; my $str = ""; ReadMode "cbreak"; do { print $key; $str .= $key; $key = ReadKey; } while $key ne "\n"; ReadMode "normal"; }
        _____________________________________________________
        Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
        How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
        I think the general algorithm would be to turn off echoing and use some function that reads one character at a time, echoing it if it's NOT a newline, and stopping the input procedure when it IS a newline.
        _____________________________________________________
        Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
        How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart