Write to console at same locations

Hi,

Is there a way to write multiple lines to the console (STDOUT) at the
same locations? For example, I’d like to show % progress for several
tasks at the same time as follows:

Task #1: 20%
Task #2: 75%
Task #3: 60%

That is, I only want to update the % numbers without outputting
additional lines/scrolling.

I know “\r” does the trick for one line, but not for multiple lines.

Thanks you!

Pai-Hung

Hi,

Apart from clearing the whole screen with system ‘cls’ (Windows) or
system ‘clear’ (Linux), there’s no simple way that works on all
platforms.

On Linux, you can use the ANSI escape sequences (I think). On Windows,
you can use the Win32 functions. Or you could use a library like
ncurses.

Pai-Hung Chen wrote in post #1051857:

Hi,

Is there a way to write multiple lines to the console (STDOUT) at the
same locations? For example, I’d like to show % progress for several
tasks at the same time as follows:

Task #1: 20%
Task #2: 75%
Task #3: 60%

That is, I only want to update the % numbers without outputting
additional lines/scrolling.

Either you can use ANSI escape codes to reposition the cursor
(non-portable to Windows) or you can uses ncurses.


Luis L.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs