format stdout

how can I update a text line without clearing the screen?

I want to show a progress info but seems impossible to update a line to increase the percent number of my script.

I always clear the screen and then print the data updated in the same position but this solution is dirty and I don’t like it.

Every program I use use this feature and it would be very useful to me.

I use Perl and C++.

Thanks.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

For a code reference look at how the ‘rpm’ command uses a progress bar
for installations of packages with the -v (verbose) switch. Other quick
info:

http://thesweeheng.wordpress.com/2008/01/03/a-progress-bar-for-bash-scripts/
http://www.wellho.net/resources/ex.php4?item=p210/paws

Found a lot of hits via Google.

Good luck.

castord wrote:
| how can I update a text line without clearing the screen?
|
| I want to show a progress info but seems impossible to update a line to
| increase the percent number of my script.
|
| I always clear the screen and then print the data updated in the same
| position but this solution is dirty and I don’t like it.
|
| Every program I use use this feature and it would be very useful to me.
|
| I use Perl and C++.
|
| Thanks.
|
|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIW+ci3s42bA80+9kRAh+gAJsEmggFkG/DP7b2v591AIavd6GRygCfTenQ
xF9O8jk1eLpgCl9d3ywPm/c=
=6RLU
-----END PGP SIGNATURE-----

On Fri, 2008-06-20 at 17:16 +0000, castord wrote:
> how can I update a text line without clearing the screen?

The “right” way is to query the terminal capabilities database
for the appropriate value (man terminfo).

So, for example, consider:
echo “hello $(tput cr)H”

On Fri, 2008-06-20 at 17:58 +0000, cjcox wrote:
> On Fri, 2008-06-20 at 17:16 +0000, castord wrote:
> > how can I update a text line without clearing the screen?
>
> The “right” way is to query the terminal capabilities database
> for the appropriate value (man terminfo).
>
> So, for example, consider:
> echo “hello $(tput cr)H”

Oh… and obviously you can query terminal capabilities from
other languages, I just used shell out of convenience.

Capabilities can include all sorts of cursor movements and
even the setting of colors and character definitions, etc.

Popular library to use is curses (ncurses). It’s a higher
level library than includes things to make terminal based
windows, scrolling, etc.

Thank you for the quick answer. I’ll try both solutions. :slight_smile: