On 1/3/08, Tim Pease <tim.pease / gmail.com> wrote:
> STDOUT.write "\rThis will overwrite the current line"
>
> The "\r" is the carriage return character, and it will return the
> insert point to the beginning of the current line. The only caveat is
> that the new line you are writing needs to be at least as long as the
> line you wish to overwrite. If it is not, you will have remnants of
> the previous line at the end of your output.

You can issue STDOUT.write("\e[K"), it will erase whole line and you
won't bother about it length, but it's not what i'm asking for :(
sorry for my English, I'll try be more specific.

Consider the following example:
---------------------------------------------------
    th = Thread.new { loop do puts "Hello, Ruby!"; sleep(10) end }
    while (line = Readline.readline("prompt> ", true))
      puts "#{line}: processed"
    end
---------------------------------------------------

This code will produce such results:
---------------------------------------------------
$ ./cli.rb
Hello, Ruby!
prompt> I WAS TYPING HERE FOR 10 SECONDSHello, Ruby!
---------------------------------------------------
And what I want, it's ALL lines be put above my input prompt, and not
interrupting me while I'm typing.

> Another option would be to use the "highline" gem.

Yeah, thank you and Robert for that pointing (really good ideads
inside!), but brief looking shows that it is not suitable for my
purpose of non-standard outputting.

One way to solve this problem which i see is safe current line of
input, including "prompt> ", erase it, output event, and output saved
line again, hopefully it will be fast enough and user won't see
anything, but how can i get current line, anyway?